diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-07-17 14:53:41 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-07-17 14:55:28 -0300 |
commit | 1a300b674810b85e6f55e4106cb27c1b2dbef499 (patch) | |
tree | 33e31312db60c600a5346ea27e674d53bcb2e857 /activemodel/test/cases | |
parent | 2888f8653e2e0a6394e41cb4e8db2e2d81313eb7 (diff) | |
download | rails-1a300b674810b85e6f55e4106cb27c1b2dbef499.tar.gz rails-1a300b674810b85e6f55e4106cb27c1b2dbef499.tar.bz2 rails-1a300b674810b85e6f55e4106cb27c1b2dbef499.zip |
Make restore_attributes public
Also make it accept a list of attributes to be changed. This will make
possible to restore only a subset of the changed attributes.
Closes #16203
Diffstat (limited to 'activemodel/test/cases')
-rw-r--r-- | activemodel/test/cases/dirty_test.rb | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/activemodel/test/cases/dirty_test.rb b/activemodel/test/cases/dirty_test.rb index 6b8bb5216b..db2cd885e2 100644 --- a/activemodel/test/cases/dirty_test.rb +++ b/activemodel/test/cases/dirty_test.rb @@ -49,10 +49,6 @@ class DirtyTest < ActiveModel::TestCase def deprecated_reload reset_changes end - - def rollback - restore_attributes - end end setup do @@ -209,10 +205,24 @@ class DirtyTest < ActiveModel::TestCase @model.name = 'Bob' @model.color = 'White' - @model.rollback + @model.restore_attributes assert_not @model.changed? assert_equal 'Dmitry', @model.name assert_equal 'Red', @model.color end + + test "restore_attributes can restore only some attributes" do + @model.name = 'Dmitry' + @model.color = 'Red' + @model.save + @model.name = 'Bob' + @model.color = 'White' + + @model.restore_attributes(['name']) + + assert @model.changed? + assert_equal 'Dmitry', @model.name + assert_equal 'White', @model.color + end end |