2017-07-09 13:41:28 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 12:26:20 -04:00
|
|
|
require "yaml"
|
2016-11-05 14:42:16 -04:00
|
|
|
require "erb"
|
2016-08-06 12:26:20 -04:00
|
|
|
require "fileutils"
|
|
|
|
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
|
2016-08-06 12:26:20 -04:00
|
|
|
Pathname.new(ENV["ARCONFIG"] || TEST_ROOT + "/config.yml")
|
2011-06-12 14:08:16 -04:00
|
|
|
end
|
|
|
|
|
2011-06-04 18:19:17 -04:00
|
|
|
def read_config
|
2011-06-12 14:08:16 -04:00
|
|
|
unless config_file.exist?
|
2016-08-06 12:26:20 -04:00
|
|
|
FileUtils.cp TEST_ROOT + "/config.example.yml", config_file
|
2011-06-04 18:19:17 -04:00
|
|
|
end
|
|
|
|
|
2016-11-05 14:42:16 -04:00
|
|
|
erb = ERB.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)
|
2016-08-06 12:26:20 -04:00
|
|
|
config["connections"].each do |adapter, connection|
|
2016-11-19 11:22:52 -05:00
|
|
|
dbs = [["arunit", "activerecord_unittest"], ["arunit2", "activerecord_unittest2"],
|
2016-11-19 15:47:08 -05:00
|
|
|
["arunit_without_prepared_statements", "activerecord_unittest"]]
|
2011-06-04 18:19:17 -04:00
|
|
|
dbs.each do |name, dbname|
|
|
|
|
unless connection[name].is_a?(Hash)
|
2016-08-06 12:26:20 -04:00
|
|
|
connection[name] = { "database" => connection[name] }
|
2011-06-04 18:19:17 -04:00
|
|
|
end
|
|
|
|
|
2016-08-06 12:26:20 -04:00
|
|
|
connection[name]["database"] ||= dbname
|
|
|
|
connection[name]["adapter"] ||= adapter
|
2011-06-04 18:19:17 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
config
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|