Skip to content
Closed
Show file tree
Hide file tree
Changes from 9 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
23 changes: 10 additions & 13 deletions .github/workflows/prs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,22 @@ jobs:
fail-fast: false
matrix:
ruby:
- '2.5'
- '2.7'
- '3.0'
- '3.1'
- '3.2'
- '3.3'
- '3.4'
activerecord:
- '5.1'
- '5.2'
- '6.0'
- '6.1'
- '7.0'
- '7.1'
- '7.2'
- '8.0'
exclude:
- ruby: '2.5'
activerecord: '7.0'
- ruby: '2.5'
activerecord: '7.1'
- ruby: '3.0'
activerecord: '5.1'
activerecord: '7.2'
- ruby: '3.0'
activerecord: '5.2'
activerecord: '8.0'
- ruby: '3.1'
activerecord: '8.0'
env:
BUNDLE_GEMFILE: "${{ github.workspace }}/gemfiles/activerecord-${{ matrix.activerecord }}.gemfile"
steps:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/pkg
*~
\.DS_Store
*.sqlite
*.sqlite*
Gemfile.lock
Gemfile.local
gemfiles/*.lock
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require:
- rubocop-rspec

AllCops:
TargetRubyVersion: 2.5
TargetRubyVersion: 3.0
SuggestExtensions: false
NewCops: disable
Exclude:
Expand Down
8 changes: 4 additions & 4 deletions ar-multidb.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
s.require_paths = ['lib']

s.required_ruby_version = '>= 2.5.0'
s.required_ruby_version = '>= 3.0.0'

s.add_runtime_dependency 'activerecord', '>= 5.1', '< 7.2'
s.add_runtime_dependency 'activesupport', '>= 5.1', '< 7.2'
s.add_runtime_dependency 'activerecord', '>= 7.1', '< 8.1'
s.add_runtime_dependency 'activesupport', '>= 7.1', '< 8.1'

s.add_development_dependency 'rake', '~> 13.0'
s.add_development_dependency 'rspec', '~> 3.8'
s.add_development_dependency 'rubocop', '~> 1.28.0'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Lets update to the latest version of rubocop, rubocop-rspec, rspec, and simplecov.

(Or whatever versions will still run with ruby 3.0+)

s.add_development_dependency 'rubocop-rspec', '~> 2.10.0'
s.add_development_dependency 'simplecov', '~> 0.21.2'
s.add_development_dependency 'simplecov-lcov', '~> 0.8.0'
s.add_development_dependency 'sqlite3', '~> 1.3'
s.add_development_dependency 'sqlite3', '~> 2'
end
7 changes: 0 additions & 7 deletions gemfiles/activerecord-6.0.gemfile

This file was deleted.

7 changes: 0 additions & 7 deletions gemfiles/activerecord-6.1.gemfile

This file was deleted.

7 changes: 0 additions & 7 deletions gemfiles/activerecord-7.0.gemfile

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

source 'https://rubygems.org'

gem 'activerecord', '~> 5.1.0'
gem 'activerecord', '~> 7.2.0'

gemspec path: '..'
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

source 'https://rubygems.org'

gem 'activerecord', '~> 5.2.0'
gem 'activerecord', '~> 8.0.0'

gemspec path: '..'
9 changes: 2 additions & 7 deletions lib/multidb/candidate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@

module Multidb
class Candidate
USE_RAILS_61 = Gem::Version.new(::ActiveRecord::VERSION::STRING) >= Gem::Version.new('6.1')
SPEC_NAME = if USE_RAILS_61
'ActiveRecord::Base'
else
'primary'
end
SPEC_NAME = 'ActiveRecord::Base'

def initialize(name, target)
@name = name

case target
when Hash
target = target.merge(name: 'primary') unless USE_RAILS_61
target = target.merge(name: 'primary')

@connection_handler = ActiveRecord::ConnectionAdapters::ConnectionHandler.new
@connection_handler.establish_connection(target)
Expand Down
10 changes: 0 additions & 10 deletions spec/lib/multidb/candidate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@
handler = subject.instance_variable_get(:@connection_handler)
expect(handler).to an_instance_of(ActiveRecord::ConnectionAdapters::ConnectionHandler)
end

it 'merges the name: primary into the hash', rails: '< 6.1' do
handler = instance_double('ActiveRecord::ConnectionAdapters::ConnectionHandler')
allow(ActiveRecord::ConnectionAdapters::ConnectionHandler).to receive(:new).and_return(handler)
allow(handler).to receive(:establish_connection)

subject

expect(handler).to have_received(:establish_connection).with(hash_including(name: 'primary'))
end
end

context 'when target is a connection handler' do
Expand Down
4 changes: 2 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
$LOAD_PATH.unshift(File.expand_path('lib', __dir__))
require 'multidb'

Dir[File.join(__dir__, 'support', '**', '*.rb')].sort.each { |f| require f }
Dir[File.join(__dir__, 'support', '**', '*.rb')].each { |f| require f }

RSpec.configure do |config|
config.disable_monkey_patching!
Expand All @@ -39,7 +39,7 @@
end

config.before do
ActiveRecord::Base.clear_all_connections!
ActiveRecord::Base.connection_handler.clear_all_connections!
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Was this seriously the only change needed to get it working on 7.1+?

Have you tested it IN a rails application to ensure if fully works in 7.1+? (not wanting to just trust the tests here).

Copy link
Copy Markdown
Contributor Author

@joe-sharp joe-sharp May 15, 2025

Choose a reason for hiding this comment

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

I plan to test today in a Rails application. It definitely seemed weird but I noticed the code (line 14 in candidate.rb) was already using the connection handler so it seemed plausible it will work. The older AR versions would be supported with maybe some careful changes to their gemfiles. I'll keep you posted.

Multidb.reset!
end

Expand Down