changing an attribute multiple times retains the correct original value

This commit is contained in:
Ian Stewart 2011-06-28 22:18:24 -07:00
parent 31536855ae
commit eafa174bfd
2 changed files with 10 additions and 1 deletions

View File

@ -156,7 +156,7 @@ module ActiveModel
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+.

View File

@ -106,4 +106,13 @@ class DirtyTest < ActiveModel::TestCase
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