diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..4acc376 --- /dev/null +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index ab011b9..0000000 --- a/.travis.yml +++ /dev/null @@ -1,11 +0,0 @@ -language: ruby -services: - - mysql - - postgresql -rvm: - - 2.5 - - 2.6 - - 2.7 -before_script: - - bin/setup - diff --git a/Gemfile b/Gemfile index c0cb1c0..fc39ebb 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/database_cleaner-sequel.gemspec b/database_cleaner-sequel.gemspec index 2725c46..9814447 100644 --- a/database_cleaner-sequel.gemspec +++ b/database_cleaner-sequel.gemspec @@ -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" diff --git a/docker-compose.yml b/docker-compose.yml index eaa0ffb..58903bf 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,4 @@ -version: '3.1' - +--- services: mysql: image: mysql:8 diff --git a/spec/database_cleaner/sequel/truncation_spec.rb b/spec/database_cleaner/sequel/truncation_spec.rb index 6b3ad52..278ab7d 100644 --- a/spec/database_cleaner/sequel/truncation_spec.rb +++ b/spec/database_cleaner/sequel/truncation_spec.rb @@ -15,7 +15,7 @@ module Sequel helper.teardown end - let(:connection) { helper.connection } + let(:connection) { helper.connection.unwrap } before { subject.db = connection } @@ -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 } diff --git a/spec/support/sample-docker.config.yml b/spec/support/sample-docker.config.yml index c6d88f4..d467b99 100644 --- a/spec/support/sample-docker.config.yml +++ b/spec/support/sample-docker.config.yml @@ -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 diff --git a/spec/support/sample.config.yml b/spec/support/sample.config.yml index bcbeb1d..4ca6924 100644 --- a/spec/support/sample.config.yml +++ b/spec/support/sample.config.yml @@ -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 diff --git a/spec/support/sequel_helper.rb b/spec/support/sequel_helper.rb index d62020f..da12e97 100644 --- a/spec/support/sequel_helper.rb +++ b/spec/support/sequel_helper.rb @@ -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