未验证 提交 b6577cb6 编写于 作者: A Andrew White 提交者: GitHub

Merge pull request #32613 from dsander/fix-as-timezone-all

Fix exception in AS::Timezone.all when any tzinfo data is missing
* 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.)
......
......@@ -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
......
......@@ -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)"]
......
......@@ -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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册