From 253bb6b9260938ed673e2c0059d729cffff4a523 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Sat, 4 Jun 2011 23:19:17 +0100 Subject: Refactor Active Record test connection setup. Please see the RUNNING_UNIT_TESTS file for details, but essentially you can now configure things in test/config.yml. You can also run tests directly via the command line, e.g. ruby path/to/test.rb (no rake needed, uses default db connection from test/config.yml). This will help us fix the CI by enabling us to isolate the different Rails versions to different databases. --- activerecord/test/support/config.rb | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 activerecord/test/support/config.rb (limited to 'activerecord/test/support/config.rb') diff --git a/activerecord/test/support/config.rb b/activerecord/test/support/config.rb new file mode 100644 index 0000000000..2760d88d20 --- /dev/null +++ b/activerecord/test/support/config.rb @@ -0,0 +1,39 @@ +require 'yaml' +require 'erubis' +require 'fileutils' + +module ARTest + class << self + def config + @config ||= read_config + end + + private + + def read_config + unless File.exist?(TEST_ROOT + '/config.yml') + FileUtils.cp TEST_ROOT + '/config.example.yml', TEST_ROOT + '/config.yml' + end + + raw = File.read(TEST_ROOT + '/config.yml') + erb = Erubis::Eruby.new(raw) + expand_config(YAML.parse(erb.result(binding)).transform) + end + + def expand_config(config) + config['connections'].each do |adapter, connection| + dbs = [['arunit', 'activerecord_unittest'], ['arunit2', '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 + end +end -- cgit v1.2.3