Don't clean it if nothing can be cleaned.
This commit is contained in:
parent
7d4b21a1fa
commit
f921a26b25
|
@ -14,6 +14,8 @@ module DatabaseCleaner::ActiveRecord
|
||||||
|
|
||||||
|
|
||||||
def clean
|
def clean
|
||||||
|
return unless connection_klass.connection.open_transactions > 0
|
||||||
|
|
||||||
connection_klass.connection.rollback_db_transaction
|
connection_klass.connection.rollback_db_transaction
|
||||||
|
|
||||||
if connection_klass.connection.respond_to?(:decrement_open_transactions)
|
if connection_klass.connection.respond_to?(:decrement_open_transactions)
|
||||||
|
|
|
@ -38,12 +38,17 @@ module DatabaseCleaner
|
||||||
|
|
||||||
describe "#clean" do
|
describe "#clean" do
|
||||||
it "should start a transaction" do
|
it "should start a transaction" do
|
||||||
|
connection.should_receive(:open_transactions).and_return(1)
|
||||||
|
|
||||||
connection.stub!(:decrement_open_transactions)
|
connection.stub!(:decrement_open_transactions)
|
||||||
|
|
||||||
connection.should_receive(:rollback_db_transaction)
|
connection.should_receive(:rollback_db_transaction)
|
||||||
Transaction.new.clean
|
Transaction.new.clean
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should decrement open transactions if possible" do
|
it "should decrement open transactions if possible" do
|
||||||
|
connection.should_receive(:open_transactions).and_return(1)
|
||||||
|
|
||||||
connection.stub!(:respond_to?).with(:decrement_open_transactions).and_return(true)
|
connection.stub!(:respond_to?).with(:decrement_open_transactions).and_return(true)
|
||||||
connection.stub!(:rollback_db_transaction)
|
connection.stub!(:rollback_db_transaction)
|
||||||
|
|
||||||
|
@ -51,7 +56,14 @@ module DatabaseCleaner
|
||||||
Transaction.new.clean
|
Transaction.new.clean
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should not try to decrement or rollback if open_transactions is 0 for whatever reason" do
|
||||||
|
connection.should_receive(:open_transactions).and_return(0)
|
||||||
|
|
||||||
|
Transaction.new.clean
|
||||||
|
end
|
||||||
|
|
||||||
it "should decrement connection via ActiveRecord::Base if connection won't" do
|
it "should decrement connection via ActiveRecord::Base if connection won't" do
|
||||||
|
connection.should_receive(:open_transactions).and_return(1)
|
||||||
connection.stub!(:respond_to?).with(:decrement_open_transactions).and_return(false)
|
connection.stub!(:respond_to?).with(:decrement_open_transactions).and_return(false)
|
||||||
connection.stub!(:rollback_db_transaction)
|
connection.stub!(:rollback_db_transaction)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue