Skip to content

Commit

Permalink
Merge pull request #32613 from dsander/fix-as-timezone-all
Browse files Browse the repository at this point in the history
Fix exception in AS::Timezone.all when any tzinfo data is missing
  • Loading branch information
pixeltrix committed Apr 19, 2018
2 parents ef2af62 + fb2af6f commit b6577cb
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
5 changes: 5 additions & 0 deletions 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.)

Expand Down
3 changes: 2 additions & 1 deletion activesupport/lib/active_support/values/time_zone.rb
Expand Up @@ -279,7 +279,8 @@ def load_country_zones(code)

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
Expand Down
15 changes: 15 additions & 0 deletions activesupport/test/time_zone_test.rb
Expand Up @@ -725,6 +725,21 @@ def test_all_uninfluenced_by_time_zone_lookups_delegated_to_tzinfo
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)"]
Expand Down
13 changes: 13 additions & 0 deletions activesupport/test/time_zone_test_helpers.rb
Expand Up @@ -23,4 +23,17 @@ def with_preserve_timezone(value)
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

0 comments on commit b6577cb

Please sign in to comment.