Skip to content

Commit d3ff790

Browse files
committed
Make ActiveRecord timezone tests fail reliably
1 parent 399af7f commit d3ff790

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

activerecord/test/cases/base_test.rb

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,14 +1117,16 @@ def test_default_char_types
11171117
end
11181118

11191119
def test_default_in_local_time
1120-
with_timezone_config default: :local do
1121-
default = Default.new
1120+
with_env_tz do
1121+
with_timezone_config default: :local do
1122+
default = Default.new
11221123

1123-
assert_equal Date.new(2004, 1, 1), default.fixed_date
1124-
assert_equal Time.local(2004, 1, 1, 0, 0, 0, 0), default.fixed_time
1124+
assert_equal Date.new(2004, 1, 1), default.fixed_date
1125+
assert_equal Time.local(2004, 1, 1, 0, 0, 0, 0), default.fixed_time
11251126

1126-
if current_adapter?(:PostgreSQLAdapter)
1127-
assert_equal Time.utc(2004, 1, 1, 0, 0, 0, 0), default.fixed_time_with_time_zone
1127+
if current_adapter?(:PostgreSQLAdapter)
1128+
assert_equal Time.utc(2004, 1, 1, 0, 0, 0, 0), default.fixed_time_with_time_zone
1129+
end
11281130
end
11291131
end
11301132
end
@@ -1157,6 +1159,19 @@ def test_default_in_utc_with_time_zone
11571159
end
11581160
end
11591161

1162+
def test_switching_default_time_zone
1163+
with_env_tz do
1164+
2.times do
1165+
with_timezone_config default: :local do
1166+
assert_equal Time.local(2004, 1, 1, 0, 0, 0, 0), Default.new.fixed_time
1167+
end
1168+
with_timezone_config default: :utc do
1169+
assert_equal Time.utc(2004, 1, 1, 0, 0, 0, 0), Default.new.fixed_time
1170+
end
1171+
end
1172+
end
1173+
end
1174+
11601175
unless in_memory_db?
11611176
def test_connection_in_local_time
11621177
with_timezone_config default: :utc do

0 commit comments

Comments
 (0)