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
This commit is contained in:
parent
79e44a5ee4
commit
66728087d0
@ -1,5 +1,7 @@
|
||||
*SVN*
|
||||
|
||||
* select_date defaults to Time.zone.today when config.time_zone is set [Geoff Buesing]
|
||||
|
||||
* Fixed that TextHelper#text_field would corrypt when raw HTML was used as the value (mchenryc, Kevin Glowacz) [#80]
|
||||
|
||||
* Added ActionController::TestCase#rescue_action_in_public! to control whether the action under test should use the regular rescue_action path instead of simply raising the exception inline (great for error testing) [DHH]
|
||||
|
@ -283,7 +283,7 @@ def select_datetime(datetime = Time.current, options = {}, html_options = {})
|
||||
# # prefixed with 'payday' rather than 'date'
|
||||
# select_datetime(my_date_time, :prefix => 'payday')
|
||||
#
|
||||
def select_date(date = Date.today, options = {}, html_options = {})
|
||||
def select_date(date = Date.current, options = {}, html_options = {})
|
||||
options[:order] ||= []
|
||||
[:year, :month, :day].each { |o| options[:order].push(o) unless options[:order].include?(o) }
|
||||
|
||||
|
@ -950,6 +950,15 @@ def test_select_time_uses_time_current_as_default
|
||||
expects(:select_minute).with(time, anything, anything).returns('')
|
||||
select_time
|
||||
end
|
||||
|
||||
def test_select_date_uses_date_current_as_default
|
||||
date = stub(:year => 2004, :month => 6, :day => 15)
|
||||
Date.expects(:current).returns date
|
||||
expects(:select_year).with(date, anything, anything).returns('')
|
||||
expects(:select_month).with(date, anything, anything).returns('')
|
||||
expects(:select_day).with(date, anything, anything).returns('')
|
||||
select_date
|
||||
end
|
||||
end
|
||||
|
||||
def test_date_select
|
||||
|
@ -1,5 +1,7 @@
|
||||
*SVN*
|
||||
|
||||
* Adding Date.current, which returns Time.zone.today if config.time_zone is set; otherwise returns Date.today [Geoff Buesing]
|
||||
|
||||
* TimeWithZone: date part getter methods (#year #mon #day etc) are defined on class; no longer relying on method_missing [Geoff Buesing]
|
||||
|
||||
* Time.zone.parse return nil for strings with no date information [Geoff Buesing]
|
||||
|
@ -25,6 +25,11 @@ def yesterday
|
||||
def tomorrow
|
||||
::Date.today.tomorrow
|
||||
end
|
||||
|
||||
# Returns Time.zone.today when config.time_zone is set, otherwise just returns Date.today.
|
||||
def current
|
||||
::Time.zone_default ? ::Time.zone.today : ::Date.today
|
||||
end
|
||||
end
|
||||
|
||||
# Converts Date to a Time (or DateTime if necessary) with the time portion set to the beginning of the day (0:00)
|
||||
|
@ -208,6 +208,29 @@ def test_xmlschema
|
||||
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')
|
||||
|
Loading…
Reference in New Issue
Block a user