Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions lib/plsql/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,15 @@ def default_timezone
@original_schema.default_timezone
else
@default_timezone ||
# Use ActiveRecord default_timezone when ActiveRecord connection is used,
# preferring the connection's activerecord_class so a subclass override
# (available in AR < 8.0) is honored before falling back to the
# module-level accessor (AR 7.0+; the only one in AR 8.0+).
(@connection && (ar_class = @connection.activerecord_class) &&
(ar_class.respond_to?(:default_timezone) ? ar_class.default_timezone : ActiveRecord.default_timezone)) ||
# Use ActiveRecord default_timezone when ActiveRecord connection is used.
# Prefer the module-level accessor (AR 7.0+; the only one in AR 8.0+) so
# that AR 7.0/7.1's deprecation warning for ActiveRecord::Base.default_timezone
# is not emitted. Fall back to the per-class accessor only on pre-7.0 AR,
# where ActiveRecord.default_timezone does not exist.
(@connection && @connection.activerecord_class &&
(ActiveRecord.respond_to?(:default_timezone) ?
ActiveRecord.default_timezone :
@connection.activerecord_class.default_timezone)) ||
Comment thread
yahonda marked this conversation as resolved.
# default to local timezone
:local
end
Expand Down
20 changes: 20 additions & 0 deletions spec/plsql/schema_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,26 @@ class TestModel < TestBaseModel
expect(plsql.default_timezone).to eq(:utc)
end

it "should not emit ActiveRecord::Base.default_timezone deprecation warning (#234)" do
skip "ActiveRecord.default_timezone is not available" unless ActiveRecord.respond_to?(:default_timezone=)

original_default_timezone = ActiveRecord.default_timezone
ActiveRecord.default_timezone = :utc

deprecator = ActiveRecord.respond_to?(:deprecator) ? ActiveRecord.deprecator : ActiveSupport::Deprecation
original_behavior = deprecator.behavior
warnings = []
Comment thread
yahonda marked this conversation as resolved.
begin
deprecator.behavior = ->(message, *) { warnings << message }
expect(plsql.default_timezone).to eq(:utc)
ensure
deprecator.behavior = original_behavior
ActiveRecord.default_timezone = original_default_timezone
end

expect(warnings.grep(/default_timezone/)).to be_empty
end

it "should have the same connection as default schema" do
expect(plsql.hr.connection).to eq(plsql.connection)
end
Expand Down
Loading