Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove specs for old rails versions #2

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 5 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,14 @@ workflows:
- build:
matrix:
parameters:
ruby_version: ["ruby:3.0.6", "ruby:3.1.4", "ruby:3.2.2"]
ruby_version: ["ruby:3.1.4", "ruby:3.2.2", "ruby:3.3.6"]
gemfile:
[
"gemfiles/rails_6_1.gemfile",
"gemfiles/rails_7_0.gemfile",
"gemfiles/rails_7_1.gemfile",
"gemfiles/rails_7_2.gemfile",
"gemfiles/rails_8_0.gemfile",
]
exclude:
- ruby_version: "ruby:3.1.4"
gemfile: "gemfiles/rails_8_0.gemfile"
10 changes: 3 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,14 @@ jobs:
- 3.1
- 3.2
- 3.3
- jruby
rails_version:
- 6_1
- 7_0
- 7_1
- 7_2
# - master # versions failing
- 8_0
exclude:
- ruby_version: jruby
rails_version: 7_1
- ruby_version: jruby
rails_version: 7_2
- rails_version: 8_0
ruby_version: 3.1
env:
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails_${{ matrix.rails_version }}.gemfile
CI: true
Expand Down
24 changes: 12 additions & 12 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
# frozen_string_literal: true

appraise 'rails-6-1' do
gem 'rails', '~> 6.1.0'
platforms :ruby do
gem 'sqlite3', '~> 1.4'
end
platforms :jruby do
gem 'activerecord-jdbc-adapter', '~> 61.0'
gem 'activerecord-jdbcpostgresql-adapter', '~> 61.0'
gem 'activerecord-jdbcmysql-adapter', '~> 61.0'
end
end

appraise 'rails-7-0' do
gem 'rails', '~> 7.0.0'
platforms :ruby do
Expand Down Expand Up @@ -48,6 +36,18 @@ appraise 'rails-7-2' do
end
end

appraise 'rails-8-0' do
gem 'rails', '~> 8.0.0'
platforms :ruby do
gem 'sqlite3', '~> 2.0'
end
platforms :jruby do
gem 'activerecord-jdbc-adapter', '~> 70.0'
gem 'activerecord-jdbcpostgresql-adapter', '~> 70.0'
gem 'activerecord-jdbcmysql-adapter', '~> 70.0'
end
end

# Install Rails from the main branch are failing
# appraise 'rails-master' do
# gem 'rails', git: 'https://github.com/rails/rails.git'
Expand Down
17 changes: 0 additions & 17 deletions gemfiles/rails_6_1.gemfile

This file was deleted.

17 changes: 17 additions & 0 deletions gemfiles/rails_8_0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This file was generated by Appraisal

source "http://rubygems.org"

gem "rails", "~> 8.0.0"

platforms :ruby do
gem "sqlite3", "~> 2.0"
end

platforms :jruby do
gem 'activerecord-jdbc-adapter', '~> 70.0'
gem "activerecord-jdbcpostgresql-adapter", "~> 70.0"
gem "activerecord-jdbcmysql-adapter", "~> 70.0"
end

gemspec path: "../"
22 changes: 6 additions & 16 deletions lib/apartment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,9 @@
require 'apartment/tenant'

require_relative 'apartment/log_subscriber'

if ActiveRecord.version.release >= Gem::Version.new('6.0')
require_relative 'apartment/active_record/connection_handling'
end

if ActiveRecord.version.release >= Gem::Version.new('6.1')
require_relative 'apartment/active_record/schema_migration'
require_relative 'apartment/active_record/internal_metadata'
end
require_relative 'apartment/active_record/connection_handling'
require_relative 'apartment/active_record/schema_migration'
require_relative 'apartment/active_record/internal_metadata'

if ActiveRecord.version.release >= Gem::Version.new('7.1')
require_relative 'apartment/active_record/postgres/schema_dumper'
Expand All @@ -37,14 +31,10 @@
attr_accessor(*ACCESSOR_METHODS)
attr_writer(*WRITER_METHODS)

if ActiveRecord.version.release >= Gem::Version.new('6.1')
def_delegators :connection_class, :connection, :connection_db_config, :establish_connection
def_delegators :connection_class, :connection, :connection_db_config, :establish_connection

def connection_config
connection_db_config.configuration_hash
end
else
def_delegators :connection_class, :connection, :connection_config, :establish_connection
def connection_config
connection_db_config.configuration_hash
end

# configure apartment with available options
Expand All @@ -65,7 +55,7 @@
end

def db_config_for(tenant)
(tenants_with_config[tenant] || connection_config)

Check failure on line 58 in lib/apartment.rb

View workflow job for this annotation

GitHub Actions / rubocop

[rubocop] lib/apartment.rb#L58

[Correctable] Style/RedundantParentheses: Don't use parentheses around a logical expression.
Raw output
lib/apartment.rb:58:7: C: [Correctable] Style/RedundantParentheses: Don't use parentheses around a logical expression.
      (tenants_with_config[tenant] || connection_config)
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
end

# Whether or not db:migrate should also migrate tenants
Expand Down
8 changes: 4 additions & 4 deletions puzzle-apartment.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Gem::Specification.new do |s|

s.required_ruby_version = '>= 3.1', '<= 3.4'

s.add_dependency 'activerecord', '>= 6.1.0', '<= 8.1'
s.add_dependency 'activerecord', '>= 7.0.0', '<= 8.1'
s.add_dependency 'parallel', '< 2.0'
s.add_dependency 'public_suffix', '>= 2.0.5', '<= 6.0.1'
s.add_dependency 'rack', '>= 1.3.6', '< 4.0'
Expand All @@ -57,8 +57,8 @@ Gem::Specification.new do |s|
s.add_development_dependency 'jdbc-mysql'
s.add_development_dependency 'jdbc-postgres'
else
s.add_development_dependency 'mysql2', '~> 0.5'
s.add_development_dependency 'pg', '~> 1.2'
s.add_development_dependency 'sqlite3', '~> 1.3.6'
s.add_development_dependency 'mysql2'
s.add_development_dependency 'pg'
s.add_development_dependency 'sqlite3'
end
end
3 changes: 2 additions & 1 deletion spec/adapters/sqlite3_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
it_behaves_like 'a connection based apartment adapter'

after(:all) do
File.delete(Apartment::Test.config['connections']['sqlite']['database'])
db_file = Apartment::Test.config['connections']['sqlite']['database']
File.delete(db_file) if File.exist?(db_file)

Check warning on line 28 in spec/adapters/sqlite3_adapter_spec.rb

View workflow job for this annotation

GitHub Actions / rubocop

[rubocop] spec/adapters/sqlite3_adapter_spec.rb#L28

Lint/NonAtomicFileOperation: Use atomic file operation method FileUtils.rm_f.
Raw output
spec/adapters/sqlite3_adapter_spec.rb:28:9: W: Lint/NonAtomicFileOperation: Use atomic file operation method FileUtils.rm_f.
        File.delete(db_file) if File.exist?(db_file)
        ^^^^^^^^^^^^^^^^^^^^

Check warning on line 28 in spec/adapters/sqlite3_adapter_spec.rb

View workflow job for this annotation

GitHub Actions / rubocop

[rubocop] spec/adapters/sqlite3_adapter_spec.rb#L28

[Correctable] Lint/NonAtomicFileOperation: Remove unnecessary existence check File.exist?.
Raw output
spec/adapters/sqlite3_adapter_spec.rb:28:30: W: [Correctable] Lint/NonAtomicFileOperation: Remove unnecessary existence check File.exist?.
        File.delete(db_file) if File.exist?(db_file)
                             ^^^^^^^^^^^^^^^^^^^^^^^
end
end

Expand Down
71 changes: 21 additions & 50 deletions spec/integration/apartment_rake_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,60 +47,31 @@
Company.delete_all
end

context 'with ActiveRecord below 5.2.0' do
before do
allow(ActiveRecord::Migrator).to receive(:migrations_paths) { %w[spec/dummy/db/migrate] }
allow(Apartment::Migrator).to receive(:activerecord_below_5_2?) { true }
end

describe '#migrate' do
it 'should migrate all databases' do
expect(ActiveRecord::Migrator).to receive(:migrate).exactly(company_count).times

@rake['apartment:migrate'].invoke
end
end

describe '#rollback' do
it 'should rollback all dbs' do
expect(ActiveRecord::Migrator).to receive(:rollback).exactly(company_count).times

@rake['apartment:rollback'].invoke
end
let(:migration_context_double) { double(:migration_context) }

Check failure on line 50 in spec/integration/apartment_rake_integration_spec.rb

View workflow job for this annotation

GitHub Actions / rubocop

[rubocop] spec/integration/apartment_rake_integration_spec.rb#L50

[Correctable] RSpec/ScatteredLet: Group all let/let! blocks in the example group together.
Raw output
spec/integration/apartment_rake_integration_spec.rb:50:5: C: [Correctable] RSpec/ScatteredLet: Group all let/let! blocks in the example group together.
    let(:migration_context_double) { double(:migration_context) }
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

describe '#migrate' do
it 'should migrate all databases' do
if ActiveRecord.version >= Gem::Version.new('7.2.0')
allow(ActiveRecord::Base.connection_pool)
else
allow(ActiveRecord::Base.connection)
end.to receive(:migration_context) { migration_context_double }
expect(migration_context_double).to receive(:migrate).exactly(company_count).times

@rake['apartment:migrate'].invoke
end
end

context 'with ActiveRecord above or equal to 5.2.0' do
let(:migration_context_double) { double(:migration_context) }

before do
allow(Apartment::Migrator).to receive(:activerecord_below_5_2?) { false }
end

describe '#migrate' do
it 'should migrate all databases' do
if ActiveRecord.version >= Gem::Version.new('7.2.0')
allow(ActiveRecord::Base.connection_pool)
else
allow(ActiveRecord::Base.connection)
end.to receive(:migration_context) { migration_context_double }
expect(migration_context_double).to receive(:migrate).exactly(company_count).times

@rake['apartment:migrate'].invoke
end
end
describe '#rollback' do
it 'should rollback all dbs' do
if ActiveRecord.version >= Gem::Version.new('7.2.0')
allow(ActiveRecord::Base.connection_pool)
else
allow(ActiveRecord::Base.connection)
end.to receive(:migration_context) { migration_context_double }
expect(migration_context_double).to receive(:rollback).exactly(company_count).times

describe '#rollback' do
it 'should rollback all dbs' do
if ActiveRecord.version >= Gem::Version.new('7.2.0')
allow(ActiveRecord::Base.connection_pool)
else
allow(ActiveRecord::Base.connection)
end.to receive(:migration_context) { migration_context_double }
expect(migration_context_double).to receive(:rollback).exactly(company_count).times

@rake['apartment:rollback'].invoke
end
@rake['apartment:rollback'].invoke
end
end

Expand Down
74 changes: 19 additions & 55 deletions spec/unit/migrator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,72 +7,36 @@
let(:tenant) { Apartment::Test.next_db }

# Don't need a real switch here, just testing behaviour
before { allow(Apartment::Tenant.adapter).to receive(:connect_to_new) }

Check failure on line 10 in spec/unit/migrator_spec.rb

View workflow job for this annotation

GitHub Actions / rubocop

[rubocop] spec/unit/migrator_spec.rb#L10

RSpec/ScatteredSetup: Do not define multiple before hooks in the same example group (also defined on line 12).
Raw output
spec/unit/migrator_spec.rb:10:3: C: RSpec/ScatteredSetup: Do not define multiple before hooks in the same example group (also defined on line 12).
  before { allow(Apartment::Tenant.adapter).to receive(:connect_to_new) }
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

context 'with ActiveRecord below 5.2.0', skip: ActiveRecord.version >= Gem::Version.new('5.2.0') do
before do
allow(ActiveRecord::Migrator).to receive(:migrations_paths) { %w[spec/dummy/db/migrate] }
allow(Apartment::Migrator).to receive(:activerecord_below_5_2?) { true }
end

describe '::migrate' do
it 'switches and migrates' do
expect(Apartment::Tenant).to receive(:switch).with(tenant).and_call_original
expect(ActiveRecord::Migrator).to receive(:migrate)

Apartment::Migrator.migrate(tenant)
end
end

describe '::run' do
it 'switches and runs' do
expect(Apartment::Tenant).to receive(:switch).with(tenant).and_call_original
expect(ActiveRecord::Migrator).to receive(:run).with(:up, anything, 1234)

Apartment::Migrator.run(:up, tenant, 1234)
end
end

describe '::rollback' do
it 'switches and rolls back' do
expect(Apartment::Tenant).to receive(:switch).with(tenant).and_call_original
expect(ActiveRecord::Migrator).to receive(:rollback).with(anything, 2)

Apartment::Migrator.rollback(tenant, 2)
end
end
before do

Check failure on line 12 in spec/unit/migrator_spec.rb

View workflow job for this annotation

GitHub Actions / rubocop

[rubocop] spec/unit/migrator_spec.rb#L12

[Correctable] RSpec/ScatteredSetup: Do not define multiple before hooks in the same example group (also defined on line 10).
Raw output
spec/unit/migrator_spec.rb:12:3: C: [Correctable] RSpec/ScatteredSetup: Do not define multiple before hooks in the same example group (also defined on line 10).
  before do ...
  ^^^^^^^^^
allow(Apartment::Migrator).to receive(:activerecord_below_5_2?) { false }
end

context 'with ActiveRecord above or equal to 5.2.0', skip: ActiveRecord.version < Gem::Version.new('5.2.0') do
before do
allow(Apartment::Migrator).to receive(:activerecord_below_5_2?) { false }
end
describe '::migrate' do
it 'switches and migrates' do
expect(Apartment::Tenant).to receive(:switch).with(tenant).and_call_original
expect_any_instance_of(ActiveRecord::MigrationContext).to receive(:migrate)

describe '::migrate' do
it 'switches and migrates' do
expect(Apartment::Tenant).to receive(:switch).with(tenant).and_call_original
expect_any_instance_of(ActiveRecord::MigrationContext).to receive(:migrate)

Apartment::Migrator.migrate(tenant)
end
Apartment::Migrator.migrate(tenant)
end
end

describe '::run' do
it 'switches and runs' do
expect(Apartment::Tenant).to receive(:switch).with(tenant).and_call_original
expect_any_instance_of(ActiveRecord::MigrationContext).to receive(:run).with(:up, 1234)
describe '::run' do
it 'switches and runs' do
expect(Apartment::Tenant).to receive(:switch).with(tenant).and_call_original
expect_any_instance_of(ActiveRecord::MigrationContext).to receive(:run).with(:up, 1234)

Apartment::Migrator.run(:up, tenant, 1234)
end
Apartment::Migrator.run(:up, tenant, 1234)
end
end

describe '::rollback' do
it 'switches and rolls back' do
expect(Apartment::Tenant).to receive(:switch).with(tenant).and_call_original
expect_any_instance_of(ActiveRecord::MigrationContext).to receive(:rollback).with(2)
describe '::rollback' do
it 'switches and rolls back' do
expect(Apartment::Tenant).to receive(:switch).with(tenant).and_call_original
expect_any_instance_of(ActiveRecord::MigrationContext).to receive(:rollback).with(2)

Apartment::Migrator.rollback(tenant, 2)
end
Apartment::Migrator.rollback(tenant, 2)
end
end
end
Loading