1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Make ActiveSupport::TimeZone.all independent of previous lookups (#31176)

This commit is contained in:
Chris LaRose 2017-11-22 09:12:08 -08:00 committed by Andrew White
parent 858baa099b
commit 078421bacb
3 changed files with 23 additions and 3 deletions

View file

@ -1,3 +1,10 @@
* Make `ActiveSupport::TimeZone.all` return only time zones that are in
`ActiveSupport::TimeZone::MAPPING`.
Fixes #7245.
*Chris LaRose*
* MemCacheStore: Support expiring counters.
Pass `expires_in: [seconds]` to `#increment` and `#decrement` options

View file

@ -256,6 +256,13 @@ module ActiveSupport
@country_zones[code] ||= load_country_zones(code)
end
def clear() #:nodoc:
@lazy_zones_map = Concurrent::Map.new
@country_zones = Concurrent::Map.new
@zones = nil
@zones_map = nil
end
private
def load_country_zones(code)
country = TZInfo::Country.get(code)
@ -269,9 +276,8 @@ module ActiveSupport
end
def zones_map
@zones_map ||= begin
MAPPING.each_key { |place| self[place] } # load all the zones
@lazy_zones_map
@zones_map ||= MAPPING.each_with_object({}) do |(name, _), zones|
zones[name] = self[name]
end
end
end

View file

@ -718,6 +718,13 @@ class TimeZoneTest < ActiveSupport::TestCase
end
end
def test_all_uninfluenced_by_time_zone_lookups_delegated_to_tzinfo
ActiveSupport::TimeZone.clear
galapagos = ActiveSupport::TimeZone["Pacific/Galapagos"]
all_zones = ActiveSupport::TimeZone.all
assert_not_includes all_zones, galapagos
end
def test_index
assert_nil ActiveSupport::TimeZone["bogus"]
assert_instance_of ActiveSupport::TimeZone, ActiveSupport::TimeZone["Central Time (US & Canada)"]