extract DatabaseHelper.with_all_dbs.

This commit is contained in:
Micah Geisel 2018-05-22 08:09:42 -07:00
parent ff90ec2d1e
commit f68782abec
4 changed files with 16 additions and 19 deletions

View File

@ -1,20 +1,17 @@
require 'support/active_record_helper'
require 'database_cleaner/active_record/truncation'
require 'database_cleaner/active_record/truncation/shared_fast_truncation'
RSpec.describe DatabaseCleaner::ActiveRecord::Truncation do
%w[mysql mysql2 sqlite3 postgres].map(&:to_sym).each do |db|
context "using a #{db} connection" do
let(:helper) { ActiveRecordHelper.new(db) }
let(:connection) { helper.connection }
ActiveRecordHelper.with_all_dbs do |helper|
context "using a #{helper.db} connection" do
around do |example|
helper.setup
example.run
helper.teardown
end
let(:connection) { helper.connection }
describe "AR connection adapter monkeypatches" do
describe "#truncate_table" do
it "truncates the table" do
@ -43,7 +40,7 @@ RSpec.describe DatabaseCleaner::ActiveRecord::Truncation do
end
end
unless db == :sqlite3
unless helper.db == :sqlite3
describe "#pre_count_truncate_tables" do
context "with :reset_ids set true" do
@ -84,7 +81,7 @@ RSpec.describe DatabaseCleaner::ActiveRecord::Truncation do
end
end
if db == :postgres
if helper.db == :postgres
describe ":except option cleanup" do
it "should not truncate the tables specified in the :except option" do
2.times { User.create }
@ -101,8 +98,6 @@ RSpec.describe DatabaseCleaner::ActiveRecord::Truncation do
end
end
it_behaves_like "an adapter with pre-count truncation"
describe "schema_migrations table" do
it "is not truncated" do

View File

@ -7,10 +7,8 @@ module DatabaseCleaner
RSpec.describe Deletion do
it_should_behave_like "a generic strategy"
%w[mysql mysql2 sqlite3 postgres].map(&:to_sym).each do |db|
context "using a #{db} connection" do
let(:helper) { SequelHelper.new(db) }
SequelHelper.with_all_dbs do |helper|
context "using a #{helper.db} connection" do
around do |example|
helper.setup
example.run

View File

@ -8,10 +8,8 @@ module DatabaseCleaner
it_should_behave_like "a generic strategy"
it_should_behave_like "a generic truncation strategy"
%w[mysql mysql2 sqlite3 postgres].map(&:to_sym).each do |db|
context "using a #{db} connection" do
let(:helper) { SequelHelper.new(db) }
SequelHelper.with_all_dbs do |helper|
context "using a #{helper.db} connection" do
around do |example|
helper.setup
example.run

View File

@ -1,6 +1,12 @@
require 'yaml'
class DatabaseHelper < Struct.new(:db)
def self.with_all_dbs &block
%w[mysql mysql2 sqlite3 postgres].map(&:to_sym).each do |db|
yield new(db)
end
end
def setup
create_db
establish_connection