Skip to content

Commit

Permalink
Remove specs for old rails versions
Browse files Browse the repository at this point in the history
  • Loading branch information
codez committed Dec 3, 2024
1 parent d3b8c6b commit 21dba83
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 116 deletions.
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ 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",
]
9 changes: 3 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,15 @@ 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
12 changes: 12 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,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: 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: "../"
6 changes: 3 additions & 3 deletions puzzle-apartment.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ def tenant_names
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 @@ -9,70 +9,34 @@
# 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

0 comments on commit 21dba83

Please sign in to comment.