diff --git a/lib/database_cleaner/active_record/transaction.rb b/lib/database_cleaner/active_record/transaction.rb index e7b4990..ee96ffb 100644 --- a/lib/database_cleaner/active_record/transaction.rb +++ b/lib/database_cleaner/active_record/transaction.rb @@ -7,6 +7,10 @@ module DatabaseCleaner::ActiveRecord include ::DatabaseCleaner::Generic::Transaction def start + # Hack to make sure that the connection is properly setup for + # the clean code. + connection_class.connection.transaction + if connection_maintains_transaction_count? if connection_class.connection.respond_to?(:increment_open_transactions) connection_class.connection.increment_open_transactions diff --git a/spec/database_cleaner/active_record/transaction_spec.rb b/spec/database_cleaner/active_record/transaction_spec.rb index 25aff0d..de70d7d 100644 --- a/spec/database_cleaner/active_record/transaction_spec.rb +++ b/spec/database_cleaner/active_record/transaction_spec.rb @@ -15,6 +15,7 @@ module DatabaseCleaner [:begin_transaction, :begin_db_transaction].each do |begin_transaction_method| context "using #{begin_transaction_method}" do before do + connection.stub(:transaction) connection.stub(begin_transaction_method) connection.stub(:respond_to?).with(:begin_transaction).and_return(:begin_transaction == begin_transaction_method) end @@ -35,6 +36,7 @@ module DatabaseCleaner connection.stub(:respond_to?).with(:increment_open_transactions).and_return(true) connection.stub(:increment_open_transactions) connection.should_receive(begin_transaction_method) + connection.should_receive(:transaction) Transaction.new.start end end