Skip to content

Commit

Permalink
Merge pull request #1897 from istewart/active_model_dirty_patch
Browse files Browse the repository at this point in the history
ActiveModel::Dirty patch for multiple assignments to the same attribute
  • Loading branch information
josevalim committed Jun 29, 2011
2 parents 3153685 + eafa174 commit 4106245
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activemodel/lib/active_model/dirty.rb
Expand Up @@ -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+.
Expand Down
9 changes: 9 additions & 0 deletions activemodel/test/cases/dirty_test.rb
Expand Up @@ -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 4106245

Please sign in to comment.