diff options
author | gbuesing <gbuesing@gmail.com> | 2008-10-13 20:18:56 -0500 |
---|---|---|
committer | gbuesing <gbuesing@gmail.com> | 2008-10-13 20:18:56 -0500 |
commit | c51db4d7ababd6f1c341d2808a298865ee449313 (patch) | |
tree | 19c2ff64789e1f3f5e83bfa6b1c5a159871742f2 /activesupport/test | |
parent | a6e5d29e0839540b6b5a1a89bcb3b1d037120474 (diff) | |
download | rails-c51db4d7ababd6f1c341d2808a298865ee449313.tar.gz rails-c51db4d7ababd6f1c341d2808a298865ee449313.tar.bz2 rails-c51db4d7ababd6f1c341d2808a298865ee449313.zip |
Enhance testing for fractional days and weeks. Update changelog.
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/core_ext/duration_test.rb | 22 | ||||
-rw-r--r-- | activesupport/test/core_ext/time_ext_test.rb | 8 |
2 files changed, 17 insertions, 13 deletions
diff --git a/activesupport/test/core_ext/duration_test.rb b/activesupport/test/core_ext/duration_test.rb index d1b15fd2ef..80cc6d25d3 100644 --- a/activesupport/test/core_ext/duration_test.rb +++ b/activesupport/test/core_ext/duration_test.rb @@ -30,21 +30,17 @@ class DurationTest < Test::Unit::TestCase end end - uses_mocha 'TestDurationSinceAndAgoWithCurrentTime' do - def test_fractional_weeks - Time.stubs(:now).returns Time.local(2000) - - assert_in_delta((24 * 7 * 1.5).hours, 1.5.weeks, 2 ** -20) - assert_in_delta((24 * 7 * 1.7).hours, 1.7.weeks, 2 ** -20) - end - - def test_fractional_days - Time.stubs(:now).returns Time.local(2000) + def test_fractional_weeks + assert_equal (86400 * 7) * 1.5, 1.5.weeks + assert_equal (86400 * 7) * 1.7, 1.7.weeks + end - assert_in_delta((24 * 1.5).hours, 1.5.days, 2 ** -20) - assert_in_delta((24 * 1.7).hours, 1.7.days, 2 ** -20) - end + def test_fractional_days + assert_equal 86400 * 1.5, 1.5.days + assert_equal 86400 * 1.7, 1.7.days + end + uses_mocha 'TestDurationSinceAndAgoWithCurrentTime' do def test_since_and_ago_with_fractional_days Time.stubs(:now).returns Time.local(2000) # since diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb index 8ceaedc7f4..11ec1c6cd6 100644 --- a/activesupport/test/core_ext/time_ext_test.rb +++ b/activesupport/test/core_ext/time_ext_test.rb @@ -381,7 +381,11 @@ class TimeExtCalculationsTest < Test::Unit::TestCase assert_equal Time.local(2006,2,28,15,15,10), Time.local(2005,2,28,15,15,10).advance(:years => 1) assert_equal Time.local(2005,6,28,15,15,10), Time.local(2005,2,28,15,15,10).advance(:months => 4) assert_equal Time.local(2005,3,21,15,15,10), Time.local(2005,2,28,15,15,10).advance(:weeks => 3) + assert_equal Time.local(2005,3,25,3,15,10), Time.local(2005,2,28,15,15,10).advance(:weeks => 3.5) + assert_equal Time.local(2005,3,26,12,51,10), Time.local(2005,2,28,15,15,10).advance(:weeks => 3.7) assert_equal Time.local(2005,3,5,15,15,10), Time.local(2005,2,28,15,15,10).advance(:days => 5) + assert_equal Time.local(2005,3,6,3,15,10), Time.local(2005,2,28,15,15,10).advance(:days => 5.5) + assert_equal Time.local(2005,3,6,8,3,10), Time.local(2005,2,28,15,15,10).advance(:days => 5.7) assert_equal Time.local(2012,9,28,15,15,10), Time.local(2005,2,28,15,15,10).advance(:years => 7, :months => 7) assert_equal Time.local(2013,10,3,15,15,10), Time.local(2005,2,28,15,15,10).advance(:years => 7, :months => 19, :days => 5) assert_equal Time.local(2013,10,17,15,15,10), Time.local(2005,2,28,15,15,10).advance(:years => 7, :months => 19, :weeks => 2, :days => 5) @@ -399,7 +403,11 @@ class TimeExtCalculationsTest < Test::Unit::TestCase assert_equal Time.utc(2006,2,22,15,15,10), Time.utc(2005,2,22,15,15,10).advance(:years => 1) assert_equal Time.utc(2005,6,22,15,15,10), Time.utc(2005,2,22,15,15,10).advance(:months => 4) assert_equal Time.utc(2005,3,21,15,15,10), Time.utc(2005,2,28,15,15,10).advance(:weeks => 3) + assert_equal Time.utc(2005,3,25,3,15,10), Time.utc(2005,2,28,15,15,10).advance(:weeks => 3.5) + assert_equal Time.utc(2005,3,26,12,51,10), Time.utc(2005,2,28,15,15,10).advance(:weeks => 3.7) assert_equal Time.utc(2005,3,5,15,15,10), Time.utc(2005,2,28,15,15,10).advance(:days => 5) + assert_equal Time.utc(2005,3,6,3,15,10), Time.utc(2005,2,28,15,15,10).advance(:days => 5.5) + assert_equal Time.utc(2005,3,6,8,3,10), Time.utc(2005,2,28,15,15,10).advance(:days => 5.7) assert_equal Time.utc(2012,9,22,15,15,10), Time.utc(2005,2,22,15,15,10).advance(:years => 7, :months => 7) assert_equal Time.utc(2013,10,3,15,15,10), Time.utc(2005,2,22,15,15,10).advance(:years => 7, :months => 19, :days => 11) assert_equal Time.utc(2013,10,17,15,15,10), Time.utc(2005,2,28,15,15,10).advance(:years => 7, :months => 19, :weeks => 2, :days => 5) |