When applying changes or reseting changes create the right class

Before this patch after the changes are applied the changes can be only
accessed using string keys, but before symbols are also accepted.

After this change every state of the model will be consistent.
上级 de3bf3ec
......@@ -167,13 +167,13 @@ def attribute_was(attr) # :nodoc:
# Removes current changes and makes them accessible through +previous_changes+.
def changes_applied
@previously_changed = changes
@changed_attributes = {}
@changed_attributes = ActiveSupport::HashWithIndifferentAccess.new
end
# Removes all dirty data: current changes and previous changes
def reset_changes
@previously_changed = {}
@changed_attributes = {}
@previously_changed = ActiveSupport::HashWithIndifferentAccess.new
@changed_attributes = ActiveSupport::HashWithIndifferentAccess.new
end
# Handle <tt>*_change</tt> for +method_missing+.
......
......@@ -83,6 +83,14 @@ def save
assert_not_nil @model.changes['name']
end
test "be cosistent with symbols arguments after the changes are applied" do
@model.name = "David"
assert @model.attribute_changed?(:name)
@model.save
@model.name = 'Rafael'
assert @model.attribute_changed?(:name)
end
test "attribute mutation" do
@model.instance_variable_set("@name", "Yam")
assert !@model.name_changed?
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册