From 6e4c18429473731445d9a14cc75bf625319b30aa Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Wed, 31 Mar 2010 08:02:48 +0100 Subject: [PATCH] More specs, multiple orms under way nicely, multiple db connections needs refactoring --- lib/database_cleaner/configuration.rb | 6 +-- spec/database_cleaner/configuration_spec.rb | 48 ++++++++++++++++++--- 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/lib/database_cleaner/configuration.rb b/lib/database_cleaner/configuration.rb index f4e4c4f..755247f 100644 --- a/lib/database_cleaner/configuration.rb +++ b/lib/database_cleaner/configuration.rb @@ -56,15 +56,15 @@ module DatabaseCleaner end def start - self.connections.first.start + self.connections.each { |connection| connection.start } end def clean - self.connections.first.clean + self.connections.each { |connection| connection.clean } end def clean_with(stratagem) - self.connections.first.clean_with stratagem + self.connections.each { |connection| connection.clean_with stratagem } end end diff --git a/spec/database_cleaner/configuration_spec.rb b/spec/database_cleaner/configuration_spec.rb index 29fb6b5..714ce12 100644 --- a/spec/database_cleaner/configuration_spec.rb +++ b/spec/database_cleaner/configuration_spec.rb @@ -58,6 +58,7 @@ describe DatabaseCleaner do it "should give me a default (autodetection) databasecleaner by default" do ::DatabaseCleaner.connections.should have (1).items ::DatabaseCleaner.connections.first.should be_a ::DatabaseCleaner::Base + ::DatabaseCleaner.connections.first.auto_detected.should be_true end end @@ -135,7 +136,7 @@ describe DatabaseCleaner do end end - context "single orm" do + context "single orm single connection" do let (:connection) { ::DatabaseCleaner.connections.first } it "should proxy strategy=" do stratagum = mock("stratagum") @@ -165,13 +166,48 @@ describe DatabaseCleaner do ::DatabaseCleaner.clean_with stratagem 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 "orm_module" do - it "should proxy to the class method" - end - let(:strategy) { mock("stratagum") } context "active record" do @@ -184,7 +220,7 @@ describe DatabaseCleaner do end 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') result = cleaner.create_strategy(:transaction, {'options' => 'hash'}) result.should == strategy