Sha256: 55812bd57baec4f7c0b64d431030db5708648d89f9e1662ff26f70952239cf74

Contents?: true

Size: 1.62 KB

Versions: 2

Compression:

Stored size: 1.62 KB

Contents

# encoding: utf-8
require 'rubygems'
require 'rspec'
require 'mongoid'
require 'mongoid_max_denormalize'

# Are we in presence of Mongoid 3
def mongoid3
  Mongoid::VERSION =~ /\A3\./
end

# When testing locally we use the database named mongoid_max_denormalize_test.
# However when tests are running in parallel on Travis we need to use different
# database names for each process running since we do not have transactions and
# want a clean slate before each spec run.
def database_name
  ENV["CI"] ? "mongoid_max_denormalize_#{Process.pid}" : "mongoid_max_denormalize_test"
end

# Logger
if mongoid3 && !ENV["CI"]
  Moped.logger = Logger.new("log/moped-test.log")
  Moped.logger.level = Logger::DEBUG
end

Mongoid.configure do |config|
  if mongoid3
    config.connect_to(database_name)
  else
    database = Mongo::Connection.new("127.0.0.1", 27017).db(database_name)
    database.add_user("mongoid", "test")
    config.master = database
    config.logger = nil
  end
end


RSpec.configure do |config|

  config.before(:suite) do
    puts "#\n# Mongoid #{Mongoid::VERSION}\n#"
  end

  # Drop all collections and clear the identity map before each spec.
  config.before(:each) do
    Moped.logger.info("\n  ### " << example.full_description) if mongoid3 && !ENV["CI"]

    Mongoid.purge!
    Mongoid::IdentityMap.clear
  end

  # On travis we are creating many different databases on each test run. We
  # drop the database after the suite.
  config.after(:suite) do
    if ENV["CI"]
      if mongoid3
        Mongoid::Threaded.sessions[:default].drop
      else
        Mongoid.master.connection.drop_database(database_name)
      end
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mongoid_max_denormalize-0.0.7 spec/spec_helper.rb
mongoid_max_denormalize-0.0.6 spec/spec_helper.rb