Skip to content

Commit

Permalink
Merge pull request rails#8391 from rmascarenhas/reset-attribute-doesn…
Browse files Browse the repository at this point in the history
…t-change-it

Reset attributes should not report changes.
  • Loading branch information
rafaelfranca committed Dec 1, 2012
2 parents 90e2d96 + cf7ab60 commit 42efdbf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 4 additions & 0 deletions 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*
Expand Down
5 changes: 4 additions & 1 deletion activemodel/lib/active_model/dirty.rb
Expand Up @@ -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
3 changes: 1 addition & 2 deletions activemodel/test/cases/dirty_test.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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.