module ARTest

Public Class Methods

config() click to toggle source
# File activerecord/test/support/config.rb, line 10
def config
  @config ||= read_config
end
connect() click to toggle source
# File activerecord/test/support/connection.rb, line 21
def self.connect
  puts "Using #{connection_name}"
  ActiveRecord::Base.logger = ActiveSupport::Logger.new("debug.log", 0, 100 * 1024 * 1024)
  ActiveRecord::Base.configurations = connection_config
  ActiveRecord::Base.establish_connection :arunit
  ARUnit2Model.establish_connection :arunit2
end
connection_config() click to toggle source
# File activerecord/test/support/connection.rb, line 14
def self.connection_config
  config.fetch("connections").fetch(connection_name) do
    puts "Connection #{connection_name.inspect} not found. Available connections: #{config['connections'].keys.join(', ')}"
    exit 1
  end
end
connection_name() click to toggle source
# File activerecord/test/support/connection.rb, line 10
def self.connection_name
  ENV["ARCONN"] || config["default_connection"]
end

Private Class Methods

config_file() click to toggle source
# File activerecord/test/support/config.rb, line 16
def config_file
  Pathname.new(ENV["ARCONFIG"] || TEST_ROOT + "/config.yml")
end
expand_config(config) click to toggle source
# File activerecord/test/support/config.rb, line 29
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
  end

  config
end
read_config() click to toggle source
# File activerecord/test/support/config.rb, line 20
def read_config
  unless config_file.exist?
    FileUtils.cp TEST_ROOT + "/config.example.yml", config_file
  end

  erb = ERB.new(config_file.read)
  expand_config(YAML.parse(erb.result(binding)).transform)
end