未验证 提交 eb3740dc 编写于 作者: R Ryuta Kamizono 提交者: GitHub

Merge pull request #32498 from eugeneius/mutation_tracker_merge_changes

Prevent changes_to_save from mutating attributes
......@@ -27,7 +27,7 @@ def changes
attr_names.each_with_object({}.with_indifferent_access) do |attr_name, result|
change = change_to_attribute(attr_name)
if change
result[attr_name] = change
result.merge!(attr_name => change)
end
end
end
......
......@@ -473,6 +473,14 @@ def test_save_should_not_save_serialized_attribute_with_partial_writes_if_not_pr
end
end
def test_changes_to_save_should_not_mutate_array_of_hashes
topic = Topic.new(author_name: "Bill", content: [{ a: "a" }])
topic.changes_to_save
assert_equal [{ a: "a" }], topic.content
end
def test_previous_changes
# original values should be in previous_changes
pirate = Pirate.new
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册