Skip to content

Commit

Permalink
Merge pull request #423 from tomgi/activerecord_deprecation_warning
Browse files Browse the repository at this point in the history
Fix activerecord 7.1 and 7.2 deprecations
  • Loading branch information
oeoeaio authored Oct 28, 2024
2 parents 51403c0 + c4dead8 commit f87b462
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 12 deletions.
20 changes: 12 additions & 8 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@ jobs:
strategy:
matrix:
ruby_version: ['2.7', '3.0', '3.1', '3.2']
rails_gemfile: ['6.0', '6.1', '7.0', '7.1']
rails_gemfile: ['6.0', '6.1', '7.0', '7.1', '7.2']
postgres_version: ['14']
include:
# Postgres versions
- { ruby_version: '3.2', rails_gemfile: '7.1', postgres_version: '9' }
- { ruby_version: '3.2', rails_gemfile: '7.1', postgres_version: '10' }
- { ruby_version: '3.2', rails_gemfile: '7.1', postgres_version: '11' }
- { ruby_version: '3.2', rails_gemfile: '7.1', postgres_version: '12' }
- { ruby_version: '3.2', rails_gemfile: '7.1', postgres_version: '13' }
- { ruby_version: '3.2', rails_gemfile: '7.1', postgres_version: '14' }
exclude: []
- { ruby_version: '3.2', rails_gemfile: '7.2', postgres_version: '9' }
- { ruby_version: '3.2', rails_gemfile: '7.2', postgres_version: '10' }
- { ruby_version: '3.2', rails_gemfile: '7.2', postgres_version: '11' }
- { ruby_version: '3.2', rails_gemfile: '7.2', postgres_version: '12' }
- { ruby_version: '3.2', rails_gemfile: '7.2', postgres_version: '13' }
- { ruby_version: '3.2', rails_gemfile: '7.2', postgres_version: '14' }
exclude: # Rails 7.2 is not compatible with Ruby < 3.1
- ruby_version: '2.7'
rails_gemfile: '7.2'
- ruby_version: '3.0'
rails_gemfile: '7.2'
name: "Test: Ruby ${{ matrix.ruby_version }}, Rails ${{ matrix.rails_gemfile }}, PostgreSQL ${{ matrix.postgres_version }}"
services:
db:
Expand Down
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ source 'https://rubygems.org'
group :development, :test do
gem 'rake'

gem 'activerecord', '~> 7.1.0', require: nil
gem 'activejob', '~> 7.1.0', require: nil
gem 'activerecord', '~> 7.2.0', require: nil
gem 'activejob', '~> 7.2.0', require: nil
gem 'sequel', require: nil
gem 'connection_pool', require: nil
gem 'pond', require: nil
Expand Down
7 changes: 6 additions & 1 deletion lib/que/active_record/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ def call(job)
# feature to unknowingly leak connections to other databases. So,
# take the additional step of telling ActiveRecord to check in all
# of the current thread's connections after each job is run.
::ActiveRecord::Base.clear_active_connections! unless job.class.resolve_que_setting(:run_synchronously)
return if job.class.resolve_que_setting(:run_synchronously)
if ::ActiveRecord.version >= Gem::Version.new('7.1')
::ActiveRecord::Base.connection_handler.clear_active_connections!(:all)
else
::ActiveRecord::Base.clear_active_connections!
end
end
end
end
Expand Down
23 changes: 23 additions & 0 deletions spec/gemfiles/Gemfile-rails-7.2
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
source 'https://rubygems.org'

gem 'que', path: '../..'

group :development, :test do
gem 'rake'

gem 'activerecord', '~> 7.2.0', require: nil
gem 'activejob', '~> 7.2.0', require: nil
gem 'sequel', require: nil
gem 'connection_pool', require: nil
gem 'pond', require: nil
gem 'pg', require: nil, platform: :ruby
gem 'pg_jruby', require: nil, platform: :jruby
end

group :test do
gem 'minitest', '~> 5.10.1'
gem 'minitest-profile', '0.0.2'
gem 'minitest-hooks', '1.4.0'
gem 'pry'
gem 'pg_examiner', '~> 0.5.2'
end
6 changes: 5 additions & 1 deletion spec/que/active_record/connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ class SecondDatabaseModel < ActiveRecord::Base
establish_connection(QUE_URL)
end

SecondDatabaseModel.clear_active_connections!
if ::ActiveRecord.version >= Gem::Version.new('7.1')
SecondDatabaseModel.connection_handler.clear_active_connections!(:all)
else
SecondDatabaseModel.clear_active_connections!
end
refute SecondDatabaseModel.connection_handler.active_connections?

class SecondDatabaseModelJob < Que::Job
Expand Down

0 comments on commit f87b462

Please sign in to comment.