Permalink
Browse files

Merge pull request #1968 from bogdan/associations_find_array_compatib…

…ility2

Fixed CollectionAssociation#find to be compatible with Array#find
  • Loading branch information...
2 parents eb2e109 + 8ba0c1a commit b27871a66fc1568dba08a4fbc1e6f20dec5dccab @spastorino spastorino committed Jul 5, 2011
@@ -78,10 +78,14 @@ def select(select = nil)
end
def find(*args)
- if options[:finder_sql]
- find_by_scan(*args)
+ if block_given?
+ load_target.find(*args) { |*block_args| yield(*block_args) }
else
- scoped.find(*args)
+ if options[:finder_sql]
+ find_by_scan(*args)
+ else
+ scoped.find(*args)
+ end
end
end
@@ -226,6 +226,10 @@ def test_finding
assert_equal 2, Firm.find(:first, :order => "id").clients.length
end
+ def test_finding_array_compatibility
+ assert_equal 2, Firm.order(:id).find{|f| f.id > 0}.clients.length
+ end
+
def test_find_with_blank_conditions
[[], {}, nil, ""].each do |blank|
assert_equal 2, Firm.find(:first, :order => "id").clients.find(:all, :conditions => blank).size

0 comments on commit b27871a

Please sign in to comment.