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
|
|
|
|
|
2018-12-10 16:22:56 -05:00
|
|
|
def config_file
|
|
|
|
Pathname.new(ENV["ARCONFIG"] || TEST_ROOT + "/config.yml")
|
2011-06-04 18:19:17 -04:00
|
|
|
end
|
|
|
|
|
2018-12-10 16:22:56 -05:00
|
|
|
def read_config
|
|
|
|
unless config_file.exist?
|
|
|
|
FileUtils.cp TEST_ROOT + "/config.example.yml", config_file
|
|
|
|
end
|
2011-06-04 18:19:17 -04:00
|
|
|
|
2018-12-10 16:22:56 -05:00
|
|
|
erb = ERB.new(config_file.read)
|
|
|
|
expand_config(YAML.parse(erb.result(binding)).transform)
|
|
|
|
end
|
2011-06-04 18:19:17 -04:00
|
|
|
|
2018-12-10 16:22:56 -05:00
|
|
|
def expand_config(config)
|
|
|
|
config["connections"].each do |adapter, connection|
|
|
|
|
dbs = [["arunit", "activerecord_unittest"], ["arunit2", "activerecord_unittest2"],
|
|
|
|
["arunit_without_prepared_statements", "activerecord_unittest"]]
|
|
|
|
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
|
2011-06-04 18:19:17 -04:00
|
|
|
end
|
|
|
|
|
2018-12-10 16:22:56 -05:00
|
|
|
config
|
|
|
|
end
|
2011-06-04 18:19:17 -04:00
|
|
|
end
|
|
|
|
end
|