diff options
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/test/core_ext/date_ext_test.rb | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/activesupport/test/core_ext/date_ext_test.rb b/activesupport/test/core_ext/date_ext_test.rb index 4ff714cabc..c403d7fb11 100644 --- a/activesupport/test/core_ext/date_ext_test.rb +++ b/activesupport/test/core_ext/date_ext_test.rb @@ -178,11 +178,47 @@ class DateExtCalculationsTest < Test::Unit::TestCase def test_yesterday_constructor assert_equal Date.current - 1, Date.yesterday end + + def test_yesterday_constructor_when_zone_default_is_not_set + with_env_tz 'UTC' do + with_tz_default do + Time.stubs(:now).returns Time.local(2000, 1, 1) + assert_equal Date.new(1999, 12, 31), Date.yesterday + end + end + end + + def test_yesterday_constructor_when_zone_default_is_set + with_env_tz 'UTC' do + with_tz_default ActiveSupport::TimeZone['Eastern Time (US & Canada)'] do # UTC -5 + Time.stubs(:now).returns Time.local(2000, 1, 1) + assert_equal Date.new(1999, 12, 30), Date.yesterday + end + end + end def test_tomorrow_constructor assert_equal Date.current + 1, Date.tomorrow end - + + def test_tomorrow_constructor_when_zone_default_is_not_set + with_env_tz 'UTC' do + with_tz_default do + Time.stubs(:now).returns Time.local(1999, 12, 31) + assert_equal Date.new(2000, 1, 1), Date.tomorrow + end + end + end + + def test_tomorrow_constructor_when_zone_default_is_set + with_env_tz 'UTC' do + with_tz_default ActiveSupport::TimeZone['Europe/Paris'] do # UTC +1 + Time.stubs(:now).returns Time.local(1999, 12, 31, 23) + assert_equal Date.new(2000, 1, 2), Date.tomorrow + end + end + end + def test_since assert_equal Time.local(2005,2,21,0,0,45), Date.new(2005,2,21).since(45) end @@ -264,6 +300,14 @@ class DateExtCalculationsTest < Test::Unit::TestCase ensure old_tz ? ENV['TZ'] = old_tz : ENV.delete('TZ') end + + def with_tz_default(tz = nil) + old_tz = Time.zone_default + Time.zone_default = tz + yield + ensure + Time.zone_default = old_tz + end end class DateExtBehaviorTest < Test::Unit::TestCase |