提交 9feb4a8b 编写于 作者: J James Yang 提交者: Yves Senn

ActiveRecord::FinderMethods.find passes proc parameter #15382

上级 8ed1dec2
* `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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册