Sha256: 65ed398cac138aa0c346e00f32ff8e89ff522ef496176e9ea8044ae21a1b0897

Contents?: true

Size: 1.62 KB

Versions: 5

Compression:

Stored size: 1.62 KB

Contents

$:.unshift File.dirname(__FILE__)
require 'rubygems'

ENV["RAILS_ENV"] ||= 'test'

#require File.expand_path("../dummy/config/environment", __FILE__)
require 'logger'
require 'require_all'
require 'cutter'
require 'sugar-high/dsl'

require 'active_record'

require 'rspec/core'

require 'factory_girl'

require 'simple_roles'

require_all File.expand_path('../support', __FILE__)

path = File.dirname(__FILE__) + '/support/database.yml'

dbfile = File.open(path)
dbconfig = YAML::load(dbfile)
ActiveRecord::Base.establish_connection(dbconfig)

class ActiveRecord::Base
  mattr_accessor :shared_connection
  @@shared_connection = nil

  def self.connection
    @@shared_connection || retrieve_connection
  end
end

ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection

# ActiveRecord::Base.logger = Logger.new(STDERR)

RSpec.configure do |config|
  config.mock_with :rspec

  config.include FactoryGirl::Syntax::Methods

  config.before(:suite) do
    with ActiveRecord::Base.connection do
      # tables.each {|t| drop_table t }

      with ActiveRecord::Migrator do
        # SimpleRoles's own migrations
        migrate File.expand_path('../../db/migrate', __FILE__)
        # Helper migration - users table
        migrate File.expand_path('../support/migrations', __FILE__)
      end if tables.empty?

      # (tables - ['schema_migrations']).map do |table|
      #   table_count = execute("SELECT COUNT(*) FROM #{table}").first.first
      #   execute "TRUNCATE #{table}" unless table_count == 0
      # end
    end
  end

  config.before(:each) do
    Transaction.start
  end

  config.after(:each) do
    Transaction.clean
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
simple_roles-0.0.11 spec/spec_helper.rb
simple_roles-0.0.10 spec/spec_helper.rb
simple_roles-0.0.9 spec/spec_helper.rb
simple_roles-0.0.8 spec/spec_helper.rb
simple_roles-0.0.7 spec/spec_helper.rb