mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Don't store incorrect values in zones_map
[#4942 state:committed] Signed-off-by: José Valim <jose.valim@gmail.com>
This commit is contained in:
parent
97a92a4cfd
commit
b2633f9f93
3 changed files with 7 additions and 5 deletions
|
@ -350,7 +350,11 @@ module ActiveSupport
|
|||
def [](arg)
|
||||
case arg
|
||||
when String
|
||||
zones_map[arg] ||= lookup(arg)
|
||||
begin
|
||||
zones_map[arg] ||= lookup(arg).tap { |tz| tz.utc_offset }
|
||||
rescue TZInfo::InvalidTimezoneIdentifier
|
||||
nil
|
||||
end
|
||||
when Numeric, ActiveSupport::Duration
|
||||
arg *= 3600 if arg.abs <= 13
|
||||
all.find { |z| z.utc_offset == arg.to_i }
|
||||
|
|
|
@ -832,9 +832,7 @@ class TimeWithZoneMethodsForTimeAndDateTimeTest < Test::Unit::TestCase
|
|||
|
||||
def test_time_zone_setter_with_invalid_zone
|
||||
Time.zone = 'foo'
|
||||
assert_not_nil Time.zone
|
||||
assert_equal 'foo', Time.zone.name
|
||||
assert_raise(TZInfo::InvalidTimezoneIdentifier) { Time.zone.utc_offset }
|
||||
assert_nil Time.zone
|
||||
|
||||
Time.zone = -15.hours
|
||||
assert_nil Time.zone
|
||||
|
|
|
@ -268,7 +268,7 @@ class TimeZoneTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_index
|
||||
assert_not_nil ActiveSupport::TimeZone["bogus"]
|
||||
assert_nil ActiveSupport::TimeZone["bogus"]
|
||||
assert_instance_of ActiveSupport::TimeZone, ActiveSupport::TimeZone["Central Time (US & Canada)"]
|
||||
assert_instance_of ActiveSupport::TimeZone, ActiveSupport::TimeZone[8]
|
||||
assert_raise(ArgumentError) { ActiveSupport::TimeZone[false] }
|
||||
|
|
Loading…
Reference in a new issue