1212require "cases/test_case"
1313require "active_support/dependencies"
1414require "active_support/logger"
15+ require "active_support/core_ext/kernel/reporting"
1516require "active_support/core_ext/kernel/singleton_class"
1617
1718require "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
120125ensure
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
124130end
125131
126132# This method makes sure that tests don't leak global state related to time zones.
127133EXPECTED_ZONE = nil
128134EXPECTED_DEFAULT_TIMEZONE = :utc
135+ EXPECTED_AWARE_TYPES = [ :datetime , :time ]
129136EXPECTED_TIME_ZONE_AWARE_ATTRIBUTES = false
130137def 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
155170end
156171
157172def enable_extension! ( extension , connection )
0 commit comments