Skip to content
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

Hotfix for support of Rails 7.2.0 #1485

Merged
merged 8 commits into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ jobs:
# have set this up with each database as a separate job, but then we'd be
# duplicating the matrix configuration three times.
matrix:
gemfile: [ 'rails_6.1', 'rails_7.0', 'rails_7.1' ]
gemfile: [ 'rails_6.1', 'rails_7.0', 'rails_7.1', 'rails_7.2' ]

# To keep matrix size down, only test highest and lowest rubies.
# See "Lowest supported ruby version" in CONTRIBUTING.md
ruby: [ '3.0', '3.2' ]
ruby: [ '3.1', '3.3' ]
steps:
- name: Checkout source
uses: actions/checkout@v4
Expand Down
5 changes: 5 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ appraise "rails-7.1" do
gem "rails", "~> 7.1.0"
gem "rails-controller-testing", "~> 1.0.5"
end

appraise "rails-7.2" do
gem "rails", "~> 7.2.0"
gem "rails-controller-testing", "~> 1.0.5"
end
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Choose version:

| paper_trail | ruby | activerecord |
|-------------|----------|---------------|
| unreleased | >= 3.0.0 | >= 6.1, < 7.2 |
| unreleased | >= 3.0.0 | >= 6.1, <= 7.2 |

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kalashnikovisme and >= 3.1.0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it 🙂 Thanks!

| 15 | >= 3.0.0 | >= 6.1, < 7.2 |
| 14 | >= 2.7.0 | >= 6.0, < 7.1 |
| 13 | >= 2.6.0 | >= 5.2, < 7.1 |
Expand Down
8 changes: 8 additions & 0 deletions gemfiles/rails_7.2.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "rails", "~> 7.2.0"
gem "rails-controller-testing", "~> 1.0.5"

gemspec path: "../"
14 changes: 14 additions & 0 deletions lib/paper_trail/active_record_version_concern.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

# Is used to handle the deprecation warning in the different versions of ActiveRecord.
module ActiveRecordVersionConcern
module_function

def deprecation
if Gem::Version.new(ActiveRecord::VERSION::STRING) < Gem::Version.new("7.2")
::ActiveSupport::Deprecation
else
::ActiveSupport::Deprecation._instance
end
end
end
2 changes: 1 addition & 1 deletion lib/paper_trail/compatibility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module PaperTrail
# versions.
module Compatibility
ACTIVERECORD_GTE = ">= 6.1" # enforced in gemspec
ACTIVERECORD_LT = "< 7.2" # not enforced in gemspec
ACTIVERECORD_LT = "< 7.3" # not enforced in gemspec
Copy link

@joshRpowell joshRpowell Aug 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8.0 ?

ACTIVERECORD_LT = "< 8.0"

see https://github.com/rails/rails/milestones

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was set to < 8 originally but there was a request to set to < 7.3 here.


E_INCOMPATIBLE_AR = <<-EOS
PaperTrail %s is not compatible with ActiveRecord %s. We allow PT
Expand Down
6 changes: 4 additions & 2 deletions lib/paper_trail/model_config.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "paper_trail/active_record_version_concern"

module PaperTrail
# Configures an ActiveRecord model, mostly at application boot time, but also
# sometimes mid-request, with methods like enable/disable.
Expand Down Expand Up @@ -156,7 +158,7 @@ def check_version_class_name(options)
# @api private - `version_class_name`
@model_class.class_attribute :version_class_name
if options[:class_name]
::ActiveSupport::Deprecation.warn(
ActiveRecordVersionConcern.deprecation.warn(
format(
DPR_CLASS_NAME_OPTION,
class_name: options[:class_name].inspect
Expand Down Expand Up @@ -192,7 +194,7 @@ def define_has_many_versions(options)
def ensure_versions_option_is_hash(options)
unless options[:versions].is_a?(Hash)
if options[:versions]
::ActiveSupport::Deprecation.warn(
ActiveRecordVersionConcern.deprecation.warn(
format(
DPR_PASSING_ASSOC_NAME_DIRECTLY_TO_VERSIONS_OPTION,
versions_name: options[:versions].inspect
Expand Down
2 changes: 1 addition & 1 deletion spec/paper_trail/compatibility_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module PaperTrail

context "when incompatible" do
it "writes a warning to stderr" do
ar_version = ::Gem::Version.new("7.2.0")
ar_version = ::Gem::Version.new("8.0.0")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be 7.3 in line with the other changes?

Suggested change
ar_version = ::Gem::Version.new("8.0.0")
ar_version = ::Gem::Version.new("7.3.0")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a pretty interesting question.

I think no because there is > method in other places to compare versions. But in this place we have exact version to test with.

At the first version of this pull request, I used 7.3 because of these commits in the rails repository here and here. But I changed it to 8.0 because of this comment.

So, I think that we should use 7.3 in cases with >.

expect {
described_class.check_activerecord(ar_version)
}.to output(/not compatible/).to_stderr
Expand Down
8 changes: 4 additions & 4 deletions spec/paper_trail/model_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ module PaperTrail
describe "has_paper_trail" do
describe "versions:" do
it "name can be passed instead of an options hash", :deprecated do
allow(::ActiveSupport::Deprecation).to receive(:warn)
allow(ActiveRecordVersionConcern.deprecation).to receive(:warn)
klass = Class.new(ApplicationRecord) do
has_paper_trail versions: :drafts
end
expect(klass.reflect_on_association(:drafts)).to be_a(
ActiveRecord::Reflection::HasManyReflection
)
expect(::ActiveSupport::Deprecation).to have_received(:warn).once.with(
expect(ActiveRecordVersionConcern.deprecation).to have_received(:warn).once.with(
a_string_starting_with("Passing versions association name"),
array_including(/#{__FILE__}:/)
)
Expand Down Expand Up @@ -78,14 +78,14 @@ module PaperTrail

describe "class_name:" do
it "can be used instead of versions: {class_name: ...}", :deprecated do
allow(::ActiveSupport::Deprecation).to receive(:warn)
allow(ActiveRecordVersionConcern.deprecation).to receive(:warn)
klass = Class.new(ApplicationRecord) do
has_paper_trail class_name: "NoObjectVersion"
end
expect(klass.reflect_on_association(:versions).options[:class_name]).to eq(
"NoObjectVersion"
)
expect(::ActiveSupport::Deprecation).to have_received(:warn).once.with(
expect(ActiveRecordVersionConcern.deprecation).to have_received(:warn).once.with(
a_string_starting_with("Passing Version class name"),
array_including(/#{__FILE__}:/)
)
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
SimpleCov.start do
add_filter %w[Appraisals Gemfile Rakefile doc gemfiles spec]
end
SimpleCov.minimum_coverage(ENV["DB"] == "postgres" ? 96.79 : 92.4)
SimpleCov.minimum_coverage(ENV["DB"] == "postgres" ? 96.72 : 92.4)

require "byebug"
require_relative "support/pt_arel_helpers"
Expand Down
13 changes: 9 additions & 4 deletions spec/support/paper_trail_spec_migrator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ def initialize
end

def migrate
::ActiveRecord::MigrationContext.new(
@migrations_path,
::ActiveRecord::Base.connection.schema_migration
).migrate
schema_migration = if Gem::Version.new(ActiveRecord::VERSION::STRING) < Gem::Version.new("7.2")
::ActiveRecord::Base.connection.schema_migration
else
::ActiveRecord::SchemaMigration.new(
ActiveRecord::Tasks::DatabaseTasks.migration_connection_pool
)
end

::ActiveRecord::MigrationContext.new(@migrations_path, schema_migration).migrate
end

# Generate a migration, run it, and delete it. We use this for testing the
Expand Down