Skip to content

Commit eafa174

Browse files
author
Ian Stewart
committed
changing an attribute multiple times retains the correct original value
1 parent 3153685 commit eafa174

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

activemodel/lib/active_model/dirty.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def attribute_will_change!(attr)
156156
rescue TypeError, NoMethodError
157157
end
158158

159-
changed_attributes[attr] = value
159+
changed_attributes[attr] = value unless changed_attributes.include?(attr)
160160
end
161161

162162
# Handle <tt>reset_*!</tt> for +method_missing+.

activemodel/test/cases/dirty_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,13 @@ def save
106106
assert_equal [nil, "Jericho Cane"], @model.previous_changes['name']
107107
end
108108

109+
test "changing the same attribute multiple times retains the correct original value" do
110+
@model.name = "Otto"
111+
@model.save
112+
@model.name = "DudeFella ManGuy"
113+
@model.name = "Mr. Manfredgensonton"
114+
assert_equal ["Otto", "Mr. Manfredgensonton"], @model.name_change
115+
assert_equal @model.name_was, "Otto"
116+
end
117+
109118
end

0 commit comments

Comments
 (0)