diff --git a/activemodel/CHANGELOG.md b/activemodel/CHANGELOG.md index aacef978586c301c78c80c539127883892ba19dc..b955e988353bd20a7e08c81c0fbcf19a3883d51e 100644 --- a/activemodel/CHANGELOG.md +++ b/activemodel/CHANGELOG.md @@ -1,5 +1,9 @@ ## Rails 4.0.0 (unreleased) ## +* `[attribute]_changed?` now returns `false` after a call to `reset_[attribute]!` + + *Renato Mascarenhas* + * Observers was extracted from Active Model as `rails-observers` gem. *Rafael Mendonça França* diff --git a/activemodel/lib/active_model/dirty.rb b/activemodel/lib/active_model/dirty.rb index d47c3ae1bb9f1f4edac2ce6a31408944eec1738a..ecb7a9e9b1a18b1163dd22c13de9be78bd3afa6e 100644 --- a/activemodel/lib/active_model/dirty.rb +++ b/activemodel/lib/active_model/dirty.rb @@ -174,7 +174,10 @@ def attribute_will_change!(attr) # 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 diff --git a/activemodel/test/cases/dirty_test.rb b/activemodel/test/cases/dirty_test.rb index eaaf910bac360187e8448c3f88627206fd6acb5b..0b9f9537e2f369d72fda92b825aaf5dd9363fa75 100644 --- a/activemodel/test/cases/dirty_test.rb +++ b/activemodel/test/cases/dirty_test.rb @@ -78,7 +78,7 @@ def save @model.name = "Bob" @model.reset_name! assert_nil @model.name - #assert !@model.name_changed #Doesn't work yet + assert !@model.name_changed? end test "setting color to same value should not result in change being recorded" do @@ -114,5 +114,4 @@ def save assert_equal ["Otto", "Mr. Manfredgensonton"], @model.name_change assert_equal @model.name_was, "Otto" end - end