Skip to content
Browse files

Don't store incorrect values in zones_map

[#4942 state:committed]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent 97a92a4 commit b2633f9f9323f5d5eca1c2c94bb7ae88ad276cda @spastorino spastorino committed with josevalim Jun 28, 2010
View
6 activesupport/lib/active_support/values/time_zone.rb
@@ -350,7 +350,11 @@ def zones_map
def [](arg)
case arg
when String
- zones_map[arg] ||= lookup(arg)
+ begin
+ zones_map[arg] ||= lookup(arg).tap { |tz| tz.utc_offset }
@jamesarosen
jamesarosen added a note Jun 10, 2011

Is lookup guaranteed to return a non-nil object? If not, you probably also want to rescue NoMethodErrors on the next line.

@spastorino
Ruby on Rails member
spastorino added a note Jun 10, 2011

yes it returns not nil, take a look at the source ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ rescue TZInfo::InvalidTimezoneIdentifier
+ nil
+ end
when Numeric, ActiveSupport::Duration
arg *= 3600 if arg.abs <= 13
all.find { |z| z.utc_offset == arg.to_i }
View
4 activesupport/test/core_ext/time_with_zone_test.rb
@@ -832,9 +832,7 @@ def test_time_zone_setter_with_tzinfo_timezone_identifier_does_lookup_and_wraps_
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
View
2 activesupport/test/time_zone_test.rb
@@ -268,7 +268,7 @@ def test_all_sorted
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] }

0 comments on commit b2633f9

Please sign in to comment.
Something went wrong with that request. Please try again.