From 3841a1a549a527a9f66693bd246d5e793980ee0d Mon Sep 17 00:00:00 2001 From: Igor Fedoronchuk Date: Wed, 8 Apr 2026 11:48:00 +0200 Subject: [PATCH 1/2] Add MySQL and PostgreSQL to CI database matrix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The existing CI matrix runs exclusively against SQLite, which hides any adapter-specific behavior (upsert semantics, conflict targets, column types, etc.). This adds two new CI jobs — one for MySQL 8.0 and one for PostgreSQL 16 — that run the full spec suite against a live database service, using the latest supported Ruby/Rails/ActiveAdmin combination. The adapter is selected by the `DB` env var (sqlite | mysql | postgres). The test Rails app is cached per-adapter (`spec/rails/rails--`) and the Gemfile loads the matching driver conditionally. Host, port, and credentials are all driven from env vars so the same setup works locally and in CI. --- .github/workflows/test.yml | 65 ++++++++++++++++++++++++++++++++++ Gemfile | 9 ++++- spec/spec_helper.rb | 3 +- spec/support/rails_template.rb | 38 +++++++++++++++++++- tasks/test.rake | 12 +++++-- 5 files changed, 122 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d65a852..c97118e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,6 +27,71 @@ jobs: bundler-cache: true - name: Run tests run: bundle exec rspec spec + test-mysql: + name: DB mysql + runs-on: ubuntu-latest + env: + RAILS: '8.0.0' + AA: '3.5.1' + DB: mysql + DB_HOST: 127.0.0.1 + DB_PORT: 3306 + DB_USERNAME: root + DB_PASSWORD: root + services: + mysql: + image: mysql:8.0 + env: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: active_admin_import_test + ports: + - 3306:3306 + options: >- + --health-cmd="mysqladmin ping -h localhost -uroot -proot" + --health-interval=10s + --health-timeout=5s + --health-retries=10 + steps: + - uses: actions/checkout@v4 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.4' + bundler-cache: true + - name: Run tests + run: bundle exec rspec spec + test-postgres: + name: DB postgres + runs-on: ubuntu-latest + env: + RAILS: '8.0.0' + AA: '3.5.1' + DB: postgres + DB_HOST: 127.0.0.1 + DB_PORT: 5432 + DB_USERNAME: postgres + DB_PASSWORD: postgres + services: + postgres: + image: postgres:16 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: active_admin_import_test + ports: + - 5432:5432 + options: >- + --health-cmd="pg_isready -U postgres" + --health-interval=10s + --health-timeout=5s + --health-retries=10 + steps: + - uses: actions/checkout@v4 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.4' + bundler-cache: true + - name: Run tests + run: bundle exec rspec spec coverage: name: Coverage runs-on: ubuntu-latest diff --git a/Gemfile b/Gemfile index 165e561..7f9ee37 100644 --- a/Gemfile +++ b/Gemfile @@ -12,7 +12,14 @@ gem 'sass-rails' group :test do gem 'simplecov', require: false gem 'rspec-rails' - gem 'sqlite3', '~> 2.0' + case ENV['DB'] + when 'mysql' + gem 'mysql2' + when 'postgres', 'postgresql' + gem 'pg' + else + gem 'sqlite3', '~> 2.0' + end gem 'database_cleaner' gem 'capybara' gem 'cuprite' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index be07cb9..d734a22 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -13,7 +13,8 @@ ENV['RAILS_ENV'] = 'test' require 'rails' ENV['RAILS'] = Rails.version -ENV['RAILS_ROOT'] = File.expand_path("../rails/rails-#{ENV['RAILS']}", __FILE__) +ENV['DB'] ||= 'sqlite' +ENV['RAILS_ROOT'] = File.expand_path("../rails/rails-#{ENV['RAILS']}-#{ENV['DB']}", __FILE__) system 'rake setup' unless File.exist?(ENV['RAILS_ROOT']) require 'active_model' diff --git a/spec/support/rails_template.rb b/spec/support/rails_template.rb index f821edf..84c898c 100644 --- a/spec/support/rails_template.rb +++ b/spec/support/rails_template.rb @@ -1,5 +1,41 @@ create_file "app/assets/config/manifest.js", skip: true +db = ENV['DB'] || 'sqlite' +case db +when 'mysql' + remove_file 'config/database.yml' + create_file 'config/database.yml', <<~YAML + default: &default + adapter: mysql2 + encoding: utf8mb4 + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + host: <%= ENV.fetch("DB_HOST", "127.0.0.1") %> + port: <%= ENV.fetch("DB_PORT", 3306) %> + username: <%= ENV.fetch("DB_USERNAME", "root") %> + password: <%= ENV.fetch("DB_PASSWORD", "root") %> + + test: + <<: *default + database: active_admin_import_test + YAML +when 'postgres', 'postgresql' + remove_file 'config/database.yml' + create_file 'config/database.yml', <<~YAML + default: &default + adapter: postgresql + encoding: unicode + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + host: <%= ENV.fetch("DB_HOST", "127.0.0.1") %> + port: <%= ENV.fetch("DB_PORT", 5432) %> + username: <%= ENV.fetch("DB_USERNAME", "postgres") %> + password: <%= ENV.fetch("DB_PASSWORD", "postgres") %> + + test: + <<: *default + database: active_admin_import_test + YAML +end + generate :model, 'author name:string{10}:uniq last_name:string birthday:date --force' generate :model, 'post title:string:uniq body:text request_ip:string author:references --force' generate :model, 'post_comment body:text post:references --force' @@ -19,6 +55,6 @@ run 'rm -rf test' route "root :to => 'admin/dashboard#index'" -rake 'db:migrate' +rake 'db:create db:migrate' run 'rm -f Gemfile Gemfile.lock' diff --git a/tasks/test.rake b/tasks/test.rake index f46bf45..e90ba40 100644 --- a/tasks/test.rake +++ b/tasks/test.rake @@ -2,12 +2,20 @@ desc "Creates a test rails app for the specs to run against" task :setup do require 'rails/version' - rails_new_opts = %w( + db = ENV['DB'] || 'sqlite' + rails_db = case db + when 'mysql' then 'mysql' + when 'postgres', 'postgresql' then 'postgresql' + else 'sqlite3' + end + + rails_new_opts = %W( --skip-turbolinks --skip-spring --skip-bootsnap + -d #{rails_db} -m spec/support/rails_template.rb ) - system "bundle exec rails new spec/rails/rails-#{Rails::VERSION::STRING} #{rails_new_opts.join(' ')}" + system "bundle exec rails new spec/rails/rails-#{Rails::VERSION::STRING}-#{db} #{rails_new_opts.join(' ')}" end From 8fa7672dc6158530ccefae4c8639a1d32710b7ca Mon Sep 17 00:00:00 2001 From: Igor Fedoronchuk Date: Wed, 8 Apr 2026 11:54:16 +0200 Subject: [PATCH 2/2] Make CI job names self-explanatory about adapter and versions The MySQL and PostgreSQL jobs were named just "DB mysql" / "DB postgres", which hides the Ruby/Rails/ActiveAdmin combination they run against. The SQLite matrix jobs also didn't mention "SQLite" anywhere. Rename all three job groups so the PR checks list shows exactly what's being tested at a glance. --- .github/workflows/test.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c97118e..3302c99 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,7 +5,7 @@ on: branches: [master] jobs: test: - name: Ruby ${{ matrix.ruby }} / Rails ${{ matrix.rails }} / AA ${{ matrix.activeadmin }} + name: Ruby ${{ matrix.ruby }} / Rails ${{ matrix.rails }} / AA ${{ matrix.activeadmin }} / SQLite runs-on: ubuntu-latest strategy: fail-fast: false @@ -28,7 +28,7 @@ jobs: - name: Run tests run: bundle exec rspec spec test-mysql: - name: DB mysql + name: Ruby 3.4 / Rails 8.0.0 / AA 3.5.1 / MySQL 8.0 runs-on: ubuntu-latest env: RAILS: '8.0.0' @@ -60,7 +60,7 @@ jobs: - name: Run tests run: bundle exec rspec spec test-postgres: - name: DB postgres + name: Ruby 3.4 / Rails 8.0.0 / AA 3.5.1 / PostgreSQL 16 runs-on: ubuntu-latest env: RAILS: '8.0.0'