Sha256: 79db1a96dc10b321a81524069e53fd73ba6ef5d48fef953a3259d46dc5b967ee

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

## ActiveRecord::TestFixtures
## Monkey patch active record's test_fixtures module to manage
## transactions for the SecondBase
module ActiveRecord
  module TestFixtures
    alias_method :original_setup_fixtures, :setup_fixtures
    alias_method :original_teardown_fixtures, :teardown_fixtures
    
    def setup_fixtures
      original_setup_fixtures
      # start tx for secondbase, if required
      # Load fixtures once and begin transaction.
      if run_in_transaction?
        SecondBase::Base.connection.increment_open_transactions
        SecondBase::Base.connection.transaction_joinable = false
        SecondBase::Base.connection.begin_db_transaction
      end
    end
    
    def teardown_fixtures
      original_teardown_fixtures
      
      # Rollback secondbase changes if a transaction is active.
      if run_in_transaction? && SecondBase::Base.connection.open_transactions != 0
        SecondBase::Base.connection.rollback_db_transaction
        SecondBase::Base.connection.decrement_open_transactions
      end
      
      SecondBase::Base.clear_active_connections!
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
secondbase-0.6.0 lib/secondbase/active_record/test_fixtures.rb