mirror of https://github.com/rails/rails
changing an attribute multiple times retains the correct original value
This commit is contained in:
parent
31536855ae
commit
eafa174bfd
|
@ -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+.
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue