Skip to content

Commit 795a85f

Browse files
committed
fix test
1 parent 5ba986e commit 795a85f

3 files changed

Lines changed: 72 additions & 37 deletions

File tree

.github/workflows/ci.yml

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
---
21
name: CI
32

43
on:
@@ -9,55 +8,53 @@ on:
98
branches:
109
- master
1110

12-
1311
jobs:
1412
test:
1513
runs-on: ubuntu-latest
14+
1615
services:
17-
mysql:
18-
image: mysql/mysql-server
19-
ports:
20-
- "3306:3306"
21-
env:
22-
MYSQL_ROOT_PASSWORD: root
23-
MYSQL_DATABASE: closure_tree_test
24-
MYSQL_ROOT_HOST: '%'
2516
postgres:
26-
image: 'postgres'
27-
ports: ['5432:5432']
17+
image: postgres:17-alpine
18+
ports:
19+
- 5432:5432
2820
env:
21+
POSTGRES_USER: postgres
2922
POSTGRES_PASSWORD: postgres
3023
POSTGRES_DB: closure_tree_test
3124
options: >-
3225
--health-cmd pg_isready
3326
--health-interval 10s
3427
--health-timeout 5s
3528
--health-retries 5
29+
30+
mysql:
31+
image: mysql:8
32+
ports:
33+
- 3306:3306
34+
env:
35+
MYSQL_USER: root
36+
MYSQL_PASSWORD: root
37+
MYSQL_DATABASE: closure_tree_test
38+
MYSQL_ROOT_PASSWORD: root
39+
options: >-
40+
--health-cmd="mysqladmin ping"
41+
--health-interval=10s
42+
--health-timeout=5s
43+
--health-retries=3
3644
3745
strategy:
3846
fail-fast: false
3947
matrix:
4048
ruby:
49+
- '3.3'
4150
- '3.4'
42-
- 'jruby'
43-
- 'truffleruby'
4451
rails:
45-
- '8.0'
4652
- '7.2'
47-
- '7.1'
48-
exclude:
49-
# JRuby doesn't support Rails 8.0 yet
50-
- ruby: 'jruby'
51-
rails: '7.2'
52-
- ruby: 'jruby'
53-
rails: '8.0'
54-
# TruffleRuby also has compatibility issues with Rails 8.0
55-
- ruby: 'truffleruby'
56-
rails: '8.0'
53+
- '8.0'
5754

5855
steps:
5956
- name: Checkout
60-
uses: actions/checkout@v3
57+
uses: actions/checkout@v4
6158

6259
- name: Setup Ruby
6360
uses: ruby/setup-ruby@v1
@@ -67,25 +64,23 @@ jobs:
6764
rubygems: latest
6865
env:
6966
RAILS_VERSION: ${{ matrix.rails }}
70-
RAILS_ENV: test
7167

7268
- name: Setup databases
7369
env:
7470
RAILS_ENV: test
75-
RAILS_VERSION: ${{ matrix.rails }}
7671
DATABASE_URL_PG: postgres://postgres:postgres@127.0.0.1:5432/closure_tree_test
7772
DATABASE_URL_MYSQL: mysql2://root:root@127.0.0.1:3306/closure_tree_test
7873
DATABASE_URL_SQLITE3: 'sqlite3::memory:'
7974
run: |
8075
cd test/dummy
81-
bundle exec rails db:schema:load
76+
bundle exec rails db:setup_all
8277
83-
- name: Test
78+
- name: Run tests
8479
env:
8580
RAILS_ENV: test
86-
RAILS_VERSION: ${{ matrix.rails }}
8781
DATABASE_URL_PG: postgres://postgres:postgres@127.0.0.1:5432/closure_tree_test
8882
DATABASE_URL_MYSQL: mysql2://root:root@127.0.0.1:3306/closure_tree_test
8983
DATABASE_URL_SQLITE3: 'sqlite3::memory:'
9084
WITH_ADVISORY_LOCK_PREFIX: ${{ github.run_id }}
91-
run: bin/rails test
85+
run: |
86+
bundle exec rake test

test/dummy/db/sqlite_schema.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# This file is auto-generated from the current state of the database. Instead
2+
# of editing this file, please use the migrations feature of Active Record to
3+
# incrementally modify your database, and then regenerate this schema definition.
4+
#
5+
# This file is the source Rails uses to define your schema when running `rails
6+
# db:schema:load`. When creating a new database, `rails db:schema:load` tends to
7+
# be faster and is potentially less error prone than running all of your
8+
# migrations from scratch. Old migrations may fail to apply correctly if those
9+
# migrations use external dependencies or application code.
10+
#
11+
# It's strongly recommended that you check this file into your version control system.
12+
13+
ActiveRecord::Schema.define(version: 0) do
14+
create_table "sqlite_tags", force: true do |t|
15+
t.string "name"
16+
t.integer "parent_id"
17+
t.datetime "created_at"
18+
t.datetime "updated_at"
19+
end
20+
21+
create_table "sqlite_tag_hierarchies", id: false, force: true do |t|
22+
t.integer "ancestor_id", null: false
23+
t.integer "descendant_id", null: false
24+
t.integer "generations", null: false
25+
end
26+
27+
add_index "sqlite_tag_hierarchies", [:ancestor_id, :descendant_id, :generations], unique: true, name: "sqlite_tag_anc_desc_idx"
28+
add_index "sqlite_tag_hierarchies", [:descendant_id], name: "sqlite_tag_desc_idx"
29+
end

test/dummy/lib/tasks/db.rake

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,23 @@
22

33
namespace :db do
44
desc 'Setup all databases'
5-
task :setup_all do
6-
ActiveRecord::Base.configurations.configs_for(env_name: Rails.env).each do |db_config|
7-
ActiveRecord::Base.establish_connection(db_config)
8-
ActiveRecord::Tasks::DatabaseTasks.create_current
9-
ActiveRecord::Tasks::DatabaseTasks.load_schema_current
5+
task :setup_all => :environment do
6+
# Load primary database schema
7+
ActiveRecord::Base.establish_connection(:primary)
8+
ActiveRecord::Base.connection.disconnect! if ActiveRecord::Base.connection.active?
9+
ActiveRecord::Base.establish_connection(:primary)
10+
load Rails.root.join('db/schema.rb')
11+
12+
# Load secondary (MySQL) database schema if configured
13+
if ENV['DATABASE_URL_MYSQL'].present?
14+
ActiveRecord::Base.establish_connection(:secondary)
15+
ActiveRecord::Base.connection.disconnect! if ActiveRecord::Base.connection.active?
16+
ActiveRecord::Base.establish_connection(:secondary)
17+
load Rails.root.join('db/secondary_schema.rb')
1018
end
19+
20+
# SQLite is in-memory so it will be created automatically
21+
ActiveRecord::Base.establish_connection(:primary)
1122
end
1223

1324
desc 'Drop all databases'

0 commit comments

Comments
 (0)