aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2014-10-20 08:46:41 +0200
committerYves Senn <yves.senn@gmail.com>2014-10-20 08:49:27 +0200
commita702d5aad5e533291267443ad523691e52aa0bd7 (patch)
tree0ea29e4e7c131ff9f00effb35969fa1787d211ba /activerecord
parentdf08a45a77da755409f344de6be5e2af38296310 (diff)
parent074880c4eab3121025840998e587753203f65f6f (diff)
downloadrails-a702d5aad5e533291267443ad523691e52aa0bd7.tar.gz
rails-a702d5aad5e533291267443ad523691e52aa0bd7.tar.bz2
rails-a702d5aad5e533291267443ad523691e52aa0bd7.zip
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
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG.md5
-rw-r--r--activerecord/lib/active_record/errors.rb2
-rw-r--r--activerecord/test/cases/attribute_methods_test.rb4
3 files changed, 4 insertions, 7 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index a1bef4aa93..e0e107e89d 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,10 +1,7 @@
* `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*
diff --git a/activerecord/lib/active_record/errors.rb b/activerecord/lib/active_record/errors.rb
index 2b9b3c8f73..5b3fdf16f5 100644
--- a/activerecord/lib/active_record/errors.rb
+++ b/activerecord/lib/active_record/errors.rb
@@ -167,7 +167,7 @@ module ActiveRecord
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
diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb
index 3fdb70a137..c3e8ceb0da 100644
--- a/activerecord/test/cases/attribute_methods_test.rb
+++ b/activerecord/test/cases/attribute_methods_test.rb
@@ -736,11 +736,11 @@ class AttributeMethodsTest < ActiveRecord::TestCase
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