diff --git a/.circleci/config.yml b/.circleci/config.yml index 151b98ff..1f9fa88d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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", ] diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index feabdc00..9cc84aa2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 diff --git a/Appraisals b/Appraisals index b3fc60c9..bf93a2d4 100644 --- a/Appraisals +++ b/Appraisals @@ -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' diff --git a/gemfiles/rails_8_0.gemfile b/gemfiles/rails_8_0.gemfile new file mode 100644 index 00000000..6704eb53 --- /dev/null +++ b/gemfiles/rails_8_0.gemfile @@ -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: "../" diff --git a/puzzle-apartment.gemspec b/puzzle-apartment.gemspec index 5c53bdda..4dd94b6b 100644 --- a/puzzle-apartment.gemspec +++ b/puzzle-apartment.gemspec @@ -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 diff --git a/spec/adapters/sqlite3_adapter_spec.rb b/spec/adapters/sqlite3_adapter_spec.rb index 339cb38c..ee666c2a 100644 --- a/spec/adapters/sqlite3_adapter_spec.rb +++ b/spec/adapters/sqlite3_adapter_spec.rb @@ -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) end end diff --git a/spec/integration/apartment_rake_integration_spec.rb b/spec/integration/apartment_rake_integration_spec.rb index e9acfb10..d2aec82c 100644 --- a/spec/integration/apartment_rake_integration_spec.rb +++ b/spec/integration/apartment_rake_integration_spec.rb @@ -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) } + + 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 diff --git a/spec/unit/migrator_spec.rb b/spec/unit/migrator_spec.rb index 8cbcb9e2..ceb10444 100644 --- a/spec/unit/migrator_spec.rb +++ b/spec/unit/migrator_spec.rb @@ -9,70 +9,34 @@ # Don't need a real switch here, just testing behaviour 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 + 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