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

Merge pull request #17019 from yuki24/add-class-name-to-unknown-attr-error

Message on AR::UnknownAttributeError should include the class name of a record
* `AR::UnknownAttributeError` now includes the class name of a record.
This would be helpful if 2 models have an attribute that has a similar
name to the other one. e.g.:
User.new(name: "Yuki Nishijima", project_attributes: {name: "kaminari"})
# => ActiveRecord::UnknownAttributeError: unknown attribute on User: name
# => ActiveRecord::UnknownAttributeError: unknown attribute 'name' for User.
*Yuki Nishijima*
......
......@@ -167,7 +167,7 @@ class UnknownAttributeError < NoMethodError
def initialize(record, attribute)
@record = record
@attribute = attribute.to_s
super("unknown attribute on #{@record.class}: #{attribute}")
super("unknown attribute '#{attribute}' for #{@record.class}.")
end
end
......
......@@ -736,11 +736,11 @@ def test_bulk_update_respects_access_control
def test_bulk_update_raise_unknown_attribute_error
error = assert_raises(ActiveRecord::UnknownAttributeError) {
Topic.new(:hello => "world")
Topic.new(hello: "world")
}
assert_instance_of Topic, error.record
assert_equal "hello", error.attribute
assert_equal "unknown attribute on Topic: hello", error.message
assert_equal "unknown attribute 'hello' for Topic.", error.message
end
def test_methods_override_in_multi_level_subclass
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册