From a581c524a2770f43399caf48202a4105ddffc3f8 Mon Sep 17 00:00:00 2001 From: Leigh Caplan Date: Wed, 23 Jun 2010 09:34:56 -0700 Subject: [PATCH 1/2] Patching time zones against master. About to fix the test. --- .../lib/active_support/values/time_zone.rb | 6 +++++- activesupport/test/time_zone_test.rb | 5 +++++ 2 files changed, 10 insertions(+), 1 deletions(-) diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb index 0a08016..6187705 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) + return zones_map[arg] if zones_map[arg] + + if zone = lookup(arg) + zones_map[arg] = zone + 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/time_zone_test.rb b/activesupport/test/time_zone_test.rb index 620623b..c7e9444 100644 --- a/activesupport/test/time_zone_test.rb +++ b/activesupport/test/time_zone_test.rb @@ -293,6 +293,11 @@ class TimeZoneTest < Test::Unit::TestCase assert ActiveSupport::TimeZone.us_zones.include?(ActiveSupport::TimeZone["Hawaii"]) assert !ActiveSupport::TimeZone.us_zones.include?(ActiveSupport::TimeZone["Kuala Lumpur"]) end + + def test_unknown_zones_dont_store_mapping_keys + ActiveSupport::TimeZone["bogus"] + assert !ActiveSupport::TimeZone.zones_map.key?("bogus") + end protected def with_env_tz(new_tz = 'US/Eastern') -- 1.6.5.3 From 5231de8b4306ee36a48562abafde05f2b2439980 Mon Sep 17 00:00:00 2001 From: Leigh Caplan Date: Wed, 23 Jun 2010 10:05:34 -0700 Subject: [PATCH 2/2] Fixed time zone lookup test to stub current tzinfo behavior. Works now in Rails 3. --- activesupport/test/time_zone_test.rb | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-) diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb index c7e9444..402eea9 100644 --- a/activesupport/test/time_zone_test.rb +++ b/activesupport/test/time_zone_test.rb @@ -294,9 +294,13 @@ class TimeZoneTest < Test::Unit::TestCase assert !ActiveSupport::TimeZone.us_zones.include?(ActiveSupport::TimeZone["Kuala Lumpur"]) end + # Older versions of tzinfo don't raise a TZInfo::InvalidTimezoneIdentifier exception + # when given an unknown time zone. In the event that our tzinfo dependency returns nil, + # the key should still *not* be stored in zones_map. def test_unknown_zones_dont_store_mapping_keys - ActiveSupport::TimeZone["bogus"] - assert !ActiveSupport::TimeZone.zones_map.key?("bogus") + ActiveSupport::TimeZone.stubs(:lookup).returns(nil) + ActiveSupport::TimeZone["nonexistent"] + assert !ActiveSupport::TimeZone.zones_map.key?("nonexistent") end protected -- 1.6.5.3