Skip to content

Commit

Permalink
Support Rails 7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
theodorton committed Jun 17, 2024
1 parent 67a1ec2 commit 5ffca52
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 11 deletions.
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.beta1"
gem "rails-controller-testing", "~> 1.0.5"
end
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.beta1"
gem "rails-controller-testing", "~> 1.0.5"

gemspec path: "../"
4 changes: 4 additions & 0 deletions lib/paper_trail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ def version
def active_record_gte_7_0?
@active_record_gte_7_0 ||= ::ActiveRecord.gem_version >= ::Gem::Version.new("7.0.0")
end

def deprecator
@deprecator ||= ActiveSupport::Deprecation.new("16.0", "PaperTrail")
end
end
end

Expand Down
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

E_INCOMPATIBLE_AR = <<-EOS
PaperTrail %s is not compatible with ActiveRecord %s. We allow PT
Expand Down
6 changes: 5 additions & 1 deletion lib/paper_trail/frameworks/rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Railtie < ::Rails::Railtie
# We specify `before: "load_config_initializers"` to ensure that the PT
# initializer happens before "app initializers" (those defined in
# the app's `config/initalizers`).
initializer "paper_trail", before: "load_config_initializers" do
initializer "paper_trail", before: "load_config_initializers" do |app|
# `on_load` is a "lazy load hook". It "declares a block that will be
# executed when a Rails component is fully loaded". (See
# `active_support/lazy_load_hooks.rb`)
Expand All @@ -25,6 +25,10 @@ class Railtie < ::Rails::Railtie
ActiveSupport.on_load(:active_record) do
require "paper_trail/frameworks/active_record"
end

if ::Rails::VERSION::STRING >= "7.1"
app.deprecators[:paper_trail] = PaperTrail.deprecator
end
end
end
end
4 changes: 2 additions & 2 deletions lib/paper_trail/model_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,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(
PaperTrail.deprecator.warn(
format(
DPR_CLASS_NAME_OPTION,
class_name: options[:class_name].inspect
Expand Down Expand Up @@ -192,7 +192,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(
PaperTrail.deprecator.warn(
format(
DPR_PASSING_ASSOC_NAME_DIRECTLY_TO_VERSIONS_OPTION,
versions_name: options[:versions].inspect
Expand Down
2 changes: 1 addition & 1 deletion paper_trail.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ has been destroyed.
# PT supports request_store versions for 3 years.
s.add_dependency "request_store", "~> 1.4"

s.add_development_dependency "appraisal", "~> 2.4.1"
s.add_development_dependency "appraisal", "~> 2.5.0"
s.add_development_dependency "byebug", "~> 11.1"
s.add_development_dependency "ffaker", "~> 2.20"
s.add_development_dependency "generator_spec", "~> 0.9.4"
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("7.3.0")
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(::PaperTrail.deprecator).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(::PaperTrail.deprecator).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(::PaperTrail.deprecator).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(::PaperTrail.deprecator).to have_received(:warn).once.with(
a_string_starting_with("Passing Version class name"),
array_including(/#{__FILE__}:/)
)
Expand Down
10 changes: 9 additions & 1 deletion spec/support/paper_trail_spec_migrator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def initialize
def migrate
::ActiveRecord::MigrationContext.new(
@migrations_path,
::ActiveRecord::Base.connection.schema_migration
schema_migration
).migrate
end

Expand All @@ -45,6 +45,14 @@ def generate_and_migrate(generator, generator_invoke_args)

private

def schema_migration
if Rails::VERSION::STRING >= "7.2"
::ActiveRecord::Base.connection_pool.schema_migration
else
::ActiveRecord::Base.connection.schema_migration
end
end

def dummy_app_migrations_dir
Pathname.new(File.expand_path("../dummy_app/db/migrate", __dir__))
end
Expand Down

0 comments on commit 5ffca52

Please sign in to comment.