aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/date_time_ext_test.rb
diff options
context:
space:
mode:
authorAndrew White <andrew.white@unboxedconsulting.com>2016-04-28 07:53:24 +0100
committerAndrew White <andrew.white@unboxed.co>2016-05-05 05:07:58 +0100
commitb782665cbb55260bfdfc19c366c5fbc4ddd6fb12 (patch)
tree05400632f01dce3874b6342b8202775a8fe2fcee /activesupport/test/core_ext/date_time_ext_test.rb
parente77588d4e14f4720db5bfce5aff7cd5ab3218a29 (diff)
downloadrails-b782665cbb55260bfdfc19c366c5fbc4ddd6fb12.tar.gz
rails-b782665cbb55260bfdfc19c366c5fbc4ddd6fb12.tar.bz2
rails-b782665cbb55260bfdfc19c366c5fbc4ddd6fb12.zip
Fix tests when preserving timezones
These two tests are explicitly testing that to_time is returning times with the sytem timezone's UTC offset, therefore they will fail when running them with `ActiveSupport.to_time_preserves_timezone = true`.
Diffstat (limited to 'activesupport/test/core_ext/date_time_ext_test.rb')
-rw-r--r--activesupport/test/core_ext/date_time_ext_test.rb10
1 files changed, 8 insertions, 2 deletions
diff --git a/activesupport/test/core_ext/date_time_ext_test.rb b/activesupport/test/core_ext/date_time_ext_test.rb
index fcd739c804..306316efcd 100644
--- a/activesupport/test/core_ext/date_time_ext_test.rb
+++ b/activesupport/test/core_ext/date_time_ext_test.rb
@@ -69,8 +69,14 @@ class DateTimeExtCalculationsTest < ActiveSupport::TestCase
def test_to_time
with_env_tz 'US/Eastern' do
assert_instance_of Time, DateTime.new(2005, 2, 21, 10, 11, 12, 0).to_time
- assert_equal Time.local(2005, 2, 21, 5, 11, 12), DateTime.new(2005, 2, 21, 10, 11, 12, 0).to_time
- assert_equal Time.local(2005, 2, 21, 5, 11, 12).utc_offset, DateTime.new(2005, 2, 21, 10, 11, 12, 0).to_time.utc_offset
+
+ if ActiveSupport.to_time_preserves_timezone
+ assert_equal Time.local(2005, 2, 21, 5, 11, 12).getlocal(0), DateTime.new(2005, 2, 21, 10, 11, 12, 0).to_time
+ assert_equal Time.local(2005, 2, 21, 5, 11, 12).getlocal(0).utc_offset, DateTime.new(2005, 2, 21, 10, 11, 12, 0).to_time.utc_offset
+ else
+ assert_equal Time.local(2005, 2, 21, 5, 11, 12), DateTime.new(2005, 2, 21, 10, 11, 12, 0).to_time
+ assert_equal Time.local(2005, 2, 21, 5, 11, 12).utc_offset, DateTime.new(2005, 2, 21, 10, 11, 12, 0).to_time.utc_offset
+ end
end
end