mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
specs for transaction
This commit is contained in:
parent
ba886ee1ec
commit
7648c3e5e6
1 changed files with 66 additions and 0 deletions
66
spec/database_cleaner/active_record/transaction_spec.rb
Normal file
66
spec/database_cleaner/active_record/transaction_spec.rb
Normal file
|
@ -0,0 +1,66 @@
|
|||
require File.dirname(__FILE__) + '/../../spec_helper'
|
||||
require 'database_cleaner/active_record/transaction'
|
||||
require 'active_record'
|
||||
|
||||
module DatabaseCleaner
|
||||
module ActiveRecord
|
||||
|
||||
describe Transaction do
|
||||
let (:connection) { mock("connection") }
|
||||
before(:each) do
|
||||
#connection.stub!(:disable_referential_integrity).and_yield
|
||||
::ActiveRecord::Base.stub!(:connection).and_return(connection)
|
||||
end
|
||||
|
||||
describe "start" do
|
||||
it "should increment open transactions if possible" do
|
||||
connection.stub!(:respond_to?).with(:increment_open_transactions).and_return(true)
|
||||
connection.stub!(:begin_db_transaction)
|
||||
|
||||
connection.should_receive(:increment_open_transactions)
|
||||
Transaction.new.start
|
||||
end
|
||||
|
||||
it "should tell ActiveRecord to increment connection if its not possible to increment current connection" do
|
||||
connection.stub!(:respond_to?).with(:increment_open_transactions).and_return(false)
|
||||
connection.stub!(:begin_db_transaction)
|
||||
|
||||
::ActiveRecord::Base.should_receive(:increment_open_transactions)
|
||||
Transaction.new.start
|
||||
end
|
||||
|
||||
it "should start a transaction" do
|
||||
connection.stub!(:increment_open_transactions)
|
||||
|
||||
connection.should_receive(:begin_db_transaction)
|
||||
Transaction.new.start
|
||||
end
|
||||
end
|
||||
|
||||
describe "clean" do
|
||||
it "should start a transaction" do
|
||||
connection.stub!(:decrement_open_transactions)
|
||||
|
||||
connection.should_receive(:rollback_db_transaction)
|
||||
Transaction.new.clean
|
||||
end
|
||||
it "should decrement open transactions if possible" do
|
||||
connection.stub!(:respond_to?).with(:decrement_open_transactions).and_return(true)
|
||||
connection.stub!(:rollback_db_transaction)
|
||||
|
||||
connection.should_receive(:decrement_open_transactions)
|
||||
Transaction.new.clean
|
||||
end
|
||||
|
||||
it "should decrement connection via ActiveRecord::Base if connection won't" do
|
||||
connection.stub!(:respond_to?).with(:decrement_open_transactions).and_return(false)
|
||||
connection.stub!(:rollback_db_transaction)
|
||||
|
||||
::ActiveRecord::Base.should_receive(:decrement_open_transactions)
|
||||
Transaction.new.clean
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue