aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/time_with_zone_test.rb
diff options
context:
space:
mode:
authorKevin McPhillips <github@kevinmcphillips.ca>2017-03-06 16:14:05 -0500
committerKevin McPhillips <github@kevinmcphillips.ca>2017-03-06 18:08:31 -0500
commit92fc8ec663f7dbb554c42dd41a86a7efe63dc725 (patch)
treecfb4e495b500b8bff5e76fe389fd67e590833af9 /activesupport/test/core_ext/time_with_zone_test.rb
parentbf388ecfc22d91f9716aca82cc4da5b583d87f17 (diff)
downloadrails-92fc8ec663f7dbb554c42dd41a86a7efe63dc725.tar.gz
rails-92fc8ec663f7dbb554c42dd41a86a7efe63dc725.tar.bz2
rails-92fc8ec663f7dbb554c42dd41a86a7efe63dc725.zip
Handle #to_time and memoization taking into account memoization, frozen state, and preserve_timezone flag.
Diffstat (limited to 'activesupport/test/core_ext/time_with_zone_test.rb')
-rw-r--r--activesupport/test/core_ext/time_with_zone_test.rb29
1 files changed, 24 insertions, 5 deletions
diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb
index 1534daacb9..ba15ea6b32 100644
--- a/activesupport/test/core_ext/time_with_zone_test.rb
+++ b/activesupport/test/core_ext/time_with_zone_test.rb
@@ -421,11 +421,29 @@ class TimeWithZoneTest < ActiveSupport::TestCase
assert_equal time, Time.at(time)
end
- def test_to_time
- with_env_tz "US/Eastern" do
- assert_equal Time, @twz.to_time.class
- assert_equal Time.local(1999, 12, 31, 19), @twz.to_time
- assert_equal Time.local(1999, 12, 31, 19).utc_offset, @twz.to_time.utc_offset
+ def test_to_time_with_preserve_timezone
+ with_preserve_timezone(true) do
+ with_env_tz "US/Eastern" do
+ time = @twz.to_time
+
+ assert_equal Time, time.class
+ assert_equal time.object_id, @twz.to_time.object_id
+ assert_equal Time.local(1999, 12, 31, 19), time
+ assert_equal Time.local(1999, 12, 31, 19).utc_offset, time.utc_offset
+ end
+ end
+ end
+
+ def test_to_time_without_preserve_timezone
+ with_preserve_timezone(false) do
+ with_env_tz "US/Eastern" do
+ time = @twz.to_time
+
+ assert_equal Time, time.class
+ assert_equal time.object_id, @twz.to_time.object_id
+ assert_equal Time.local(1999, 12, 31, 19), time
+ assert_equal Time.local(1999, 12, 31, 19).utc_offset, time.utc_offset
+ end
end
end
@@ -508,6 +526,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase
@twz.period
@twz.time
@twz.to_datetime
+ @twz.to_time
end
end