mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
change configuration test to test cleaners directly.
This commit is contained in:
parent
b194419fcd
commit
9055df104f
1 changed files with 50 additions and 50 deletions
|
@ -1,45 +1,45 @@
|
||||||
RSpec.describe DatabaseCleaner::Configuration do
|
RSpec.describe DatabaseCleaner::Cleaners do
|
||||||
subject(:config) { described_class.new }
|
subject(:cleaners) { described_class.new }
|
||||||
|
|
||||||
context "orm specification" do
|
context "orm specification" do
|
||||||
it "should not accept nil orms" do
|
it "should not accept nil orms" do
|
||||||
expect { config[nil] }.to raise_error(ArgumentError)
|
expect { cleaners[nil] }.to raise_error(ArgumentError)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should accept :active_record" do
|
it "should accept :active_record" do
|
||||||
cleaner = config[:active_record]
|
cleaner = cleaners[:active_record]
|
||||||
expect(cleaner).to be_a(DatabaseCleaner::Base)
|
expect(cleaner).to be_a(DatabaseCleaner::Base)
|
||||||
expect(cleaner.orm).to eq :active_record
|
expect(cleaner.orm).to eq :active_record
|
||||||
expect(config.cleaners.values).to eq [cleaner]
|
expect(cleaners.values).to eq [cleaner]
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should accept multiple orm's" do
|
it "should accept multiple orm's" do
|
||||||
cleaners = [config[:couch_potato], config[:data_mapper]]
|
cleaners_values = [cleaners[:couch_potato], cleaners[:data_mapper]]
|
||||||
expect(config.cleaners.values.map(&:orm)).to eq [:couch_potato, :data_mapper]
|
expect(cleaners.values.map(&:orm)).to eq [:couch_potato, :data_mapper]
|
||||||
expect(config.cleaners.values).to eq cleaners
|
expect(cleaners.values).to eq cleaners_values
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should accept a connection parameter and store it" do
|
it "should accept a connection parameter and store it" do
|
||||||
cleaner = config[:active_record, connection: :first_connection]
|
cleaner = cleaners[:active_record, connection: :first_connection]
|
||||||
expect(cleaner).to be_a(DatabaseCleaner::Base)
|
expect(cleaner).to be_a(DatabaseCleaner::Base)
|
||||||
expect(cleaner.orm).to eq :active_record
|
expect(cleaner.orm).to eq :active_record
|
||||||
expect(cleaner.db).to eq :first_connection
|
expect(cleaner.db).to eq :first_connection
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should accept multiple connections for a single orm" do
|
it "should accept multiple connections for a single orm" do
|
||||||
config[:data_mapper, connection: :first_db]
|
cleaners[:data_mapper, connection: :first_db]
|
||||||
config[:data_mapper, connection: :second_db]
|
cleaners[:data_mapper, connection: :second_db]
|
||||||
expect(config.cleaners.values.map(&:orm)).to eq [:data_mapper, :data_mapper]
|
expect(cleaners.values.map(&:orm)).to eq [:data_mapper, :data_mapper]
|
||||||
expect(config.cleaners.values.map(&:db)).to eq [:first_db, :second_db]
|
expect(cleaners.values.map(&:db)).to eq [:first_db, :second_db]
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should accept multiple connections and multiple orms" do
|
it "should accept multiple connections and multiple orms" do
|
||||||
config[:data_mapper, connection: :first_db ]
|
cleaners[:data_mapper, connection: :first_db ]
|
||||||
config[:active_record, connection: :second_db]
|
cleaners[:active_record, connection: :second_db]
|
||||||
config[:active_record, connection: :first_db ]
|
cleaners[:active_record, connection: :first_db ]
|
||||||
config[:data_mapper, connection: :second_db]
|
cleaners[:data_mapper, connection: :second_db]
|
||||||
expect(config.cleaners.values.map(&:orm)).to eq [:data_mapper, :active_record, :active_record, :data_mapper]
|
expect(cleaners.values.map(&:orm)).to eq [:data_mapper, :active_record, :active_record, :data_mapper]
|
||||||
expect(config.cleaners.values.map(&:db)).to eq [:first_db, :second_db, :first_db, :second_db]
|
expect(cleaners.values.map(&:db)).to eq [:first_db, :second_db, :first_db, :second_db]
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should retrieve a db rather than create a new one" do
|
it "should retrieve a db rather than create a new one" do
|
||||||
|
@ -47,47 +47,47 @@ RSpec.describe DatabaseCleaner::Configuration do
|
||||||
strategy_class = class_double("DatabaseCleaner::ActiveRecord::Truncation").as_stubbed_const
|
strategy_class = class_double("DatabaseCleaner::ActiveRecord::Truncation").as_stubbed_const
|
||||||
allow(strategy_class).to receive(:new)
|
allow(strategy_class).to receive(:new)
|
||||||
|
|
||||||
cleaner = config[:active_record]
|
cleaner = cleaners[:active_record]
|
||||||
config[:active_record].strategy = :truncation
|
cleaners[:active_record].strategy = :truncation
|
||||||
expect(config[:active_record]).to equal cleaner
|
expect(cleaners[:active_record]).to equal cleaner
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "top level api methods" do
|
context "top level api methods" do
|
||||||
context "single orm single connection" do
|
context "single orm single connection" do
|
||||||
let(:connection) { config[:active_record] }
|
let(:cleaner) { cleaners[:active_record] }
|
||||||
|
|
||||||
it "should proxy strategy=" do
|
it "should proxy strategy=" do
|
||||||
stratagem = double("stratagem")
|
stratagem = double("stratagem")
|
||||||
expect(connection).to receive(:strategy=).with(stratagem)
|
expect(cleaner).to receive(:strategy=).with(stratagem)
|
||||||
config.strategy = stratagem
|
cleaners.strategy = stratagem
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should proxy orm=" do
|
it "should proxy orm=" do
|
||||||
orm = double("orm")
|
orm = double("orm")
|
||||||
expect(connection).to receive(:orm=).with(orm)
|
expect(cleaner).to receive(:orm=).with(orm)
|
||||||
config.orm = orm
|
cleaners.orm = orm
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should proxy start" do
|
it "should proxy start" do
|
||||||
expect(connection).to receive(:start)
|
expect(cleaner).to receive(:start)
|
||||||
config.start
|
cleaners.start
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should proxy clean" do
|
it "should proxy clean" do
|
||||||
expect(connection).to receive(:clean)
|
expect(cleaner).to receive(:clean)
|
||||||
config.clean
|
cleaners.clean
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should proxy cleaning' do
|
it 'should proxy cleaning' do
|
||||||
expect(connection).to receive(:cleaning)
|
expect(cleaner).to receive(:cleaning)
|
||||||
config.cleaning { }
|
cleaners.cleaning { }
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should proxy clean_with" do
|
it "should proxy clean_with" do
|
||||||
stratagem = double("stratgem")
|
stratagem = double("stratgem")
|
||||||
expect(connection).to receive(:clean_with).with(stratagem, {})
|
expect(cleaner).to receive(:clean_with).with(stratagem, {})
|
||||||
config.clean_with stratagem, {}
|
cleaners.clean_with stratagem, {}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -98,8 +98,8 @@ RSpec.describe DatabaseCleaner::Configuration do
|
||||||
let(:active_record) { double("active_mock") }
|
let(:active_record) { double("active_mock") }
|
||||||
let(:data_mapper) { double("data_mock") }
|
let(:data_mapper) { double("data_mock") }
|
||||||
|
|
||||||
before do
|
subject(:cleaners) do
|
||||||
config.cleaners = DatabaseCleaner::Cleaners.new({
|
DatabaseCleaner::Cleaners.new({
|
||||||
active_record: active_record,
|
active_record: active_record,
|
||||||
data_mapper: data_mapper,
|
data_mapper: data_mapper,
|
||||||
})
|
})
|
||||||
|
@ -109,21 +109,21 @@ RSpec.describe DatabaseCleaner::Configuration do
|
||||||
expect(active_record).to receive(:orm=)
|
expect(active_record).to receive(:orm=)
|
||||||
expect(data_mapper).to receive(:orm=)
|
expect(data_mapper).to receive(:orm=)
|
||||||
|
|
||||||
config.orm = :orm
|
cleaners.orm = :orm
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should proxy start to all cleaners" do
|
it "should proxy start to all cleaners" do
|
||||||
expect(active_record).to receive(:start)
|
expect(active_record).to receive(:start)
|
||||||
expect(data_mapper).to receive(:start)
|
expect(data_mapper).to receive(:start)
|
||||||
|
|
||||||
config.start
|
cleaners.start
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should proxy clean to all cleaners" do
|
it "should proxy clean to all cleaners" do
|
||||||
expect(active_record).to receive(:clean)
|
expect(active_record).to receive(:clean)
|
||||||
expect(data_mapper).to receive(:clean)
|
expect(data_mapper).to receive(:clean)
|
||||||
|
|
||||||
config.clean
|
cleaners.clean
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should proxy clean_with to all cleaners" do
|
it "should proxy clean_with to all cleaners" do
|
||||||
|
@ -131,7 +131,7 @@ RSpec.describe DatabaseCleaner::Configuration do
|
||||||
expect(active_record).to receive(:clean_with).with(stratagem)
|
expect(active_record).to receive(:clean_with).with(stratagem)
|
||||||
expect(data_mapper).to receive(:clean_with).with(stratagem)
|
expect(data_mapper).to receive(:clean_with).with(stratagem)
|
||||||
|
|
||||||
config.clean_with stratagem
|
cleaners.clean_with stratagem
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should initiate cleaning on each connection, yield, and finish cleaning each connection" do
|
it "should initiate cleaning on each connection, yield, and finish cleaning each connection" do
|
||||||
|
@ -148,7 +148,7 @@ RSpec.describe DatabaseCleaner::Configuration do
|
||||||
end
|
end
|
||||||
|
|
||||||
yielded = false
|
yielded = false
|
||||||
config.cleaning do
|
cleaners.cleaning do
|
||||||
expect(active_record.started).to eq(true)
|
expect(active_record.started).to eq(true)
|
||||||
expect(data_mapper.started).to eq(true)
|
expect(data_mapper.started).to eq(true)
|
||||||
expect(active_record.cleaned).to eq(nil)
|
expect(active_record.cleaned).to eq(nil)
|
||||||
|
@ -172,8 +172,8 @@ RSpec.describe DatabaseCleaner::Configuration do
|
||||||
let(:active_record_2) { FakeStrategy.new(:active_record, :different) }
|
let(:active_record_2) { FakeStrategy.new(:active_record, :different) }
|
||||||
let(:data_mapper_1) { FakeStrategy.new(:data_mapper) }
|
let(:data_mapper_1) { FakeStrategy.new(:data_mapper) }
|
||||||
|
|
||||||
before do
|
subject(:cleaners) do
|
||||||
config.cleaners = DatabaseCleaner::Cleaners.new({
|
DatabaseCleaner::Cleaners.new({
|
||||||
active_record_1: active_record_1,
|
active_record_1: active_record_1,
|
||||||
active_record_2: active_record_2,
|
active_record_2: active_record_2,
|
||||||
data_mapper_1: data_mapper_1,
|
data_mapper_1: data_mapper_1,
|
||||||
|
@ -181,8 +181,8 @@ RSpec.describe DatabaseCleaner::Configuration do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should proxy #orm= to all cleaners and remove duplicate cleaners" do
|
it "should proxy #orm= to all cleaners and remove duplicate cleaners" do
|
||||||
expect { config.orm = :data_mapper }
|
expect { cleaners.orm = :data_mapper }
|
||||||
.to change { config.cleaners.values }
|
.to change { cleaners.values }
|
||||||
.from([active_record_1,active_record_2,data_mapper_1])
|
.from([active_record_1,active_record_2,data_mapper_1])
|
||||||
.to([active_record_1,active_record_2])
|
.to([active_record_1,active_record_2])
|
||||||
end
|
end
|
||||||
|
@ -192,16 +192,16 @@ RSpec.describe DatabaseCleaner::Configuration do
|
||||||
let(:active_record_1) { FakeStrategy.new(:active_record, :default, :truncation) }
|
let(:active_record_1) { FakeStrategy.new(:active_record, :default, :truncation) }
|
||||||
let(:active_record_2) { FakeStrategy.new(:active_record, :default, :transaction) }
|
let(:active_record_2) { FakeStrategy.new(:active_record, :default, :transaction) }
|
||||||
|
|
||||||
before do
|
subject(:cleaners) do
|
||||||
config.cleaners = DatabaseCleaner::Cleaners.new({
|
DatabaseCleaner::Cleaners.new({
|
||||||
active_record_1: active_record_1,
|
active_record_1: active_record_1,
|
||||||
active_record_2: active_record_2,
|
active_record_2: active_record_2,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should proxy #strategy= to all cleaners and remove duplicate cleaners" do
|
it "should proxy #strategy= to all cleaners and remove duplicate cleaners" do
|
||||||
expect { config.strategy = :truncation }
|
expect { cleaners.strategy = :truncation }
|
||||||
.to change { config.cleaners.values }
|
.to change { cleaners.values }
|
||||||
.from([active_record_1,active_record_2])
|
.from([active_record_1,active_record_2])
|
||||||
.to([active_record_1])
|
.to([active_record_1])
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue