support finding by a ruby class [#5979 state:resolved]

This commit is contained in:
Aaron Patterson
2010-11-15 20:24:58 -08:00
parent 7bf9cbb766
commit ace84a003c
2 changed files with 10 additions and 0 deletions

View File

@@ -27,6 +27,9 @@ module ActiveRecord
attribute.in(value)
when ActiveRecord::Base
attribute.eq(value.quoted_id)
when Class
# FIXME: I think we need to deprecate this behavior
attribute.eq(value.name)
else
attribute.eq(value)
end

View File

@@ -438,6 +438,13 @@ class RelationTest < ActiveRecord::TestCase
assert_equal author, authors.first
end
class Mary < Author; end
def test_find_by_classname
Author.create!(:name => Mary.name)
assert_equal 1, Author.where(:name => Mary).size
end
def test_find_by_id_with_list_of_ar
author = Author.first
authors = Author.find_by_id([author])