aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
diff options
context:
space:
mode:
authorAlexey Shein <alexey.shein.dev@gmail.com>2016-04-21 03:53:48 +0500
committerJeremy Daer <jeremydaer@gmail.com>2016-04-25 20:55:33 -0500
commit420730b10b46be7e40d806007bb28d3b17c7519f (patch)
tree66503d58e8084581f27494c9a536960276effc4f /activesupport/test
parentea628f72c3f6ef77752794356fcb358858fd8827 (diff)
downloadrails-420730b10b46be7e40d806007bb28d3b17c7519f.tar.gz
rails-420730b10b46be7e40d806007bb28d3b17c7519f.tar.bz2
rails-420730b10b46be7e40d806007bb28d3b17c7519f.zip
Do not cache ActiveSupport::TimeZone#utc_offset
This can be an issue when TZInfo::TimeZone#current_period is refreshed due to timezone period transition, but it's not reflected in ActiveSupport::TimeZone object. For example, on Sun, 26 Oct 2014 22:00 UTC, Moscow changed its TZ from MSK +04:00 to MSK +03:00 (-1 hour). If ActiveSupport::TimeZone['Moscow'] happens to be initialized just before the timezone transition, it will cache its stale utc_offset even after the timezone transition. This commit removes cache and fixes this issue. Signed-off-by: Jeremy Daer <jeremydaer@gmail.com>
Diffstat (limited to 'activesupport/test')
-rw-r--r--activesupport/test/time_zone_test.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb
index d0674eb03a..a15d5c6a0e 100644
--- a/activesupport/test/time_zone_test.rb
+++ b/activesupport/test/time_zone_test.rb
@@ -395,6 +395,17 @@ class TimeZoneTest < ActiveSupport::TestCase
assert_equal(-18_000, zone.utc_offset)
end
+ def test_utc_offset_is_not_cached_when_current_period_gets_stale
+ tz = ActiveSupport::TimeZone.create('Moscow')
+ travel_to(Time.utc(2014, 10, 25, 21)) do # 1 hour before TZ change
+ assert_equal 14400, tz.utc_offset, 'utc_offset should be initialized according to current_period'
+ end
+
+ travel_to(Time.utc(2014, 10, 25, 22)) do # after TZ change
+ assert_equal 10800, tz.utc_offset, 'utc_offset should not be cached when current_period gets stale'
+ end
+ end
+
def test_seconds_to_utc_offset_with_colon
assert_equal "-06:00", ActiveSupport::TimeZone.seconds_to_utc_offset(-21_600)
assert_equal "+00:00", ActiveSupport::TimeZone.seconds_to_utc_offset(0)