diff options
author | Andrew White <pixeltrix@users.noreply.github.com> | 2018-04-19 09:25:02 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-19 09:25:02 +0100 |
commit | b6577cb62880a88380fce6a086a1c084d5a74c18 (patch) | |
tree | 9ea30543b6b2f68f15d9c0b711054ee035a4b8fe /activesupport | |
parent | ef2af628a9ec1cc4e7b6997a021dd3f85cfe4665 (diff) | |
parent | fb2af6f849c8d25732f2c17352c59f2dc8b8320d (diff) | |
download | rails-b6577cb62880a88380fce6a086a1c084d5a74c18.tar.gz rails-b6577cb62880a88380fce6a086a1c084d5a74c18.tar.bz2 rails-b6577cb62880a88380fce6a086a1c084d5a74c18.zip |
Merge pull request #32613 from dsander/fix-as-timezone-all
Fix exception in AS::Timezone.all when any tzinfo data is missing
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/CHANGELOG.md | 5 | ||||
-rw-r--r-- | activesupport/lib/active_support/values/time_zone.rb | 3 | ||||
-rw-r--r-- | activesupport/test/time_zone_test.rb | 15 | ||||
-rw-r--r-- | activesupport/test/time_zone_test_helpers.rb | 13 |
4 files changed, 35 insertions, 1 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index 483eb12ce1..247eec68ac 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,3 +1,8 @@ +* Fix bug where `ActiveSupport::Timezone.all` would fail when tzinfo data for + any timezone defined in `ActiveSupport::MAPPING` is missing. + + *Dominik Sander* + * Redis cache store: `delete_matched` no longer blocks the Redis server. (Switches from evaled Lua to a batched SCAN + DEL loop.) diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb index 9dfaddb825..5f709c5fd9 100644 --- a/activesupport/lib/active_support/values/time_zone.rb +++ b/activesupport/lib/active_support/values/time_zone.rb @@ -279,7 +279,8 @@ module ActiveSupport def zones_map @zones_map ||= MAPPING.each_with_object({}) do |(name, _), zones| - zones[name] = self[name] + timezone = self[name] + zones[name] = timezone if timezone end end end diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb index 63ca22efb5..120afa61f2 100644 --- a/activesupport/test/time_zone_test.rb +++ b/activesupport/test/time_zone_test.rb @@ -725,6 +725,21 @@ class TimeZoneTest < ActiveSupport::TestCase assert_not_includes all_zones, galapagos end + def test_all_not_raises_exception_with_mizzing_tzinfo_data + mappings = { + "Puerto Rico" => "America/Unknown", + "Pittsburgh" => "America/New_York" + } + + with_tz_mappings(mappings) do + assert_nil ActiveSupport::TimeZone["Puerto Rico"] + assert_nil ActiveSupport::TimeZone[-9] + assert_nothing_raised do + ActiveSupport::TimeZone.all + end + end + end + def test_index assert_nil ActiveSupport::TimeZone["bogus"] assert_instance_of ActiveSupport::TimeZone, ActiveSupport::TimeZone["Central Time (US & Canada)"] diff --git a/activesupport/test/time_zone_test_helpers.rb b/activesupport/test/time_zone_test_helpers.rb index 051703a781..85ed727c9b 100644 --- a/activesupport/test/time_zone_test_helpers.rb +++ b/activesupport/test/time_zone_test_helpers.rb @@ -23,4 +23,17 @@ module TimeZoneTestHelpers ensure ActiveSupport.to_time_preserves_timezone = old_preserve_tz end + + def with_tz_mappings(mappings) + old_mappings = ActiveSupport::TimeZone::MAPPING.dup + ActiveSupport::TimeZone.clear + ActiveSupport::TimeZone::MAPPING.clear + ActiveSupport::TimeZone::MAPPING.merge!(mappings) + + yield + ensure + ActiveSupport::TimeZone.clear + ActiveSupport::TimeZone::MAPPING.clear + ActiveSupport::TimeZone::MAPPING.merge!(old_mappings) + end end |