aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test/cases/dirty_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activemodel/test/cases/dirty_test.rb')
-rw-r--r--activemodel/test/cases/dirty_test.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/activemodel/test/cases/dirty_test.rb b/activemodel/test/cases/dirty_test.rb
index 2853476c91..562fadbb85 100644
--- a/activemodel/test/cases/dirty_test.rb
+++ b/activemodel/test/cases/dirty_test.rb
@@ -45,6 +45,10 @@ class DirtyTest < ActiveModel::TestCase
def reload
reset_changes
end
+
+ def rollback
+ undo_changes
+ end
end
setup do
@@ -176,4 +180,18 @@ class DirtyTest < ActiveModel::TestCase
assert_equal ActiveSupport::HashWithIndifferentAccess.new, @model.previous_changes
assert_equal ActiveSupport::HashWithIndifferentAccess.new, @model.changed_attributes
end
+
+ test "undo_changes should restore all previous data" do
+ @model.name = 'Dmitry'
+ @model.color = 'Red'
+ @model.save
+ @model.name = 'Bob'
+ @model.color = 'White'
+
+ @model.rollback
+
+ assert_not @model.changed?
+ assert_equal 'Dmitry', @model.name
+ assert_equal 'Red', @model.color
+ end
end