diff options
author | Fernando Tapia Rico <fertapric@gmail.com> | 2015-04-21 18:56:43 +0200 |
---|---|---|
committer | Fernando Tapia Rico <fertapric@gmail.com> | 2015-04-21 19:30:46 +0200 |
commit | f072db8e4fb34cfd50840e8bf84fe90340cad5fe (patch) | |
tree | 9f0310fb93006c778cb00e7bcb71efc117ea74d2 /activemodel/test/cases | |
parent | b12abe673306f2b5298b7a296c74ddc9061d2fec (diff) | |
download | rails-f072db8e4fb34cfd50840e8bf84fe90340cad5fe.tar.gz rails-f072db8e4fb34cfd50840e8bf84fe90340cad5fe.tar.bz2 rails-f072db8e4fb34cfd50840e8bf84fe90340cad5fe.zip |
Add `ActiveModel::Dirty#[attr_name]_previously_changed?` and
`ActiveModel::Dirty#[attr_name]_previous_change` to improve access
to recorded changes after the model has been saved.
It makes the dirty-attributes query methods consistent before and after
saving.
Diffstat (limited to 'activemodel/test/cases')
-rw-r--r-- | activemodel/test/cases/dirty_test.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/activemodel/test/cases/dirty_test.rb b/activemodel/test/cases/dirty_test.rb index 66ed8a350a..d17a12ad12 100644 --- a/activemodel/test/cases/dirty_test.rb +++ b/activemodel/test/cases/dirty_test.rb @@ -137,6 +137,19 @@ class DirtyTest < ActiveModel::TestCase assert_equal [nil, "Jericho Cane"], @model.previous_changes['name'] end + test "setting new attributes should not affect previous changes" do + @model.name = "Jericho Cane" + @model.save + @model.name = "DudeFella ManGuy" + assert_equal [nil, "Jericho Cane"], @model.name_previous_change + end + + test "saving should preserve model's previous changed status" do + @model.name = "Jericho Cane" + @model.save + assert @model.name_previously_changed? + end + test "previous value is preserved when changed after save" do assert_equal({}, @model.changed_attributes) @model.name = "Paul" |