File tree Expand file tree Collapse file tree 2 files changed +21
-4
lines changed Expand file tree Collapse file tree 2 files changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -185,12 +185,19 @@ module Tasks
185
185
singleton_class . attr_accessor :legacy_connection_handling
186
186
self . legacy_connection_handling = true
187
187
188
- ##
189
- # :singleton-method:
190
188
# Determines whether to use Time.utc (using :utc) or Time.local (using :local) when pulling
191
189
# dates and times from the database. This is set to :utc by default.
192
- singleton_class . attr_accessor :default_timezone
193
- self . default_timezone = :utc
190
+ def self . default_timezone = ( default_timezone )
191
+ unless %i[ local utc ] . include? ( default_timezone )
192
+ raise ArgumentError , 'default_timezone must be either :utc (default) or :local'
193
+ end
194
+
195
+ @default_timezone = default_timezone
196
+ end
197
+
198
+ def self . default_timezone
199
+ @default_timezone ||= :utc
200
+ end
194
201
195
202
singleton_class . attr_accessor :writing_role
196
203
self . writing_role = :writing
Original file line number Diff line number Diff line change 7
7
class DateTimeTest < ActiveRecord ::TestCase
8
8
include InTimeZone
9
9
10
+ def test_default_timezone_validation
11
+ assert_raises ArgumentError do
12
+ ActiveRecord . default_timezone = 'UTC'
13
+ end
14
+
15
+ # These values should not raise errors
16
+ ActiveRecord . default_timezone = :local
17
+ ActiveRecord . default_timezone = :utc
18
+ end
19
+
10
20
def test_saves_both_date_and_time
11
21
with_env_tz "America/New_York" do
12
22
with_timezone_config default : :utc do
You can’t perform that action at this time.
0 commit comments