Permalink
Browse files

Merge pull request #15584 from jamesyang124/issue_15382

ActiveRecord::FinderMethods.find doesn't pass proc parameter to array

Manual merge of #15584.

Closes #15584.
  • Loading branch information...
2 parents 8ed1dec + 9feb4a8 commit 44b7d6c41610bb8ddd058b3815543985f65bf7ad @senny senny committed Jun 10, 2014
@@ -1,3 +1,10 @@
+* `ActiveRecord::FinderMethods.find` with block can handle proc parameter as
+ `Enumerable#find` does.
+
+ Fixes #15382.
+
+ *James Yang*
+
* Make timezone aware attributes work with PostgreSQL array columns.
Fixes #13402.
@@ -65,7 +65,7 @@ module FinderMethods
# # returns an Array of the required fields, available since Rails 3.1.
def find(*args)
if block_given?
- to_a.find { |*block_args| yield(*block_args) }
+ to_a.find(*args) { |*block_args| yield(*block_args) }
else
find_with_ids(*args)
end
@@ -33,6 +33,17 @@ def test_find
assert_equal(topics(:first).title, Topic.find(1).title)
end
+ def test_find_with_proc_parameter_and_block
+ e = assert_raises(RuntimeError) do
+ Topic.all.find(-> { raise "should happen" }) { |e| e.title == "non-existing-title" }
+ end
+ assert_equal "should happen", e.message
+
+ assert_nothing_raised(RuntimeError) do
+ Topic.all.find(-> { raise "should not happen" }) { |e| e.title == topics(:first).title }
+ end
+ end
+
def test_find_passing_active_record_object_is_deprecated
assert_deprecated do
Topic.find(Topic.last)

0 comments on commit 44b7d6c

Please sign in to comment.