Skip to content

Commit 4bf5499

Browse files
BuonOmorafiss
authored andcommitted
chore(test): update helper
1 parent 1b17ecd commit 4bf5499

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

test/cases/helper.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
require "cases/test_case"
1313
require "active_support/dependencies"
1414
require "active_support/logger"
15+
require "active_support/core_ext/kernel/reporting"
1516
require "active_support/core_ext/kernel/singleton_class"
1617

1718
require "support/config"
@@ -105,6 +106,7 @@ def with_timezone_config(cfg)
105106

106107
old_default_zone = ActiveRecord.default_timezone
107108
old_awareness = ActiveRecord::Base.time_zone_aware_attributes
109+
old_aware_types = ActiveRecord::Base.time_zone_aware_types
108110
old_zone = Time.zone
109111

110112
if cfg.has_key?(:default)
@@ -113,19 +115,24 @@ def with_timezone_config(cfg)
113115
if cfg.has_key?(:aware_attributes)
114116
ActiveRecord::Base.time_zone_aware_attributes = cfg[:aware_attributes]
115117
end
118+
if cfg.has_key?(:aware_types)
119+
ActiveRecord::Base.time_zone_aware_types = cfg[:aware_types]
120+
end
116121
if cfg.has_key?(:zone)
117122
Time.zone = cfg[:zone]
118123
end
119124
yield
120125
ensure
121126
ActiveRecord.default_timezone = old_default_zone
122127
ActiveRecord::Base.time_zone_aware_attributes = old_awareness
128+
ActiveRecord::Base.time_zone_aware_types = old_aware_types
123129
Time.zone = old_zone
124130
end
125131

126132
# This method makes sure that tests don't leak global state related to time zones.
127133
EXPECTED_ZONE = nil
128134
EXPECTED_DEFAULT_TIMEZONE = :utc
135+
EXPECTED_AWARE_TYPES = [:datetime, :time]
129136
EXPECTED_TIME_ZONE_AWARE_ATTRIBUTES = false
130137
def verify_default_timezone_config
131138
if Time.zone != EXPECTED_ZONE
@@ -152,6 +159,14 @@ def verify_default_timezone_config
152159
Got: #{ActiveRecord::Base.time_zone_aware_attributes}
153160
MSG
154161
end
162+
if ActiveRecord::Base.time_zone_aware_types != EXPECTED_AWARE_TYPES
163+
$stderr.puts <<-MSG
164+
\n#{self}
165+
Global state `ActiveRecord::Base.time_zone_aware_types` was leaked.
166+
Expected: #{EXPECTED_AWARE_TYPES}
167+
Got: #{ActiveRecord::Base.time_zone_aware_types}
168+
MSG
169+
end
155170
end
156171

157172
def enable_extension!(extension, connection)

0 commit comments

Comments
 (0)