diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d65a852..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 @@ -27,6 +27,71 @@ jobs: bundler-cache: true - name: Run tests run: bundle exec rspec spec + test-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' + 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: Ruby 3.4 / Rails 8.0.0 / AA 3.5.1 / PostgreSQL 16 + 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