Skip to content

Commit a7821a6

Browse files
authored
Merge pull request #30 from leoarnold/leoarnold/github-actions
Pivot from Travis CI to GitHub Actions
2 parents 0d776d6 + f2c7dd2 commit a7821a6

9 files changed

Lines changed: 110 additions & 18 deletions

File tree

.github/workflows/ci.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Tests
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
test:
7+
name: 'Ruby: ${{ matrix.ruby }}'
8+
runs-on: 'ubuntu-22.04'
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
ruby: ['4.0', '3.4', '3.3', '3.2']
13+
14+
steps:
15+
- uses: actions/checkout@v5
16+
- name: Set up Ruby ${{ matrix.ruby }}
17+
uses: ruby/setup-ruby@v1
18+
with:
19+
ruby-version: ${{ matrix.ruby }}
20+
bundler-cache: true # 'bundle install' and cache
21+
- name: Copy config file
22+
run: cp spec/support/sample.config.yml spec/support/config.yml
23+
- name: Run tests
24+
run: bundle exec rake
25+
26+
services:
27+
mysql:
28+
image: mysql:5.7
29+
env:
30+
MYSQL_ALLOW_EMPTY_PASSWORD: yes
31+
ports:
32+
- 3306:3306
33+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
34+
35+
postgres:
36+
# Docker Hub image
37+
image: postgres
38+
# Provide the password for postgres
39+
env:
40+
POSTGRES_USER: postgres
41+
POSTGRES_PASSWORD: postgres
42+
ports:
43+
- 5432:5432
44+
# Set health checks to wait until postgres has started
45+
options: >-
46+
--health-cmd pg_isready
47+
--health-interval 10s
48+
--health-timeout 5s
49+
--health-retries 5

.travis.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ gemspec
55

66
gem "database_cleaner-core", git: "https://github.com/DatabaseCleaner/database_cleaner"
77
gem "byebug"
8+
gem "trilogy"
89

910
group :test do
1011
gem "simplecov", require: false

database_cleaner-sequel.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
1818
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
1919
spec.require_paths = ["lib"]
2020

21-
spec.add_dependency "database_cleaner-core", "~>2.0.0"
21+
spec.add_dependency "database_cleaner-core", "~>2.0"
2222
spec.add_dependency "sequel"
2323

2424
spec.add_development_dependency "bundler"

docker-compose.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
version: '3.1'
2-
1+
---
32
services:
43
mysql:
54
image: mysql:8

spec/database_cleaner/sequel/truncation_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module Sequel
1515
helper.teardown
1616
end
1717

18-
let(:connection) { helper.connection }
18+
let(:connection) { helper.connection.unwrap }
1919

2020
before { subject.db = connection }
2121

@@ -58,7 +58,7 @@ module Sequel
5858
end
5959

6060
describe 'auto increment sequences' do
61-
it "resets AUTO_INCREMENT primary key seqeunce" do
61+
it "resets AUTO_INCREMENT primary key sequence" do
6262
table = connection[:users]
6363
2.times { table.insert }
6464

spec/support/sample-docker.config.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ mysql2:
77
port: 3307
88
encoding: utf8
99

10+
trilogy:
11+
adapter: trilogy
12+
database: database_cleaner_test
13+
username: database_cleaner
14+
password: database_cleaner
15+
host: 127.0.0.1
16+
port: 3307
17+
encoding: utf8
18+
1019
postgres:
1120
adapter: postgresql
1221
database: database_cleaner_test

spec/support/sample.config.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,20 @@ mysql2:
77
port: 3306
88
encoding: utf8
99

10+
trilogy:
11+
adapter: trilogy
12+
database: database_cleaner_test
13+
username: root
14+
password:
15+
host: 127.0.0.1
16+
port: 3306
17+
encoding: utf8
18+
1019
postgres:
1120
adapter: postgresql
1221
database: database_cleaner_test
1322
username: postgres
14-
password:
23+
password: postgres
1524
host: 127.0.0.1
1625
encoding: unicode
1726
template: template0

spec/support/sequel_helper.rb

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,47 @@
22
require 'database_cleaner/spec/database_helper'
33

44
class SequelHelper < DatabaseCleaner::Spec::DatabaseHelper
5+
class DatabaseShim
6+
def self.wrap(connection)
7+
if defined?(::Sequel::Trilogy::Database) && connection.is_a?(::Sequel::Trilogy::Database)
8+
TrilogyShim.new(connection)
9+
else
10+
new(connection)
11+
end
12+
end
13+
14+
def initialize(connection)
15+
@connection = connection
16+
end
17+
18+
def respond_to_missing?(method, include_private = false)
19+
@connection.respond_to?(method, include_private)
20+
end
21+
22+
def unwrap
23+
@connection
24+
end
25+
26+
private
27+
28+
def method_missing(name, *args, &block)
29+
return super unless respond_to_missing?(name)
30+
31+
@connection.send(name, *args, &block)
32+
end
33+
end
34+
35+
class TrilogyShim < DatabaseShim
36+
def execute(sql)
37+
@connection.run(sql)
38+
end
39+
end
40+
541
private
642

743
def establish_connection(config = default_config)
844
url = "#{db}:///"
945
url = "sqlite:///" if db == :sqlite3
10-
@connection = ::Sequel.connect(url, config)
46+
@connection = DatabaseShim.wrap(::Sequel.connect(url, config))
1147
end
1248
end

0 commit comments

Comments
 (0)