diff options
author | Jeremy Kemper <jeremykemper@gmail.com> | 2014-08-19 12:44:14 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremykemper@gmail.com> | 2014-08-19 12:44:14 -0700 |
commit | e9bc3ef5c9c28299908597706e78ef041108498b (patch) | |
tree | 239403cabbdfa90dc0da1a07673a0aea670a832c /activesupport/test | |
parent | fad9e729f1817738c25a90ef3b77acf720e93c1f (diff) | |
parent | ab291e8718e5b3bffc282ff7a23baa5debff2bce (diff) | |
download | rails-e9bc3ef5c9c28299908597706e78ef041108498b.tar.gz rails-e9bc3ef5c9c28299908597706e78ef041108498b.tar.bz2 rails-e9bc3ef5c9c28299908597706e78ef041108498b.zip |
Merge pull request #16564 from zzak/move_time_travel_test
Move TimeHelperTest to TimeTravelTest from `as/test_test.rb`
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/test_test.rb | 69 | ||||
-rw-r--r-- | activesupport/test/time_travel_test.rb | 68 |
2 files changed, 68 insertions, 69 deletions
diff --git a/activesupport/test/test_test.rb b/activesupport/test/test_test.rb index b74bc9bf20..2c284f3b71 100644 --- a/activesupport/test/test_test.rb +++ b/activesupport/test/test_test.rb @@ -174,72 +174,3 @@ class TestCaseTaggedLoggingTest < ActiveSupport::TestCase assert_match "#{self.class}: #{name}\n", @out.string end end - -class TimeHelperTest < ActiveSupport::TestCase - setup do - Time.stubs now: Time.now - end - - teardown do - travel_back - end - - def test_time_helper_travel - expected_time = Time.now + 1.day - travel 1.day - - assert_equal expected_time.to_s(:db), Time.now.to_s(:db) - assert_equal expected_time.to_date, Date.today - end - - def test_time_helper_travel_with_block - expected_time = Time.now + 1.day - - travel 1.day do - assert_equal expected_time.to_s(:db), Time.now.to_s(:db) - assert_equal expected_time.to_date, Date.today - end - - assert_not_equal expected_time.to_s(:db), Time.now.to_s(:db) - assert_not_equal expected_time.to_date, Date.today - end - - def test_time_helper_travel_to - expected_time = Time.new(2004, 11, 24, 01, 04, 44) - travel_to expected_time - - assert_equal expected_time, Time.now - assert_equal Date.new(2004, 11, 24), Date.today - end - - def test_time_helper_travel_to_with_block - expected_time = Time.new(2004, 11, 24, 01, 04, 44) - - travel_to expected_time do - assert_equal expected_time, Time.now - assert_equal Date.new(2004, 11, 24), Date.today - end - - assert_not_equal expected_time, Time.now - assert_not_equal Date.new(2004, 11, 24), Date.today - end - - def test_time_helper_travel_back - expected_time = Time.new(2004, 11, 24, 01, 04, 44) - - travel_to expected_time - assert_equal expected_time, Time.now - assert_equal Date.new(2004, 11, 24), Date.today - travel_back - - assert_not_equal expected_time, Time.now - assert_not_equal Date.new(2004, 11, 24), Date.today - end - - def test_travel_to_will_reset_the_usec_to_avoid_mysql_rouding - travel_to Time.utc(2014, 10, 10, 10, 10, 50, 999999) do - assert_equal 50, Time.now.sec - assert_equal 0, Time.now.usec - end - end -end diff --git a/activesupport/test/time_travel_test.rb b/activesupport/test/time_travel_test.rb new file mode 100644 index 0000000000..cb5aac7a33 --- /dev/null +++ b/activesupport/test/time_travel_test.rb @@ -0,0 +1,68 @@ +class TimeTravelTest < ActiveSupport::TestCase + setup do + Time.stubs now: Time.now + end + + teardown do + travel_back + end + + def test_time_helper_travel + expected_time = Time.now + 1.day + travel 1.day + + assert_equal expected_time.to_s(:db), Time.now.to_s(:db) + assert_equal expected_time.to_date, Date.today + end + + def test_time_helper_travel_with_block + expected_time = Time.now + 1.day + + travel 1.day do + assert_equal expected_time.to_s(:db), Time.now.to_s(:db) + assert_equal expected_time.to_date, Date.today + end + + assert_not_equal expected_time.to_s(:db), Time.now.to_s(:db) + assert_not_equal expected_time.to_date, Date.today + end + + def test_time_helper_travel_to + expected_time = Time.new(2004, 11, 24, 01, 04, 44) + travel_to expected_time + + assert_equal expected_time, Time.now + assert_equal Date.new(2004, 11, 24), Date.today + end + + def test_time_helper_travel_to_with_block + expected_time = Time.new(2004, 11, 24, 01, 04, 44) + + travel_to expected_time do + assert_equal expected_time, Time.now + assert_equal Date.new(2004, 11, 24), Date.today + end + + assert_not_equal expected_time, Time.now + assert_not_equal Date.new(2004, 11, 24), Date.today + end + + def test_time_helper_travel_back + expected_time = Time.new(2004, 11, 24, 01, 04, 44) + + travel_to expected_time + assert_equal expected_time, Time.now + assert_equal Date.new(2004, 11, 24), Date.today + travel_back + + assert_not_equal expected_time, Time.now + assert_not_equal Date.new(2004, 11, 24), Date.today + end + + def test_travel_to_will_reset_the_usec_to_avoid_mysql_rouding + travel_to Time.utc(2014, 10, 10, 10, 10, 50, 999999) do + assert_equal 50, Time.now.sec + assert_equal 0, Time.now.usec + end + end +end |