mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
adds test coverage for Date.current vs Date.today in Date.(yesterday|tomorrow) implementation
This commit is contained in:
parent
8672a97e11
commit
0e00f428a8
1 changed files with 45 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue