diff --git a/.rspec b/.rspec index 34c5164..65c58ab 100644 --- a/.rspec +++ b/.rspec @@ -1,3 +1,4 @@ --format documentation --color --require spec_helper +--tag ~with_jdbc diff --git a/Gemfile b/Gemfile index c0cb1c0..3699139 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,19 @@ source "https://rubygems.org" gemspec gem "database_cleaner-core", git: "https://github.com/DatabaseCleaner/database_cleaner" -gem "byebug" + +group :cruby_only do + gem "byebug" + gem "mysql2" + gem "pg" + gem "sqlite3" +end + +group :development do + gem "bundler" + gem "rake" + gem "rspec" +end group :test do gem "simplecov", require: false diff --git a/database_cleaner-sequel.gemspec b/database_cleaner-sequel.gemspec index 2725c46..6e4adea 100644 --- a/database_cleaner-sequel.gemspec +++ b/database_cleaner-sequel.gemspec @@ -20,11 +20,4 @@ Gem::Specification.new do |spec| spec.add_dependency "database_cleaner-core", "~>2.0.0" spec.add_dependency "sequel" - - spec.add_development_dependency "bundler" - spec.add_development_dependency "rake" - spec.add_development_dependency "rspec" - spec.add_development_dependency "mysql2" - spec.add_development_dependency "pg" - spec.add_development_dependency "sqlite3" end diff --git a/spec/database_cleaner/sequel/jdbc_transaction_spec.rb b/spec/database_cleaner/sequel/jdbc_transaction_spec.rb new file mode 100644 index 0000000..44883f0 --- /dev/null +++ b/spec/database_cleaner/sequel/jdbc_transaction_spec.rb @@ -0,0 +1,117 @@ +require 'database_cleaner/sequel/transaction' +require 'database_cleaner/spec' +require 'sequel' +require 'database_cleaner/spec/database_helper' +require 'ostruct' + +if RUBY_PLATFORM == 'java' + require_relative '../../support/postgresql-42.3.0.jar' + + class SequelHelper < DatabaseCleaner::Spec::DatabaseHelper + private + + def establish_connection(_config = default_config) + @connection = ::Sequel.connect( + # 'postgres://database_cleaner:database_cleaner@127.0.0.1:5433/database_cleaner_test' + 'jdbc:postgresql://127.0.0.1:5433/database_cleaner_test?user=database_cleaner&password=database_cleaner' + ) + end + end +end + +module DatabaseCleaner + module Sequel + RSpec.describe Transaction, :with_jdbc do + it_should_behave_like "a database_cleaner strategy" + + SequelHelper.with_all_dbs do |helper| + next unless helper.db == :postgres + + context "using a #{helper.db} connection" do + around do |example| + helper.setup + example.run + helper.teardown + end + + let(:connection) { helper.connection } + + before { subject.db = connection } + + context "cleaning" do + it "should clean database" do + subject.cleaning do + connection[:users].insert + expect(connection[:users].count).to eq(1) + end + + expect(connection[:users]).to be_empty + end + + it "should work with nested transaction" do + subject.cleaning do + begin + connection.transaction do + connection[:users].insert + connection[:users].insert + + expect(connection[:users].count).to eq(2) + raise ::Sequel::Rollback + end + rescue + end + + connection[:users].insert + expect(connection[:users].count).to eq(1) + end + + expect(connection[:users]).to be_empty + end + end + + context "start/clean" do + it "should clean database" do + subject.start + + connection[:users].insert + expect(connection[:users].count).to eq(1) + + subject.clean + + expect(connection[:users]).to be_empty + end + + it "should work with nested transaction" do + subject.start + begin + connection.transaction do + connection[:users].insert + connection[:users].insert + + expect(connection[:users].count).to eq(2) + raise ::Sequel::Rollback + end + rescue + end + + connection[:users].insert + expect(connection[:users].count).to eq(1) + + subject.clean + + expect(connection[:users]).to be_empty + end + end + end + end + + describe "start" do + it "should start a transaction" + end + + describe "clean" do + it "should finish a transaction" + end + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 61f4f37..e2c53f9 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,4 @@ require "bundler/setup" -require "byebug" if ENV['COVERAGE'] == 'true' require "simplecov" diff --git a/spec/support/postgresql-42.3.0.jar b/spec/support/postgresql-42.3.0.jar new file mode 100644 index 0000000..03cb692 Binary files /dev/null and b/spec/support/postgresql-42.3.0.jar differ