ActiveModel::Dirty patch for multiple assignments to the same attribute #1897

Merged
merged 1 commit into from Jun 29, 2011
Jump to file or symbol
Failed to load files and symbols.
+10 −1
Split
@@ -156,7 +156,7 @@ def attribute_will_change!(attr)
rescue TypeError, NoMethodError
end
- changed_attributes[attr] = value
+ changed_attributes[attr] = value unless changed_attributes.include?(attr)
end
# Handle <tt>reset_*!</tt> for +method_missing+.
@@ -106,4 +106,13 @@ def save
assert_equal [nil, "Jericho Cane"], @model.previous_changes['name']
end
+ test "changing the same attribute multiple times retains the correct original value" do
+ @model.name = "Otto"
+ @model.save
+ @model.name = "DudeFella ManGuy"
+ @model.name = "Mr. Manfredgensonton"
+ assert_equal ["Otto", "Mr. Manfredgensonton"], @model.name_change
+ assert_equal @model.name_was, "Otto"
+ end
+
end