Permalink
Browse files

Merge pull request #8391 from rmascarenhas/reset-attribute-doesnt-cha…

…nge-it

Reset attributes should not report changes.
  • Loading branch information...
2 parents 90e2d96 + cf7ab60 commit 42efdbf23e14fec629e32c6339ec4e8c85ae1701 @rafaelfranca rafaelfranca committed Dec 1, 2012
Showing with 9 additions and 3 deletions.
  1. +4 −0 activemodel/CHANGELOG.md
  2. +4 −1 activemodel/lib/active_model/dirty.rb
  3. +1 −2 activemodel/test/cases/dirty_test.rb
View
@@ -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*
@@ -174,7 +174,10 @@ def attribute_will_change!(attr)
# 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
@@ -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

0 comments on commit 42efdbf

Please sign in to comment.