提交 76281aa4 编写于 作者: J jasl

Model#find with hash argument should raise RecordNotFoundError instead of NoMethodError

上级 7cdc1744
......@@ -336,7 +336,7 @@ def raise_record_not_found_exception!(ids = nil, result_size = nil, expected_siz
error = +"Couldn't find #{name}"
error << " with#{conditions}" if conditions
raise RecordNotFound.new(error, name, key)
elsif Array(ids).size == 1
elsif Array.wrap(ids).size == 1
error = "Couldn't find #{name} with '#{key}'=#{ids}#{conditions}"
raise RecordNotFound.new(error, name, key, ids)
else
......
......@@ -44,6 +44,11 @@ def test_find
assert_equal(topics(:first).title, Topic.find(1).title)
end
def test_find_with_hash_parameter
assert_raises(ActiveRecord::RecordNotFound) { Post.find(foo: "bar") }
assert_raises(ActiveRecord::RecordNotFound) { Post.find(foo: "bar", bar: "baz") }
end
def test_find_with_proc_parameter_and_block
exception = assert_raises(RuntimeError) do
Topic.all.find(-> { raise "should happen" }) { |e| e.title == "non-existing-title" }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册