diff options
author | Tom Lea <commit@tomlea.co.uk> | 2008-09-04 17:38:53 +0100 |
---|---|---|
committer | gbuesing <gbuesing@gmail.com> | 2008-10-13 20:00:09 -0500 |
commit | 27c70ff386e76ed0af41b53f2ba8cdb09bc94ace (patch) | |
tree | a6de54ec663f6822323023982fdf7a12714b68a0 /activesupport/test/core_ext | |
parent | 1abdc8752d7fbc0733da763e751a2671db42961a (diff) | |
download | rails-27c70ff386e76ed0af41b53f2ba8cdb09bc94ace.tar.gz rails-27c70ff386e76ed0af41b53f2ba8cdb09bc94ace.tar.bz2 rails-27c70ff386e76ed0af41b53f2ba8cdb09bc94ace.zip |
Time#advance recognizes fractional days and weeks [#970 state:resolved]
Diffstat (limited to 'activesupport/test/core_ext')
-rw-r--r-- | activesupport/test/core_ext/duration_test.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/duration_test.rb b/activesupport/test/core_ext/duration_test.rb index f802ed8760..b01fbf2efb 100644 --- a/activesupport/test/core_ext/duration_test.rb +++ b/activesupport/test/core_ext/duration_test.rb @@ -31,6 +31,40 @@ class DurationTest < Test::Unit::TestCase 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) + + 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_since_and_ago_with_fractional_days + Time.stubs(:now).returns Time.local(2000) + # since + assert_equal 36.hours.since, 1.5.days.since + assert_equal((24 * 1.7).hours.since, 1.7.days.since) + # ago + assert_equal 36.hours.ago, 1.5.days.ago + assert_equal((24 * 1.7).hours.ago, 1.7.days.ago) + end + + def test_since_and_ago_with_fractional_weeks + Time.stubs(:now).returns Time.local(2000) + # since + assert_equal((7 * 36).hours.since, 1.5.weeks.since) + assert_equal((7 * 24 * 1.7).hours.since, 1.7.weeks.since) + # ago + assert_equal((7 * 36).hours.ago, 1.5.weeks.ago) + assert_equal((7 * 24 * 1.7).hours.ago, 1.7.weeks.ago) + end + def test_since_and_ago_anchored_to_time_now_when_time_zone_default_not_set Time.zone_default = nil with_env_tz 'US/Eastern' do |