提交 cf7ab605 编写于 作者: R Renato Mascarenhas

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
~~~
上级 0181c2da
## 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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册