Sha256: 9e061377494f46f4b2c9fd87e31bf8f21748e86731efa92d1ea9eff5bec12206

Contents?: true

Size: 1.49 KB

Versions: 1

Compression:

Stored size: 1.49 KB

Contents

require 'rubygems'        
require 'active_record'  
             
require File.join( File.dirname(__FILE__), %w[.. lib mole] )

# Init the mole with defaults             
::Mole.initialize
         
# Connect to the database    
unless ActiveRecord::Base.connected?
  db_config = YAML.load_file( File.join( File.dirname(__FILE__), %w[.. config database.yml] ) )["test"]
  # ::ActiveRecord::Base.logger = ::Mole.logger 
  # ::ActiveRecord::Base.logger.level = :debug
  ::ActiveRecord::Base.establish_connection(db_config)
end

class CallStackChecker
  class << self
    def called
      @called = 1
    end
    
    def reset
      @called = 0
    end
    
    def called?
      @called == 1
    end    
  end
end
                  
gem 'rspec'
require 'spec'
                     
Spec::Runner.configure do |config|  
  config.before(:each) do
    # from fixtures.rb in rails
    begin
      ActiveRecord::Base.send :increment_open_transactions
      ActiveRecord::Base.connection.begin_db_transaction
    rescue
    end
  end

  config.after(:each) do      
    begin
      # from fixtures.rb in rails
      if Thread.current['open_transactions'] && Thread.current['open_transactions'] > 0
        Thread.current['open_transactions'].downto(1) do
          ActiveRecord::Base.connection.rollback_db_transaction if ActiveRecord::Base.connection
        end
        Thread.current['open_transactions'] = 0
      end
      ActiveRecord::Base.verify_active_connections!
    rescue
    end
  end
end                           

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mole-0.0.1 spec/spec_helper.rb