Merge pull request #38473 from eugeneius/alias_assign_attributes

Copy argument in AttributeAssignment#attributes=
This commit is contained in:
Kasper Timm Hansen 2020-02-17 00:54:43 +01:00 committed by GitHub
commit 7113be6877
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View File

@ -10,6 +10,8 @@ module ActiveRecord
super(attributes.dup)
end
alias attributes= assign_attributes
private
def _assign_attributes(attributes)
multi_parameter_attributes = {}

View File

@ -279,14 +279,16 @@ class AttributeMethodsTest < ActiveRecord::TestCase
end
test "hashes are not mangled" do
new_topic = { title: "New Topic" }
new_topic_values = { title: "AnotherTopic" }
new_topic = { title: "New Topic", content: { key: "First value" } }
new_topic_values = { title: "AnotherTopic", content: { key: "Second value" } }
topic = Topic.new(new_topic)
assert_equal new_topic[:title], topic.title
assert_equal new_topic[:content], topic.content
topic.attributes = new_topic_values
assert_equal new_topic_values[:title], topic.title
assert_equal new_topic_values[:content], topic.content
end
test "create through factory" do