diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2018-09-26 14:10:24 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-26 14:10:24 -0400 |
commit | 6556898884d636c59baae008e42783b8d3e16440 (patch) | |
tree | 13cecd6630717dc66a970ff971876fd052716020 /activemodel | |
parent | 0a4c2d4738a536ac6e1f4347205c0c62dd3ceb9a (diff) | |
parent | 2253f6cca10d5dd474654138e6190481ae764bc6 (diff) | |
download | rails-6556898884d636c59baae008e42783b8d3e16440.tar.gz rails-6556898884d636c59baae008e42783b8d3e16440.tar.bz2 rails-6556898884d636c59baae008e42783b8d3e16440.zip |
Merge pull request #30676 from artofhuman/import-assert-attrs-error-message
Improve error message when assign wrong attributes to model
Diffstat (limited to 'activemodel')
-rw-r--r-- | activemodel/lib/active_model/attribute_assignment.rb | 2 | ||||
-rw-r--r-- | activemodel/test/cases/attribute_assignment_test.rb | 4 |
2 files changed, 4 insertions, 2 deletions
diff --git a/activemodel/lib/active_model/attribute_assignment.rb b/activemodel/lib/active_model/attribute_assignment.rb index 217bf1ac01..f0e3458f51 100644 --- a/activemodel/lib/active_model/attribute_assignment.rb +++ b/activemodel/lib/active_model/attribute_assignment.rb @@ -27,7 +27,7 @@ module ActiveModel # cat.status # => 'sleeping' def assign_attributes(new_attributes) if !new_attributes.respond_to?(:stringify_keys) - raise ArgumentError, "When assigning attributes, you must pass a hash as an argument." + raise ArgumentError, "When assigning attributes, you must pass a hash as an argument, #{new_attributes.class} passed." end return if new_attributes.empty? diff --git a/activemodel/test/cases/attribute_assignment_test.rb b/activemodel/test/cases/attribute_assignment_test.rb index b06291f1b4..30e8419685 100644 --- a/activemodel/test/cases/attribute_assignment_test.rb +++ b/activemodel/test/cases/attribute_assignment_test.rb @@ -100,9 +100,11 @@ class AttributeAssignmentTest < ActiveModel::TestCase end test "an ArgumentError is raised if a non-hash-like object is passed" do - assert_raises(ArgumentError) do + err = assert_raises(ArgumentError) do Model.new(1) end + + assert_equal("When assigning attributes, you must pass a hash as an argument, Integer passed.", err.message) end test "forbidden attributes cannot be used for mass assignment" do |