diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2016-07-05 20:26:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-05 20:26:24 +0200 |
commit | 2dfb06a9b5a5d29354a20b9527941910e8467636 (patch) | |
tree | a12d2c124cbdf14dee78035318a1aa3fc4ab2467 /activesupport/test | |
parent | 55c7de37a618ac68936365657160260150db907d (diff) | |
parent | 919e7053622422d4a653f43b57da5a4179d5bbb2 (diff) | |
download | rails-2dfb06a9b5a5d29354a20b9527941910e8467636.tar.gz rails-2dfb06a9b5a5d29354a20b9527941910e8467636.tar.bz2 rails-2dfb06a9b5a5d29354a20b9527941910e8467636.zip |
Merge pull request #24890 from vipulnsward/travel-to-raise
`travel/travel_to` travel time helpers, now raise on nested calls
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/time_travel_test.rb | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/activesupport/test/time_travel_test.rb b/activesupport/test/time_travel_test.rb index 59c3e52c2f..e9f87bdf82 100644 --- a/activesupport/test/time_travel_test.rb +++ b/activesupport/test/time_travel_test.rb @@ -77,6 +77,49 @@ class TimeTravelTest < ActiveSupport::TestCase end end + def test_time_helper_travel_to_with_nested_calls_with_blocks + Time.stub(:now, Time.now) do + outer_expected_time = Time.new(2004, 11, 24, 01, 04, 44) + inner_expected_time = Time.new(2004, 10, 24, 01, 04, 44) + travel_to outer_expected_time do + assert_raises(RuntimeError, /Calling `travel_to` with a block, when we have previously already made a call to `travel_to`, can lead to confusing time stubbing./) do + travel_to(inner_expected_time) do + #noop + end + end + end + end + end + + def test_time_helper_travel_to_with_nested_calls + Time.stub(:now, Time.now) do + outer_expected_time = Time.new(2004, 11, 24, 01, 04, 44) + inner_expected_time = Time.new(2004, 10, 24, 01, 04, 44) + travel_to outer_expected_time do + assert_nothing_raised do + travel_to(inner_expected_time) + + assert_equal inner_expected_time, Time.now + end + end + end + end + + def test_time_helper_travel_to_with_subsequent_calls + Time.stub(:now, Time.now) do + initial_expected_time = Time.new(2004, 11, 24, 01, 04, 44) + subsequent_expected_time = Time.new(2004, 10, 24, 01, 04, 44) + assert_nothing_raised do + travel_to initial_expected_time + travel_to subsequent_expected_time + + assert_equal subsequent_expected_time, Time.now + + travel_back + end + end + end + def test_travel_to_will_reset_the_usec_to_avoid_mysql_rouding Time.stub(:now, Time.now) do travel_to Time.utc(2014, 10, 10, 10, 10, 50, 999999) do |