From 552d4d85f3e4d9332054bee7e18a5b44ae1ed3cf Mon Sep 17 00:00:00 2001 From: igor04 Date: Thu, 24 Apr 2014 16:06:26 +0300 Subject: Added rollback method to ActiveModel::Dirty --- activemodel/test/cases/dirty_test.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'activemodel/test/cases') diff --git a/activemodel/test/cases/dirty_test.rb b/activemodel/test/cases/dirty_test.rb index 2853476c91..d39484a7b9 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 + rollback_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 "rollback 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 -- cgit v1.2.3