Skip to content

Commit

Permalink
Merge pull request #15584 from jamesyang124/issue_15382
Browse files Browse the repository at this point in the history
ActiveRecord::FinderMethods.find doesn't pass proc parameter to array

Manual merge of #15584.

Closes #15584.
  • Loading branch information
senny committed Jun 10, 2014
2 parents 8ed1dec + 9feb4a8 commit 44b7d6c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
7 changes: 7 additions & 0 deletions activerecord/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/relation/finder_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions activerecord/test/cases/finder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 44b7d6c

Please sign in to comment.