Sha256: 6a2d152ac3893cc7233115c67cd2312abec23d6e432a00ab0be59bad9f0fdc84

Contents?: true

Size: 1.33 KB

Versions: 2

Compression:

Stored size: 1.33 KB

Contents

# Require the DataMapper, and a Mock Adapter.
require File.dirname(__FILE__) + '/lib/data_mapper'
require File.dirname(__FILE__) + '/spec/mock_adapter'

adapter = ENV['ADAPTER'] || 'sqlite3'

configuration_options = {
  :adapter => adapter,
  :database =>  (ENV['DATABASE'] || 'data_mapper_1').dup
}

# Prepare the log path, and remove the existing spec.log
require 'fileutils'

if ENV['LOG_NAME']
  FileUtils::mkdir_p(File.dirname(__FILE__) + '/log')
  log_path = File.dirname(__FILE__) + "/log/#{ENV['LOG_NAME']}.log"
  FileUtils::rm log_path if File.exists?(log_path)

  configuration_options.merge!(:log_stream => log_path, :log_level => Logger::DEBUG)
end

case adapter
  when 'postgresql' then
    configuration_options[:username] = ENV['USERNAME'] || 'postgres'
  when 'mysql' then
    configuration_options[:username] = 'root'
  when 'sqlite3' then
    unless configuration_options[:database] == ':memory:'
      configuration_options[:database] << '.db'
    end
end

load_models = lambda do
  Dir[File.dirname(__FILE__) + '/spec/models/*.rb'].sort.each { |path| load path }
end

DataMapper::Database.setup(configuration_options)
DataMapper::Database.setup(:mock, :adapter => MockAdapter)

[:default, :mock].each { |name| database(name) { load_models.call } }

# Reset the test database.
DataMapper::Base.auto_migrate! unless ENV['AUTO_MIGRATE'] == 'false'

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
datamapper-0.2.3 environment.rb
datamapper-0.2.4 environment.rb