From 317dd938dd15fb84a764b66983852012f7651001 Mon Sep 17 00:00:00 2001 From: Alejandro Perea Date: Wed, 6 Dec 2023 18:05:54 +0100 Subject: [PATCH] [Fix #903] Fix deprecation warning in LogSubscriber when updating to Rails 7.1 (#907) --- .github/workflows/ruby.yml | 2 +- CHANGELOG.md | 2 ++ gemfiles/rails.7.1.activerecord.gemfile | 13 +++++++++++++ lib/chewy.rb | 1 + lib/chewy/log_subscriber.rb | 6 +++++- 5 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 gemfiles/rails.7.1.activerecord.gemfile diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 636110841..9c518a8fa 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -43,7 +43,7 @@ jobs: fail-fast: false matrix: ruby: [ '3.0', '3.1', '3.2' ] - gemfile: [ rails.6.1.activerecord, rails.7.0.activerecord ] + gemfile: [ rails.6.1.activerecord, rails.7.0.activerecord, rails.7.1.activerecord ] name: ${{ matrix.ruby }}-${{ matrix.gemfile }} env: diff --git a/CHANGELOG.md b/CHANGELOG.md index fc63274c0..5dc336724 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ ### New Features +* [#907](https://github.com/toptal/chewy/pull/907): Fix deprecation warning in LogSubscriber for Rails 7.1 ([@alejandroperea](https://github.com/alejandroperea)) + ### Changes ### Bugs Fixed diff --git a/gemfiles/rails.7.1.activerecord.gemfile b/gemfiles/rails.7.1.activerecord.gemfile new file mode 100644 index 000000000..af8ec812e --- /dev/null +++ b/gemfiles/rails.7.1.activerecord.gemfile @@ -0,0 +1,13 @@ +source 'https://rubygems.org' + +gem 'activejob', '~> 7.1.0' +gem 'activerecord', '~> 7.1.0' +gem 'activesupport', '~> 7.1.0' +gem 'kaminari-core', '~> 1.1.0', require: false +gem 'parallel', require: false +gem 'rspec_junit_formatter', '~> 0.4.1' +gem 'sidekiq', require: false + +gem 'rexml' if RUBY_VERSION >= '3.0.0' + +gemspec path: '../' diff --git a/lib/chewy.rb b/lib/chewy.rb index a6239be31..e95f25c75 100644 --- a/lib/chewy.rb +++ b/lib/chewy.rb @@ -1,3 +1,4 @@ +require 'active_support' require 'active_support/version' require 'active_support/concern' require 'active_support/deprecation' diff --git a/lib/chewy/log_subscriber.rb b/lib/chewy/log_subscriber.rb index c35d63fbf..368c0813b 100644 --- a/lib/chewy/log_subscriber.rb +++ b/lib/chewy/log_subscriber.rb @@ -24,7 +24,11 @@ def render_action(action, event) subject = payload[:type].presence || payload[:index] action = "#{subject} #{action} (#{event.duration.round(1)}ms)" - action = color(action, GREEN, true) + action = if ActiveSupport.version >= Gem::Version.new('7.1') + color(action, GREEN, bold: true) + else + color(action, GREEN, true) + end debug(" #{action} #{description}") end