2017-07-09 13:41:28 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 12:26:20 -04:00
|
|
|
require "fileutils"
|
|
|
|
require "pathname"
|
2019-10-05 20:37:23 -04:00
|
|
|
require "active_support/configuration_file"
|
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
|
|
|
|
2019-10-05 20:37:23 -04:00
|
|
|
expand_config ActiveSupport::ConfigurationFile.parse(config_file)
|
2018-12-10 16:22:56 -05:00
|
|
|
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
|