Skip to content
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
67 changes: 66 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 8 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 2 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
38 changes: 37 additions & 1 deletion spec/support/rails_template.rb
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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'
12 changes: 10 additions & 2 deletions tasks/test.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading