diff options
author | José Valim <jose.valim@gmail.com> | 2011-06-29 02:48:55 -0700 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-06-29 02:48:55 -0700 |
commit | 4106245530bc573c035fe70e8fc8633e89741abd (patch) | |
tree | 1261787801779d58c2a41fa6b090fc5379f82709 | |
parent | 31536855ae90bf2fb07c855d05837246b5aa6fb9 (diff) | |
parent | eafa174bfdeef943669332b67d87078b9b88e02d (diff) | |
download | rails-4106245530bc573c035fe70e8fc8633e89741abd.tar.gz rails-4106245530bc573c035fe70e8fc8633e89741abd.tar.bz2 rails-4106245530bc573c035fe70e8fc8633e89741abd.zip |
Merge pull request #1897 from istewart/active_model_dirty_patch
ActiveModel::Dirty patch for multiple assignments to the same attribute
-rw-r--r-- | activemodel/lib/active_model/dirty.rb | 2 | ||||
-rw-r--r-- | activemodel/test/cases/dirty_test.rb | 9 |
2 files changed, 10 insertions, 1 deletions
diff --git a/activemodel/lib/active_model/dirty.rb b/activemodel/lib/active_model/dirty.rb index 3b412d3dd7..166cccf161 100644 --- a/activemodel/lib/active_model/dirty.rb +++ b/activemodel/lib/active_model/dirty.rb @@ -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+. diff --git a/activemodel/test/cases/dirty_test.rb b/activemodel/test/cases/dirty_test.rb index 858ae9cb69..98244a6290 100644 --- a/activemodel/test/cases/dirty_test.rb +++ b/activemodel/test/cases/dirty_test.rb @@ -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 |