mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
More specs, multiple orms under way nicely, multiple db connections needs refactoring
This commit is contained in:
parent
f7858cd501
commit
6e4c184294
2 changed files with 45 additions and 9 deletions
|
|
@ -56,15 +56,15 @@ module DatabaseCleaner
|
||||||
end
|
end
|
||||||
|
|
||||||
def start
|
def start
|
||||||
self.connections.first.start
|
self.connections.each { |connection| connection.start }
|
||||||
end
|
end
|
||||||
|
|
||||||
def clean
|
def clean
|
||||||
self.connections.first.clean
|
self.connections.each { |connection| connection.clean }
|
||||||
end
|
end
|
||||||
|
|
||||||
def clean_with(stratagem)
|
def clean_with(stratagem)
|
||||||
self.connections.first.clean_with stratagem
|
self.connections.each { |connection| connection.clean_with stratagem }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,7 @@ describe DatabaseCleaner do
|
||||||
it "should give me a default (autodetection) databasecleaner by default" do
|
it "should give me a default (autodetection) databasecleaner by default" do
|
||||||
::DatabaseCleaner.connections.should have (1).items
|
::DatabaseCleaner.connections.should have (1).items
|
||||||
::DatabaseCleaner.connections.first.should be_a ::DatabaseCleaner::Base
|
::DatabaseCleaner.connections.first.should be_a ::DatabaseCleaner::Base
|
||||||
|
::DatabaseCleaner.connections.first.auto_detected.should be_true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -135,7 +136,7 @@ describe DatabaseCleaner do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "single orm" do
|
context "single orm single connection" do
|
||||||
let (:connection) { ::DatabaseCleaner.connections.first }
|
let (:connection) { ::DatabaseCleaner.connections.first }
|
||||||
it "should proxy strategy=" do
|
it "should proxy strategy=" do
|
||||||
stratagum = mock("stratagum")
|
stratagum = mock("stratagum")
|
||||||
|
|
@ -165,13 +166,48 @@ describe DatabaseCleaner do
|
||||||
::DatabaseCleaner.clean_with stratagem
|
::DatabaseCleaner.clean_with stratagem
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "multiple orms single connection per orm" do
|
||||||
|
context "proxy methods" do
|
||||||
|
let(:active_record) { mock("active_mock") }
|
||||||
|
let(:data_mapper) { mock("data_mock") }
|
||||||
|
|
||||||
|
before(:each) do
|
||||||
|
::DatabaseCleaner.stub!(:connections).and_return([active_record,data_mapper])
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should proxy start to all connections" do
|
||||||
|
active_record.should_receive(:start)
|
||||||
|
data_mapper.should_receive(:start)
|
||||||
|
|
||||||
|
::DatabaseCleaner.start
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should proxy clean to all connections" do
|
||||||
|
active_record.should_receive(:clean)
|
||||||
|
data_mapper.should_receive(:clean)
|
||||||
|
|
||||||
|
::DatabaseCleaner.clean
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should proxy clean_with to all connections" do
|
||||||
|
stratagem = mock("stratgem")
|
||||||
|
active_record.should_receive(:clean_with).with(stratagem)
|
||||||
|
data_mapper.should_receive(:clean_with).with(stratagem)
|
||||||
|
|
||||||
|
::DatabaseCleaner.clean_with stratagem
|
||||||
|
end
|
||||||
|
end
|
||||||
|
context "more contentious proxy methods" do
|
||||||
|
it "should proxy orm to all connections and remove duplicate connections" do
|
||||||
|
|
||||||
|
::DatabaseCleaner.orm = :active_record
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe ::DatabaseCleaner::Base do
|
describe ::DatabaseCleaner::Base do
|
||||||
|
|
||||||
describe "orm_module" do
|
|
||||||
it "should proxy to the class method"
|
|
||||||
end
|
|
||||||
|
|
||||||
let(:strategy) { mock("stratagum") }
|
let(:strategy) { mock("stratagum") }
|
||||||
|
|
||||||
context "active record" do
|
context "active record" do
|
||||||
|
|
@ -184,7 +220,7 @@ describe DatabaseCleaner do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".create_strategy" do
|
describe ".create_strategy" do
|
||||||
it "should initialize and return the appropirate strategy" do
|
it "should initialize and return the appropriate strategy" do
|
||||||
DatabaseCleaner::ActiveRecord::Transaction.should_receive(:new).with('options' => 'hash')
|
DatabaseCleaner::ActiveRecord::Transaction.should_receive(:new).with('options' => 'hash')
|
||||||
result = cleaner.create_strategy(:transaction, {'options' => 'hash'})
|
result = cleaner.create_strategy(:transaction, {'options' => 'hash'})
|
||||||
result.should == strategy
|
result.should == strategy
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue