Permalink
Browse files

changing an attribute multiple times retains the correct original value

  • Loading branch information...
1 parent 3153685 commit eafa174bfdeef943669332b67d87078b9b88e02d Ian Stewart committed Jun 29, 2011
Showing with 10 additions and 1 deletion.
  1. +1 −1 activemodel/lib/active_model/dirty.rb
  2. +9 −0 activemodel/test/cases/dirty_test.rb
@@ -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

0 comments on commit eafa174

Please sign in to comment.