aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/dirty.rb
diff options
context:
space:
mode:
authorRenato Mascarenhas <mascarenhas.renato@gmail.com>2012-12-01 15:29:49 -0200
committerRenato Mascarenhas <mascarenhas.renato@gmail.com>2012-12-01 16:58:09 -0200
commitcf7ab6056adfd1d2feb98444d82f89adcb6e5533 (patch)
tree7b5b1a3ed17327dd23779f2bd24d5b32e2710914 /activemodel/lib/active_model/dirty.rb
parent0181c2da977fc3de4e4c4eac602b26ff180cda2c (diff)
downloadrails-cf7ab6056adfd1d2feb98444d82f89adcb6e5533.tar.gz
rails-cf7ab6056adfd1d2feb98444d82f89adcb6e5533.tar.bz2
rails-cf7ab6056adfd1d2feb98444d82f89adcb6e5533.zip
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 ~~~
Diffstat (limited to 'activemodel/lib/active_model/dirty.rb')
-rw-r--r--activemodel/lib/active_model/dirty.rb5
1 files changed, 4 insertions, 1 deletions
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 <tt>reset_*!</tt> 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