diff options
author | Yves Senn <yves.senn@gmail.com> | 2013-11-20 14:36:58 +0100 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2013-11-21 17:29:53 +0100 |
commit | e2fbec96d4d6a8872ea9f21271e8a24682cd70df (patch) | |
tree | beef354151607add644b2815271fe253e15f8c25 /activerecord/test/cases | |
parent | 68aebd489566ee514d86765c0d5dceb7feb7aacf (diff) | |
download | rails-e2fbec96d4d6a8872ea9f21271e8a24682cd70df.tar.gz rails-e2fbec96d4d6a8872ea9f21271e8a24682cd70df.tar.bz2 rails-e2fbec96d4d6a8872ea9f21271e8a24682cd70df.zip |
replace custom Time stubbing with `travel` and `travel_to`.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/mixin_test.rb | 44 |
1 files changed, 7 insertions, 37 deletions
diff --git a/activerecord/test/cases/mixin_test.rb b/activerecord/test/cases/mixin_test.rb index f927c13979..ad0d5cce27 100644 --- a/activerecord/test/cases/mixin_test.rb +++ b/activerecord/test/cases/mixin_test.rb @@ -3,42 +3,11 @@ require "cases/helper" class Mixin < ActiveRecord::Base end -# Let us control what Time.now returns for the TouchTest suite -class Time - @@forced_now_time = nil - cattr_accessor :forced_now_time - - class << self - def now_with_forcing - if @@forced_now_time - @@forced_now_time - else - now_without_forcing - end - end - alias_method_chain :now, :forcing - end -end - - class TouchTest < ActiveRecord::TestCase fixtures :mixins def setup - Time.forced_now_time = Time.now - end - - def teardown - Time.forced_now_time = nil - end - - def test_time_mocking - five_minutes_ago = 5.minutes.ago - Time.forced_now_time = five_minutes_ago - assert_equal five_minutes_ago, Time.now - - Time.forced_now_time = nil - assert_not_equal five_minutes_ago, Time.now + travel_to Time.now end def test_update @@ -68,12 +37,13 @@ class TouchTest < ActiveRecord::TestCase old_updated_at = stamped.updated_at - Time.forced_now_time = 5.minutes.from_now - stamped.lft_will_change! - stamped.save + travel 5.minutes do + stamped.lft_will_change! + stamped.save - assert_equal Time.now, stamped.updated_at - assert_equal old_updated_at, stamped.created_at + assert_equal Time.now, stamped.updated_at + assert_equal old_updated_at, stamped.created_at + end end def test_create_turned_off |