Skip to content
Open
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
49 changes: 49 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Tests

on: [push, pull_request]

jobs:
test:
name: 'Ruby: ${{ matrix.ruby }}'
runs-on: 'ubuntu-22.04'
strategy:
fail-fast: false
matrix:
ruby: ['4.0', '3.4', '3.3', '3.2']

steps:
- uses: actions/checkout@v5
- name: Set up Ruby ${{ matrix.ruby }}
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true # 'bundle install' and cache
- name: Copy config file
run: cp spec/support/sample.config.yml spec/support/config.yml
- name: Run tests
run: bundle exec rake

services:
mysql:
image: mysql:5.7
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

postgres:
# Docker Hub image
image: postgres
# Provide the password for postgres
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
11 changes: 0 additions & 11 deletions .travis.yml

This file was deleted.

1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ gemspec

gem "database_cleaner-core", git: "https://github.com/DatabaseCleaner/database_cleaner"
gem "byebug"
gem "trilogy"

group :test do
gem "simplecov", require: false
Expand Down
2 changes: 1 addition & 1 deletion database_cleaner-sequel.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_dependency "database_cleaner-core", "~>2.0.0"
spec.add_dependency "database_cleaner-core", "~>2.0"
spec.add_dependency "sequel"

spec.add_development_dependency "bundler"
Expand Down
3 changes: 1 addition & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
version: '3.1'

---
services:
mysql:
image: mysql:8
Expand Down
4 changes: 2 additions & 2 deletions spec/database_cleaner/sequel/truncation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module Sequel
helper.teardown
end

let(:connection) { helper.connection }
let(:connection) { helper.connection.unwrap }

before { subject.db = connection }

Expand Down Expand Up @@ -58,7 +58,7 @@ module Sequel
end

describe 'auto increment sequences' do
it "resets AUTO_INCREMENT primary key seqeunce" do
it "resets AUTO_INCREMENT primary key sequence" do
table = connection[:users]
2.times { table.insert }

Expand Down
9 changes: 9 additions & 0 deletions spec/support/sample-docker.config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ mysql2:
port: 3307
encoding: utf8

trilogy:
adapter: trilogy
database: database_cleaner_test
username: database_cleaner
password: database_cleaner
host: 127.0.0.1
port: 3307
encoding: utf8

postgres:
adapter: postgresql
database: database_cleaner_test
Expand Down
11 changes: 10 additions & 1 deletion spec/support/sample.config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,20 @@ mysql2:
port: 3306
encoding: utf8

trilogy:
adapter: trilogy
database: database_cleaner_test
username: root
password:
host: 127.0.0.1
port: 3306
encoding: utf8

postgres:
adapter: postgresql
database: database_cleaner_test
username: postgres
password:
password: postgres
host: 127.0.0.1
encoding: unicode
template: template0
Expand Down
38 changes: 37 additions & 1 deletion spec/support/sequel_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,47 @@
require 'database_cleaner/spec/database_helper'

class SequelHelper < DatabaseCleaner::Spec::DatabaseHelper
class DatabaseShim
def self.wrap(connection)
if defined?(::Sequel::Trilogy::Database) && connection.is_a?(::Sequel::Trilogy::Database)
TrilogyShim.new(connection)
else
new(connection)
end
end

def initialize(connection)
@connection = connection
end

def respond_to_missing?(method, include_private = false)
@connection.respond_to?(method, include_private)
end

def unwrap
@connection
end

private

def method_missing(name, *args, &block)
return super unless respond_to_missing?(name)

@connection.send(name, *args, &block)
end
end

class TrilogyShim < DatabaseShim
def execute(sql)
@connection.run(sql)
end
end

private

def establish_connection(config = default_config)
url = "#{db}:///"
url = "sqlite:///" if db == :sqlite3
@connection = ::Sequel.connect(url, config)
@connection = DatabaseShim.wrap(::Sequel.connect(url, config))
end
end