aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/date_ext_test.rb
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2010-05-03 00:02:14 +0200
committerXavier Noria <fxn@hashref.com>2010-05-03 00:03:32 +0200
commit0e00f428a816cd24ca645794385fd7b71dbfed73 (patch)
tree56d6709a864836ea36706a7c86cdb166be647c29 /activesupport/test/core_ext/date_ext_test.rb
parent8672a97e11b1a3697b0147b83fd1f812395997a1 (diff)
downloadrails-0e00f428a816cd24ca645794385fd7b71dbfed73.tar.gz
rails-0e00f428a816cd24ca645794385fd7b71dbfed73.tar.bz2
rails-0e00f428a816cd24ca645794385fd7b71dbfed73.zip
adds test coverage for Date.current vs Date.today in Date.(yesterday|tomorrow) implementation
Diffstat (limited to 'activesupport/test/core_ext/date_ext_test.rb')
-rw-r--r--activesupport/test/core_ext/date_ext_test.rb46
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