diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index caf6872..127d266 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - ruby-version: ["3.4", "3.3", "3.2", "3.1", "3.0", "2.7", "2.6"] + ruby-version: ["3.4", "3.3", "3.2", "3.1", "3.0", "2.7", "2.6", "2.5"] steps: - uses: actions/checkout@v2 diff --git a/CHANGELOG.md b/CHANGELOG.md index eccfb1f..caffef8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,13 @@ -# main [(unreleased)](https://github.com/fastruby/next_rails/compare/v1.4.3...main) +# main [(unreleased)](https://github.com/fastruby/next_rails/compare/v1.4.4...main) - [BUGFIX: example](https://github.com/fastruby/next_rails/pull/) * Your changes/patches go here. +# v1.4.4 / 2025-02-26 [(commits)](https://github.com/fastruby/next_rails/compare/v1.4.3...v1.4.4) + +- [FEATURE: Update deprecation tracker to support newer Rails versions (7.1+)](https://github.com/fastruby/next_rails/pull/142) + # v1.4.3 / 2025-02-20 [(commits)](https://github.com/fastruby/next_rails/compare/v1.4.2...v1.4.3) - [Add next_rails --init](https://github.com/fastruby/next_rails/pull/139) diff --git a/README.md b/README.md index 6eec4b0..6fa169a 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,7 @@ next_rails --help # For more options and examples This command helps you dual-boot your application. ```bash -next --init # Create Gemfile.next and Gemfile.next.lock +next_next --init # Create Gemfile.next and Gemfile.next.lock vim Gemfile # Tweak your dependencies conditionally using `next?` next bundle install # Install new gems next rails s # Start server using Gemfile.next @@ -168,7 +168,7 @@ Or install it yourself as: Execute: - $ next --init + $ next_rails --init Init will create a Gemfile.next and an initialized Gemfile.next.lock. The Gemfile.next.lock is initialized with the contents of your existing diff --git a/lib/deprecation_tracker.rb b/lib/deprecation_tracker.rb index 7d76360..c7ade8d 100644 --- a/lib/deprecation_tracker.rb +++ b/lib/deprecation_tracker.rb @@ -73,7 +73,17 @@ def self.init_tracker(opts = {}) mode = opts[:mode] transform_message = opts[:transform_message] deprecation_tracker = DeprecationTracker.new(shitlist_path, transform_message, mode) - if defined?(ActiveSupport) + # Since Rails 7.1 the preferred way to track deprecations is to use the deprecation trackers via + # `Rails.application.deprecators`. + # We fallback to tracking deprecations via the ActiveSupport singleton object if Rails.application.deprecators is + # not defined for older Rails versions. + if defined?(Rails) && defined?(Rails.application) && defined?(Rails.application.deprecators) + Rails.application.deprecators.each do |deprecator| + deprecator.behavior << -> (message, _callstack = nil, _deprecation_horizon = nil, _gem_name = nil) { + deprecation_tracker.add(message) + } + end + elsif defined?(ActiveSupport) ActiveSupport::Deprecation.behavior << -> (message, _callstack = nil, _deprecation_horizon = nil, _gem_name = nil) { deprecation_tracker.add(message) } diff --git a/lib/next_rails/version.rb b/lib/next_rails/version.rb index 8d4ea73..f823a0c 100644 --- a/lib/next_rails/version.rb +++ b/lib/next_rails/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module NextRails - VERSION = "1.4.3" + VERSION = "1.4.4" end diff --git a/spec/deprecation_tracker_spec.rb b/spec/deprecation_tracker_spec.rb index a3fda3a..21d7dfe 100644 --- a/spec/deprecation_tracker_spec.rb +++ b/spec/deprecation_tracker_spec.rb @@ -251,6 +251,48 @@ end end + describe "#init_tracker" do + it "returns a new instance of DeprecationTracker" do + tracker = DeprecationTracker.init_tracker({mode: "save"}) + expect(tracker).to be_a(DeprecationTracker) + end + + it "subscribes to KernelWarnTracker deprecation events" do + expect do + DeprecationTracker.init_tracker({mode: "save"}) + end.to change(DeprecationTracker::KernelWarnTracker.callbacks, :size).by(1) + end + + context "when Rails.application.deprecation is not defined and ActiveSupport is defined" do + it "sets the ActiveSupport::Deprecation behavior" do + # Stub ActiveSupport::Deprecation with a simple behavior array + stub_const("ActiveSupport::Deprecation", Class.new { + def self.behavior + @behavior ||= [] + end + }) + + expect do + DeprecationTracker.init_tracker({mode: "save"}) + end.to change(ActiveSupport::Deprecation.behavior, :size).by(1) + end + end + + context "when Rails.application.deprecation is defined" do + it "sets the behavior of each Rails.application.deprecators" do + # Stub Rails.application.deprecators with an array of mock deprecators + fake_deprecator_1 = double("Deprecator", behavior: []) + fake_deprecator_2 = double("Deprecator", behavior: []) + stub_const("Rails", Module.new) + allow(Rails).to receive_message_chain(:application, :deprecators).and_return([fake_deprecator_1, fake_deprecator_2]) + + expect do + DeprecationTracker.init_tracker({ mode: "save" }) + end.to change(fake_deprecator_1.behavior, :size).by(1).and change(fake_deprecator_2.behavior, :size).by(1) + end + end + end + describe DeprecationTracker::KernelWarnTracker do it "captures Kernel#warn" do warn_messages = []