aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
diff options
context:
space:
mode:
authorAndrew White <pixeltrix@users.noreply.github.com>2018-04-19 09:25:02 +0100
committerGitHub <noreply@github.com>2018-04-19 09:25:02 +0100
commitb6577cb62880a88380fce6a086a1c084d5a74c18 (patch)
tree9ea30543b6b2f68f15d9c0b711054ee035a4b8fe /activesupport/test
parentef2af628a9ec1cc4e7b6997a021dd3f85cfe4665 (diff)
parentfb2af6f849c8d25732f2c17352c59f2dc8b8320d (diff)
downloadrails-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/test')
-rw-r--r--activesupport/test/time_zone_test.rb15
-rw-r--r--activesupport/test/time_zone_test_helpers.rb13
2 files changed, 28 insertions, 0 deletions
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