aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorSantiago Pastorino <santiago@wyeworks.com>2010-06-28 14:01:48 -0300
committerJosé Valim <jose.valim@gmail.com>2010-06-28 19:35:33 +0200
commitb2633f9f9323f5d5eca1c2c94bb7ae88ad276cda (patch)
tree4995b1f679178161d154f0b901f0f936e9737228 /activesupport
parent97a92a4cfddf819357ca09b4a91a5937b044e4d8 (diff)
downloadrails-b2633f9f9323f5d5eca1c2c94bb7ae88ad276cda.tar.gz
rails-b2633f9f9323f5d5eca1c2c94bb7ae88ad276cda.tar.bz2
rails-b2633f9f9323f5d5eca1c2c94bb7ae88ad276cda.zip
Don't store incorrect values in zones_map
[#4942 state:committed] Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/values/time_zone.rb6
-rw-r--r--activesupport/test/core_ext/time_with_zone_test.rb4
-rw-r--r--activesupport/test/time_zone_test.rb2
3 files changed, 7 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb
index 0a08016522..05b40298d3 100644
--- a/activesupport/lib/active_support/values/time_zone.rb
+++ b/activesupport/lib/active_support/values/time_zone.rb
@@ -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 }
diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb
index cf11f4d28f..5ce4277672 100644
--- a/activesupport/test/core_ext/time_with_zone_test.rb
+++ b/activesupport/test/core_ext/time_with_zone_test.rb
@@ -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
diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb
index 922449988b..af6eee69e5 100644
--- a/activesupport/test/time_zone_test.rb
+++ b/activesupport/test/time_zone_test.rb
@@ -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] }