2011-06-04 18:19:17 -04:00
|
|
|
require 'yaml'
|
|
|
|
require 'erubis'
|
|
|
|
require 'fileutils'
|
2011-06-17 09:55:34 -04:00
|
|
|
require 'pathname'
|
2011-06-04 18:19:17 -04:00
|
|
|
|
|
|
|
module ARTest
|
|
|
|
class << self
|
|
|
|
def config
|
|
|
|
@config ||= read_config
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2011-06-12 14:08:16 -04:00
|
|
|
def config_file
|
|
|
|
Pathname.new(ENV['ARCONFIG'] || TEST_ROOT + '/config.yml')
|
|
|
|
end
|
|
|
|
|
2011-06-04 18:19:17 -04:00
|
|
|
def read_config
|
2011-06-12 14:08:16 -04:00
|
|
|
unless config_file.exist?
|
|
|
|
FileUtils.cp TEST_ROOT + '/config.example.yml', config_file
|
2011-06-04 18:19:17 -04:00
|
|
|
end
|
|
|
|
|
2011-06-12 14:08:16 -04:00
|
|
|
erb = Erubis::Eruby.new(config_file.read)
|
2011-06-04 18:19:17 -04:00
|
|
|
expand_config(YAML.parse(erb.result(binding)).transform)
|
|
|
|
end
|
|
|
|
|
|
|
|
def expand_config(config)
|
|
|
|
config['connections'].each do |adapter, connection|
|
2011-06-05 06:20:06 -04:00
|
|
|
dbs = [['arunit', 'activerecord_unittest'], ['arunit2', 'activerecord_unittest2']]
|
2011-06-04 18:19:17 -04:00
|
|
|
dbs.each do |name, dbname|
|
|
|
|
unless connection[name].is_a?(Hash)
|
|
|
|
connection[name] = { 'database' => connection[name] }
|
|
|
|
end
|
|
|
|
|
|
|
|
connection[name]['database'] ||= dbname
|
|
|
|
connection[name]['adapter'] ||= adapter
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
config
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|