mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
some tests for #cleaning
This commit is contained in:
parent
587d0ac6c8
commit
d86e97055c
3 changed files with 36 additions and 0 deletions
|
@ -451,6 +451,13 @@ module DatabaseCleaner
|
||||||
subject.clean!
|
subject.clean!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "cleaning" do
|
||||||
|
it "should proxy cleaning to the strategy" do
|
||||||
|
strategy.should_receive(:cleaning)
|
||||||
|
subject.cleaning { }
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "auto_detected?" do
|
describe "auto_detected?" do
|
||||||
|
|
|
@ -163,6 +163,11 @@ describe ::DatabaseCleaner do
|
||||||
::DatabaseCleaner.clean
|
::DatabaseCleaner.clean
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should proxy cleaning' do
|
||||||
|
connection.should_receive(:cleaning)
|
||||||
|
::DatabaseCleaner.cleaning { }
|
||||||
|
end
|
||||||
|
|
||||||
it "should proxy clean_with" do
|
it "should proxy clean_with" do
|
||||||
stratagem = double("stratgem")
|
stratagem = double("stratgem")
|
||||||
connection.should_receive(:clean_with).with(stratagem, {})
|
connection.should_receive(:clean_with).with(stratagem, {})
|
||||||
|
@ -203,6 +208,28 @@ describe ::DatabaseCleaner do
|
||||||
::DatabaseCleaner.clean
|
::DatabaseCleaner.clean
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should initiate cleaning on each connection, yield, and finish cleaning each connection" do
|
||||||
|
[active_record, data_mapper].each do |connection|
|
||||||
|
mc = class << connection; self; end
|
||||||
|
mc.send(:attr_reader, :started, :cleaned)
|
||||||
|
mc.send(:define_method, 'cleaning') do |&block|
|
||||||
|
@started = true
|
||||||
|
block.call
|
||||||
|
@cleaned = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
::DatabaseCleaner.cleaning do
|
||||||
|
active_record.started.should == true
|
||||||
|
data_mapper.started.should == true
|
||||||
|
active_record.cleaned.should == nil
|
||||||
|
data_mapper.cleaned.should == nil
|
||||||
|
@yielded = true
|
||||||
|
end
|
||||||
|
active_record.cleaned.should == true
|
||||||
|
data_mapper.cleaned.should == true
|
||||||
|
end
|
||||||
|
|
||||||
it "should proxy clean_with to all connections" do
|
it "should proxy clean_with to all connections" do
|
||||||
stratagem = double("stratgem")
|
stratagem = double("stratgem")
|
||||||
active_record.should_receive(:clean_with).with(stratagem)
|
active_record.should_receive(:clean_with).with(stratagem)
|
||||||
|
|
|
@ -5,9 +5,11 @@ end
|
||||||
shared_examples_for "a generic truncation strategy" do
|
shared_examples_for "a generic truncation strategy" do
|
||||||
it { should respond_to(:start) }
|
it { should respond_to(:start) }
|
||||||
it { should respond_to(:clean) }
|
it { should respond_to(:clean) }
|
||||||
|
it { should respond_to(:cleaning) }
|
||||||
end
|
end
|
||||||
|
|
||||||
shared_examples_for "a generic transaction strategy" do
|
shared_examples_for "a generic transaction strategy" do
|
||||||
it { should respond_to(:start) }
|
it { should respond_to(:start) }
|
||||||
it { should respond_to(:clean) }
|
it { should respond_to(:clean) }
|
||||||
|
it { should respond_to(:cleaning) }
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue