-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Rails 7.1 testing #35
Add Rails 7.1 testing #35
Conversation
These were the offenses: 68 Style/FrozenStringLiteralComment [Unsafe Correctable] 4 Performance/StringIdentifierArgument [Safe Correctable] 1 Style/HashEachMethods [Unsafe Correctable] Still sticking to `TargetRubyVersion` being 2.6 to avoid possibly autocorrecting in a backwards incompatible way, though
this workflow didn't run, probably because it's a syntax error to have two gemfile entries for a single ruby key (I wondered if I could have a single gemfile array keyval, but I'm trying to do the obvious thing first)
6802d21
to
259b3fc
Compare
InternalMetadata and friends no longer inherit from ActiveRecord::Base in 7.1, so calling `skip_audit_log` on them fails. This is a hacky workaround to avoid calling that when using Rails 7.1
this setting was removed in 7.1, so specs will fail (the dummy app's config sets it)
Rails.version returns the whole version string, we just need to see that we're on 7.0
@@ -12,6 +14,6 @@ module Dummy | |||
class Application < Rails::Application | |||
config.autoloader = Rails::VERSION::MAJOR >= 7 ? :zeitwerk : :classic | |||
config.active_record.sqlite3.represent_boolean_as_integer = true if Rails::VERSION::MAJOR < 6 | |||
config.active_record.legacy_connection_handling = false if Rails::VERSION::MAJOR >= 7 | |||
config.active_record.legacy_connection_handling = false if Rails::VERSION::MAJOR == 7 && Rails::VERSION::MINOR == 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This setting was removed in 7.1.
@@ -34,7 +36,7 @@ Gem::Specification.new do |s| | |||
s.add_development_dependency "rspec-rails" | |||
s.add_development_dependency "spring" | |||
s.add_development_dependency "spring-commands-rspec" | |||
s.add_development_dependency "sqlite3" | |||
s.add_development_dependency "sqlite3", '~> 1.4' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was facing some CI troubles when this was unpinned, e.g. https://github.com/Betterment/journaled/actions/runs/8727969396/job/23946685922. I'm guessing this hadn't surfaced before because the newer versions didn't exist(?)
module Journaled | ||
VERSION = "5.3.1".freeze | ||
VERSION = "5.3.2" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm only bumping patch because our actual dependencies were already sitting on 7.1 versions and I'm not dropping support for anything. We simply didn't actually test them in CI.
lib/journaled/audit_log.rb
Outdated
|
||
# These classes do not inherit from ActiveRecord::Base in 7.1 | ||
# so calling `skip_audit_log` on them will raise. | ||
%w(ActiveRecord::InternalMetadata ActiveRecord::SchemaMigration).include?(name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am assuming the original reason for skipping these was that we didn't want them to have the callbacks defined in this module, but that they would have them because we include
the module in the on_load
hook for AR (i.e. in 7.1, since these classes don't inherit from Base, then they don't get the methods after all)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to exclude these from DEFAULT_EXCLUDED_CLASSES
at class load time if we're on 7.1 or greater?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(And, yeah, that was the goal. If they don't inherit, then they don't need to be included.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, we could check .respond_to?(:skip_audit_log)
, but I would start with the more explicit list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes total sense; I updated the const's assignment and removed this method! I felt like inlining the array for both branches of the if-expr wasn't that bad/verbose (and decided to drop it by a line to avoid having a huge indent).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TAFN -- just the one question about changing the way the constant is defined, rather than dynamically skipping the classes later.
… time from PR feedback; instead of doing the version check at runtime, do it at class load time, i.e. when the constant is defined
if Gem::Version.new(Rails.version) < Gem::Version.new('7.1') | ||
%w( | ||
Delayed::Job | ||
PaperTrail::Version | ||
ActiveStorage::Attachment | ||
ActiveStorage::Blob | ||
ActiveRecord::InternalMetadata | ||
ActiveRecord::SchemaMigration | ||
) | ||
else | ||
%w( | ||
Delayed::Job | ||
PaperTrail::Version | ||
ActiveStorage::Attachment | ||
ActiveStorage::Blob | ||
) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to just have the same if-expr here instead of fiddling with mocking the version and whatnot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
domain LGTM && platform LGTM!
@argvniyx-enroute @smudge: Unblocked! - disabled Semgrep for this repo. |
Summary
I stumbled upon an error when trying to add Rails 7.1 support to a
journaled
dependent: inaudit_log.rb
, we callskip_audit_log
on certain ActiveRecord classes which no longer inherit fromActiveRecord::Base
in 7.1, so that would raise with aNoMethodError
. This PR:.ruby-version
to 3.2.2 (most if not all of us are using >=3.0) as our daily driver, so it's a bit of an ergonomic change)frozen_string_literal: true
lints; mostly felt the need to do this to unblock runningbe rake
locally)skip_audit_log
on ActiveRecord classes when on Rails 7.1legacy_connection_handling
when on Rails 7.0Other Information
There might be some other things worth considering (not ignoring lockfiles(?), actually using the new connection handling (even if it is only a dummy app)) but I didn't want to drag out a PR that's already pretty big.
/domain @smudge @Betterment/journaled-owners
/platform @smudge