Commit 7cea354
Prefer ActiveRecord.default_timezone over per-class accessor (rsim#234)
Calling `ar_class.default_timezone` on Rails 7.0.x prints
DEPRECATION WARNING: ActiveRecord::Base.default_timezone is
deprecated and will be removed in Rails 7.1. Use
ActiveRecord.default_timezone instead.
even though both accessors return the same value. The per-class
accessor was introduced as a deprecated proxy in Rails 7.0
(rails/rails@c3f43075a3) and removed entirely in Rails 7.1
(rails/rails@96c9db1b48), so the warning only fires on Rails 7.0.x.
Switch the order in PLSQL::Schema#default_timezone so that we ask the
module-level ActiveRecord.default_timezone first when it is available
(AR 7.0+) and only fall back to the per-class accessor on pre-7.0 AR
where the module-level one does not exist. This silences the warning
on Rails 7.0.x and is a no-op on Rails 7.1+ (where the per-class
accessor was already gone) and on Rails <= 6.x (where the module-level
accessor did not yet exist).
Add a regression test that captures deprecator output while resolving
plsql.default_timezone with `activerecord_class` set, and asserts that
no warning mentioning default_timezone was raised. The existing
ActiveRecord.default_timezone is captured before assignment and
restored from the ensure block alongside the deprecator behavior so
the test is order-independent.
Verified by rsim#269 / rsim#271 that the test fails on AR 7.0 without this fix
and passes on AR 7.1+ regardless.
Fixes rsim#234
References:
- rails/rails@c3f43075a3 (added the deprecated delegators in Rails 7.0)
- rails/rails@96c9db1b48 (removed them in Rails 7.1)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent e39e8e4 commit 7cea354
2 files changed
Lines changed: 29 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
108 | 111 | | |
109 | 112 | | |
110 | 113 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
218 | 218 | | |
219 | 219 | | |
220 | 220 | | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
221 | 241 | | |
222 | 242 | | |
223 | 243 | | |
| |||
0 commit comments