File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -99,12 +99,15 @@ def default_timezone
9999 @original_schema . default_timezone
100100 else
101101 @default_timezone ||
102- # Use ActiveRecord default_timezone when ActiveRecord connection is used,
103- # preferring the connection's activerecord_class so a subclass override
104- # (available in AR < 8.0) is honored before falling back to the
105- # module-level accessor (AR 7.0+; the only one in AR 8.0+).
106- ( @connection && ( ar_class = @connection . activerecord_class ) &&
107- ( ar_class . respond_to? ( :default_timezone ) ? ar_class . default_timezone : ActiveRecord . default_timezone ) ) ||
102+ # Use ActiveRecord default_timezone when ActiveRecord connection is used.
103+ # Prefer the module-level accessor (AR 7.0+; the only one in AR 8.0+) so
104+ # that AR 7.0/7.1's deprecation warning for ActiveRecord::Base.default_timezone
105+ # is not emitted. Fall back to the per-class accessor only on pre-7.0 AR,
106+ # where ActiveRecord.default_timezone does not exist.
107+ ( @connection && @connection . activerecord_class &&
108+ ( ActiveRecord . respond_to? ( :default_timezone ) ?
109+ ActiveRecord . default_timezone :
110+ @connection . activerecord_class . default_timezone ) ) ||
108111 # default to local timezone
109112 :local
110113 end
Original file line number Diff line number Diff line change @@ -218,6 +218,26 @@ class TestModel < TestBaseModel
218218 expect ( plsql . default_timezone ) . to eq ( :utc )
219219 end
220220
221+ it "should not emit ActiveRecord::Base.default_timezone deprecation warning (#234)" do
222+ skip "ActiveRecord.default_timezone is not available" unless ActiveRecord . respond_to? ( :default_timezone= )
223+
224+ original_default_timezone = ActiveRecord . default_timezone
225+ ActiveRecord . default_timezone = :utc
226+
227+ deprecator = ActiveRecord . respond_to? ( :deprecator ) ? ActiveRecord . deprecator : ActiveSupport ::Deprecation
228+ original_behavior = deprecator . behavior
229+ warnings = [ ]
230+ begin
231+ deprecator . behavior = -> ( message , *) { warnings << message }
232+ expect ( plsql . default_timezone ) . to eq ( :utc )
233+ ensure
234+ deprecator . behavior = original_behavior
235+ ActiveRecord . default_timezone = original_default_timezone
236+ end
237+
238+ expect ( warnings . grep ( /default_timezone/ ) ) . to be_empty
239+ end
240+
221241 it "should have the same connection as default schema" do
222242 expect ( plsql . hr . connection ) . to eq ( plsql . connection )
223243 end
You can’t perform that action at this time.
0 commit comments