提交 f244d8f5 编写于 作者: Y Yves Senn

Merge pull request #15584 from jamesyang124/issue_15382

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

Manual merge of #15584.

Closes #15584.

Conflicts:
	activerecord/CHANGELOG.md
	activerecord/test/cases/finder_test.rb
上级 8c9dfe55
* `ActiveRecord::FinderMethods.find` with block can handle proc parameter as
`Enumerable#find` does.
Fixes #15382.
*James Yang*
* `ActiveRecord::SchemaMigration` has no primary key regardless of the
`primary_key_prefix_type` configuration.
......
......@@ -63,7 +63,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_symbols_table_ref
Post.first # warm up
x = Symbol.all_symbols.count
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册