aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-02-28 19:54:42 +0900
committerRyuta Kamizono <kamipo@gmail.com>2018-02-28 19:58:45 +0900
commit42a16a4d6514f28e05f1c22a5f9125d194d9c7cb (patch)
treea0a393447e00b679dd93fa4350e873d5d3fb395f /activemodel
parent761122a6caf5030db8d791ed7d9ebf7afac529a2 (diff)
downloadrails-42a16a4d6514f28e05f1c22a5f9125d194d9c7cb.tar.gz
rails-42a16a4d6514f28e05f1c22a5f9125d194d9c7cb.tar.bz2
rails-42a16a4d6514f28e05f1c22a5f9125d194d9c7cb.zip
Alias `assign_attributes` to `attributes=` for `AttributeAssignment`
There is no reason `attributes=` doesn't take `assign_attributes`.
Diffstat (limited to 'activemodel')
-rw-r--r--activemodel/lib/active_model/attribute_assignment.rb2
-rw-r--r--activemodel/test/cases/attribute_assignment_test.rb8
2 files changed, 10 insertions, 0 deletions
diff --git a/activemodel/lib/active_model/attribute_assignment.rb b/activemodel/lib/active_model/attribute_assignment.rb
index aa931119ff..217bf1ac01 100644
--- a/activemodel/lib/active_model/attribute_assignment.rb
+++ b/activemodel/lib/active_model/attribute_assignment.rb
@@ -35,6 +35,8 @@ module ActiveModel
_assign_attributes(sanitize_for_mass_assignment(attributes))
end
+ alias attributes= assign_attributes
+
private
def _assign_attributes(attributes)
diff --git a/activemodel/test/cases/attribute_assignment_test.rb b/activemodel/test/cases/attribute_assignment_test.rb
index 448f8587fd..b06291f1b4 100644
--- a/activemodel/test/cases/attribute_assignment_test.rb
+++ b/activemodel/test/cases/attribute_assignment_test.rb
@@ -68,6 +68,14 @@ class AttributeAssignmentTest < ActiveModel::TestCase
assert_equal "world", model.description
end
+ test "simple assignment alias" do
+ model = Model.new
+
+ model.attributes = { name: "hello", description: "world" }
+ assert_equal "hello", model.name
+ assert_equal "world", model.description
+ end
+
test "assign non-existing attribute" do
model = Model.new
error = assert_raises(ActiveModel::UnknownAttributeError) do