diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-01-20 22:58:14 -0200 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-01-20 22:58:14 -0200 |
commit | 06a00038efbbaef127ad8908fffea6799c577440 (patch) | |
tree | fbb99094dcb8cbc3ad941a68fcafff23ef328ed1 /activemodel | |
parent | de3bf3ec3d7dfa81870aca5b8ed8c237e093fe9f (diff) | |
download | rails-06a00038efbbaef127ad8908fffea6799c577440.tar.gz rails-06a00038efbbaef127ad8908fffea6799c577440.tar.bz2 rails-06a00038efbbaef127ad8908fffea6799c577440.zip |
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.
Diffstat (limited to 'activemodel')
-rw-r--r-- | activemodel/lib/active_model/dirty.rb | 6 | ||||
-rw-r--r-- | activemodel/test/cases/dirty_test.rb | 8 |
2 files changed, 11 insertions, 3 deletions
diff --git a/activemodel/lib/active_model/dirty.rb b/activemodel/lib/active_model/dirty.rb index 58d87e6f7f..72e2224926 100644 --- a/activemodel/lib/active_model/dirty.rb +++ b/activemodel/lib/active_model/dirty.rb @@ -167,13 +167,13 @@ module ActiveModel # 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+. diff --git a/activemodel/test/cases/dirty_test.rb b/activemodel/test/cases/dirty_test.rb index 54427a1513..efadb2600f 100644 --- a/activemodel/test/cases/dirty_test.rb +++ b/activemodel/test/cases/dirty_test.rb @@ -83,6 +83,14 @@ class DirtyTest < ActiveModel::TestCase 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? |