From dfd88083f85115c62da5f2cca2e0e4a8430e2b76 Mon Sep 17 00:00:00 2001 From: Leigh Caplan Date: Mon, 28 Jun 2010 15:38:16 -0700 Subject: [PATCH 1/2] Rewrite the clause to pluck the existing value from zones_map before performing a lookup. --- .../lib/active_support/values/time_zone.rb | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb index 0c39c76..ad9ea2a 100644 --- a/activesupport/lib/active_support/values/time_zone.rb +++ b/activesupport/lib/active_support/values/time_zone.rb @@ -387,8 +387,10 @@ module ActiveSupport def [](arg) case arg when String - if tz = lookup(arg) - zones_map[arg] ||= tz + if tz = zones_map[arg] + tz + elsif tz = lookup(arg) + zones_map[arg] = tz end when Numeric, ActiveSupport::Duration arg *= 3600 if arg.abs <= 13 -- 1.6.5.3 From a8a96c4424ba5385d0cf5e93ca6b7825546aab1e Mon Sep 17 00:00:00 2001 From: Leigh Caplan Date: Mon, 28 Jun 2010 17:50:35 -0700 Subject: [PATCH 2/2] Added a test to make sure existing time zones don't trigger a lookup --- activesupport/test/time_zone_test.rb | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) create mode 100644 activesupport/lookup-fix-2-3-stable.patch diff --git a/activesupport/lookup-fix-2-3-stable.patch b/activesupport/lookup-fix-2-3-stable.patch new file mode 100644 index 0000000..e69de29 diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb index c12c74b..d72f90f 100644 --- a/activesupport/test/time_zone_test.rb +++ b/activesupport/test/time_zone_test.rb @@ -265,6 +265,11 @@ class TimeZoneTest < Test::Unit::TestCase ActiveSupport::TimeZone["bogus"] assert !ActiveSupport::TimeZone.zones_map.key?("bogus") end + + def test_set_zones_dont_perform_lookup + ActiveSupport::TimeZone.expects(:find_tzinfo).never + ActiveSupport::TimeZone['Eastern Time (US & Canada)'] + end def test_new assert_equal ActiveSupport::TimeZone["Central Time (US & Canada)"], ActiveSupport::TimeZone.new("Central Time (US & Canada)") -- 1.6.5.3