From cf7ab6056adfd1d2feb98444d82f89adcb6e5533 Mon Sep 17 00:00:00 2001 From: Renato Mascarenhas Date: Sat, 1 Dec 2012 15:29:49 -0200 Subject: Reset attributes should not report changes. When resetting an attribute, you expect it to return to the state it was before any changes. Namely, this fixes this unexpected behavior: ~~~ruby model.name = "Bob" model.reset_name! model.name_changed? #=> true ~~~ --- activemodel/lib/active_model/dirty.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'activemodel/lib') diff --git a/activemodel/lib/active_model/dirty.rb b/activemodel/lib/active_model/dirty.rb index d47c3ae1bb..ecb7a9e9b1 100644 --- a/activemodel/lib/active_model/dirty.rb +++ b/activemodel/lib/active_model/dirty.rb @@ -174,7 +174,10 @@ module ActiveModel # Handle reset_*! for +method_missing+. def reset_attribute!(attr) - __send__("#{attr}=", changed_attributes[attr]) if attribute_changed?(attr) + if attribute_changed?(attr) + __send__("#{attr}=", changed_attributes[attr]) + changed_attributes.delete(attr) + end end end end -- cgit v1.2.3