diff options
author | gbuesing <gbuesing@gmail.com> | 2008-05-08 22:48:47 -0500 |
---|---|---|
committer | gbuesing <gbuesing@gmail.com> | 2008-05-08 22:48:47 -0500 |
commit | 66728087d0eb99a524498e8f24725dae6073edd6 (patch) | |
tree | e8675936450de56cc4603d9057668cc365ae7113 /activesupport/test | |
parent | 79e44a5ee484f977c2cad8a4cffe882b816340a1 (diff) | |
download | rails-66728087d0eb99a524498e8f24725dae6073edd6.tar.gz rails-66728087d0eb99a524498e8f24725dae6073edd6.tar.bz2 rails-66728087d0eb99a524498e8f24725dae6073edd6.zip |
Adding Date.current, which returns Time.zone.today if config.time_zone is set; otherwise returns Date.today. ActionView date_helper uses Date.current to determine locale-appropriate default
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/core_ext/date_ext_test.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/date_ext_test.rb b/activesupport/test/core_ext/date_ext_test.rb index 2e363c439a..5925ae3a61 100644 --- a/activesupport/test/core_ext/date_ext_test.rb +++ b/activesupport/test/core_ext/date_ext_test.rb @@ -208,6 +208,29 @@ class DateExtCalculationsTest < Test::Unit::TestCase end end end + + uses_mocha 'TestDateCurrent' do + def test_current_returns_date_today_when_zone_default_not_set + with_env_tz 'US/Central' do + Time.stubs(:now).returns Time.local(1999, 12, 31, 23) + assert_equal Date.new(1999, 12, 31), Date.today + assert_equal Date.new(1999, 12, 31), Date.current + end + end + + def test_current_returns_time_zone_today_when_zone_default_set + silence_warnings do # silence warnings raised by tzinfo gem + Time.zone_default = TimeZone['Eastern Time (US & Canada)'] + with_env_tz 'US/Central' do + Time.stubs(:now).returns Time.local(1999, 12, 31, 23) + assert_equal Date.new(1999, 12, 31), Date.today + assert_equal Date.new(2000, 1, 1), Date.current + end + end + ensure + Time.zone_default = nil + end + end protected def with_env_tz(new_tz = 'US/Eastern') |