Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Message on AR::UnknownAttributeError should include the class name of a record #17019

Merged
merged 1 commit into from
Oct 20, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions activerecord/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
* `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

*Yuki Nishijima*

* Fix regression causing `after_create` callbacks to run before associated
records are autosaved.

Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class UnknownAttributeError < NoMethodError
def initialize(record, attribute)
@record = record
@attribute = attribute.to_s
super("unknown attribute: #{attribute}")
super("unknown attribute on #{@record.class}: #{attribute}")
end

end
Expand Down
6 changes: 3 additions & 3 deletions activerecord/test/cases/attribute_methods_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -736,11 +736,11 @@ def test_bulk_update_respects_access_control

def test_bulk_update_raise_unknown_attribute_error
error = assert_raises(ActiveRecord::UnknownAttributeError) {
@target.new(:hello => "world")
Topic.new(:hello => "world")
}
assert_instance_of @target, error.record
assert_instance_of Topic, error.record
assert_equal "hello", error.attribute
assert_equal "unknown attribute: hello", error.message
assert_equal "unknown attribute on Topic: hello", error.message
end

def test_methods_override_in_multi_level_subclass
Expand Down