mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
Merge pull request #191 from cleanoffer/fix_active_record_start_transaction
Call transaction before calling rollback_transaction_records
This commit is contained in:
commit
c34b4e4dea
2 changed files with 6 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue