diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2006-07-10 19:27:04 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2006-07-10 19:27:04 +0000 |
commit | 41f3b7ab56d1c90454c0c5db6cbf3e8982ac0f34 (patch) | |
tree | b580ea8b2672442652bb9c3c527809da570b03eb /activerecord | |
parent | 5ad4f1ad94c71bfbb6aacc8a27addc4a0de54506 (diff) | |
download | rails-41f3b7ab56d1c90454c0c5db6cbf3e8982ac0f34.tar.gz rails-41f3b7ab56d1c90454c0c5db6cbf3e8982ac0f34.tar.bz2 rails-41f3b7ab56d1c90454c0c5db6cbf3e8982ac0f34.zip |
Test connections use AR::Base.configurations. References #5497.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4602 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
12 files changed, 174 insertions, 177 deletions
diff --git a/activerecord/test/connections/native_db2/connection.rb b/activerecord/test/connections/native_db2/connection.rb index aa736ccc85..921ac28109 100644 --- a/activerecord/test/connections/native_db2/connection.rb +++ b/activerecord/test/connections/native_db2/connection.rb @@ -4,21 +4,22 @@ require 'logger' ActiveRecord::Base.logger = Logger.new("debug.log") -db1 = 'arunit' -db2 = 'arunit2' +ActiveRecord::Base.configurations = { + 'arunit' => { + :adapter => 'db2', + :host => 'localhost', + :username => 'arunit', + :password => 'arunit', + :database => 'arunit' + }, + 'arunit2' => { + :adapter => 'db2', + :host => 'localhost', + :username => 'arunit', + :password => 'arunit', + :database => 'arunit2' + } +} -ActiveRecord::Base.establish_connection( - :adapter => "db2", - :host => "localhost", - :username => "arunit", - :password => "arunit", - :database => db1 -) - -Course.establish_connection( - :adapter => "db2", - :host => "localhost", - :username => "arunit2", - :password => "arunit2", - :database => db2 -) +ActiveRecord::Base.establish_connection 'arunit' +Course.establish_connection 'arunit2' diff --git a/activerecord/test/connections/native_firebird/connection.rb b/activerecord/test/connections/native_firebird/connection.rb index b7d47940f7..c198a99869 100644 --- a/activerecord/test/connections/native_firebird/connection.rb +++ b/activerecord/test/connections/native_firebird/connection.rb @@ -4,22 +4,23 @@ require 'logger' ActiveRecord::Base.logger = Logger.new("debug.log") -db1 = 'activerecord_unittest' -db2 = 'activerecord_unittest2' +ActiveRecord::Base.configurations = { + 'arunit' => { + :adapter => 'firebird', + :host => 'localhost', + :username => 'rails', + :password => 'rails', + :database => 'activerecord_unittest', + :charset => 'UTF8' + }, + 'arunit2' => { + :adapter => 'firebird', + :host => 'localhost', + :username => 'rails', + :password => 'rails', + :database => 'activerecord_unittest2' + } +} -ActiveRecord::Base.establish_connection( - :adapter => "firebird", - :host => "localhost", - :username => "rails", - :password => "rails", - :database => db1, - :charset => "UTF8" -) - -Course.establish_connection( - :adapter => "firebird", - :host => "localhost", - :username => "rails", - :password => "rails", - :database => db2 -) +ActiveRecord::Base.establish_connection 'arunit' +Course.establish_connection 'arunit2' diff --git a/activerecord/test/connections/native_frontbase/connection.rb b/activerecord/test/connections/native_frontbase/connection.rb index e3d1d5b1e1..11dd8d275d 100644 --- a/activerecord/test/connections/native_frontbase/connection.rb +++ b/activerecord/test/connections/native_frontbase/connection.rb @@ -4,23 +4,24 @@ require 'logger' ActiveRecord::Base.logger = Logger.new("debug.log") -db1 = 'activerecord_unittest' -db2 = 'activerecord_unittest2' +ActiveRecord::Base.configurations = { + 'arunit' => { + :adapter => 'frontbase', + :host => 'localhost', + :username => 'rails', + :password => '', + :database => 'activerecord_unittest', + :session_name => "unittest-#{$$}" + }, + 'arunit2' => { + :adapter => 'frontbase', + :host => 'localhost', + :username => 'rails', + :password => '', + :database => 'activerecord_unittest2', + :session_name => "unittest-#{$$}" + } +} -ActiveRecord::Base.establish_connection( - :adapter => "frontbase", - :host => "localhost", - :username => "rails", - :password => "", - :database => db1, - :session_name => "unittest-#{$$}" -) - -Course.establish_connection( - :adapter => "frontbase", - :host => "localhost", - :username => "rails", - :password => "", - :database => db2, - :session_name => "unittest-#{$$}" -) +ActiveRecord::Base.establish_connection 'arunit' +Course.establish_connection 'arunit2' diff --git a/activerecord/test/connections/native_mysql/connection.rb b/activerecord/test/connections/native_mysql/connection.rb index b665a6b449..9a91a75cac 100644 --- a/activerecord/test/connections/native_mysql/connection.rb +++ b/activerecord/test/connections/native_mysql/connection.rb @@ -4,18 +4,19 @@ require 'logger' ActiveRecord::Base.logger = Logger.new("debug.log") -db1 = 'activerecord_unittest' -db2 = 'activerecord_unittest2' +ActiveRecord::Base.configurations = { + 'arunit' => { + :adapter => 'mysql', + :username => 'rails', + :encoding => 'utf8', + :database => 'activerecord_unittest', + }, + 'arunit2' => { + :adapter => 'mysql', + :username => 'rails', + :database => 'activerecord_unittest2' + } +} -ActiveRecord::Base.establish_connection( - :adapter => "mysql", - :username => "rails", - :encoding => "utf8", - :database => db1 -) - -Course.establish_connection( - :adapter => "mysql", - :username => "rails", - :database => db2 -) +ActiveRecord::Base.establish_connection 'arunit' +Course.establish_connection 'arunit2' diff --git a/activerecord/test/connections/native_openbase/connection.rb b/activerecord/test/connections/native_openbase/connection.rb index 01a2ffe646..deaa73d347 100644 --- a/activerecord/test/connections/native_openbase/connection.rb +++ b/activerecord/test/connections/native_openbase/connection.rb @@ -4,19 +4,18 @@ require 'logger' ActiveRecord::Base.logger = Logger.new("debug.log") -db1 = 'activerecord_unittest' -db2 = 'activerecord_unittest2' +ActiveRecord::Base.configurations = { + 'arunit' => { + :adapter => 'openbase', + :username => 'admin', + :database => 'activerecord_unittest', + }, + 'arunit2' => { + :adapter => 'openbase', + :username => 'admin', + :database => 'activerecord_unittest2' + } +} -ActiveRecord::Base.establish_connection( - :adapter => "openbase", - :username => "admin", - :password => "", - :database => db1 -) - -Course.establish_connection( - :adapter => "openbase", - :username => "admin", - :password => "", - :database => db2 -) +ActiveRecord::Base.establish_connection 'arunit' +Course.establish_connection 'arunit2' diff --git a/activerecord/test/connections/native_oracle/connection.rb b/activerecord/test/connections/native_oracle/connection.rb index b0d9696a70..e127e36675 100644 --- a/activerecord/test/connections/native_oracle/connection.rb +++ b/activerecord/test/connections/native_oracle/connection.rb @@ -8,16 +8,20 @@ ActiveRecord::Base.logger.level = Logger::WARN # Set these to your database connection strings db = ENV['ARUNIT_DB'] || 'activerecord_unittest' -ActiveRecord::Base.establish_connection( - :adapter => 'oracle', - :username => 'arunit', - :password => 'arunit', - :database => db -) +ActiveRecord::Base.configurations = { + 'arunit' => { + :adapter => 'oracle', + :username => 'arunit', + :password => 'arunit', + :database => db, + }, + 'arunit2' => { + :adapter => 'oracle', + :username => 'arunit2', + :password => 'arunit2', + :database => db + } +} -Course.establish_connection( - :adapter => 'oracle', - :username => 'arunit2', - :password => 'arunit2', - :database => db -) +ActiveRecord::Base.establish_connection 'arunit' +Course.establish_connection 'arunit2' diff --git a/activerecord/test/connections/native_postgresql/connection.rb b/activerecord/test/connections/native_postgresql/connection.rb index 1bdff730b1..a75fc6e2ae 100644 --- a/activerecord/test/connections/native_postgresql/connection.rb +++ b/activerecord/test/connections/native_postgresql/connection.rb @@ -4,21 +4,20 @@ require 'logger' ActiveRecord::Base.logger = Logger.new("debug.log") -db1 = 'activerecord_unittest' -db2 = 'activerecord_unittest2' +ActiveRecord::Base.configurations = { + 'arunit' => { + :adapter => 'postgresql', + :username => 'postgres', + :database => 'activerecord_unittest', + :min_messages => 'warning' + }, + 'arunit2' => { + :adapter => 'postgresql', + :username => 'postgres', + :database => 'activerecord_unittest2', + :min_messages => 'warning' + } +} -ActiveRecord::Base.establish_connection( - :adapter => "postgresql", - :username => "postgres", - :password => "postgres", - :database => db1, - :min_messages => "warning" -) - -Course.establish_connection( - :adapter => "postgresql", - :username => "postgres", - :password => "postgres", - :database => db2, - :min_messages => "warning" -) +ActiveRecord::Base.establish_connection 'arunit' +Course.establish_connection 'arunit2' diff --git a/activerecord/test/connections/native_sqlite/connection.rb b/activerecord/test/connections/native_sqlite/connection.rb index b714e1782a..14ae999023 100644 --- a/activerecord/test/connections/native_sqlite/connection.rb +++ b/activerecord/test/connections/native_sqlite/connection.rb @@ -11,14 +11,13 @@ sqlite_test_db = "#{BASE_DIR}/fixture_database.sqlite" sqlite_test_db2 = "#{BASE_DIR}/fixture_database_2.sqlite" def make_connection(clazz, db_file, db_definitions_file) + ActiveRecord::Base.configurations = { clazz.name => { :adapter => 'sqlite', :database => db_file } } unless File.exist?(db_file) puts "SQLite database not found at #{db_file}. Rebuilding it." sqlite_command = %Q{sqlite #{db_file} "create table a (a integer); drop table a;"} puts "Executing '#{sqlite_command}'" raise SqliteError.new("Seems that there is no sqlite executable available") unless system(sqlite_command) - clazz.establish_connection( - :adapter => "sqlite", - :database => db_file) + clazz.establish_connection(clazz.name) script = File.read("#{BASE_DIR}/db_definitions/#{db_definitions_file}") # SQLite-Ruby has problems with semi-colon separated commands, so split and execute one at a time script.split(';').each do @@ -26,9 +25,7 @@ def make_connection(clazz, db_file, db_definitions_file) clazz.connection.execute(command) unless command.strip.empty? end else - clazz.establish_connection( - :adapter => "sqlite", - :database => db_file) + clazz.establish_connection(clazz.name) end end diff --git a/activerecord/test/connections/native_sqlite3/connection.rb b/activerecord/test/connections/native_sqlite3/connection.rb index 182ec6ba68..008ea686d6 100644 --- a/activerecord/test/connections/native_sqlite3/connection.rb +++ b/activerecord/test/connections/native_sqlite3/connection.rb @@ -11,14 +11,13 @@ sqlite_test_db = "#{BASE_DIR}/fixture_database.sqlite3" sqlite_test_db2 = "#{BASE_DIR}/fixture_database_2.sqlite3" def make_connection(clazz, db_file, db_definitions_file) + ActiveRecord::Base.configurations = { clazz.name => { :adapter => 'sqlite3', :database => db_file } } unless File.exist?(db_file) puts "SQLite3 database not found at #{db_file}. Rebuilding it." sqlite_command = %Q{sqlite3 #{db_file} "create table a (a integer); drop table a;"} puts "Executing '#{sqlite_command}'" raise SqliteError.new("Seems that there is no sqlite3 executable available") unless system(sqlite_command) - clazz.establish_connection( - :adapter => "sqlite3", - :database => db_file) + clazz.establish_connection(clazz.name) script = File.read("#{BASE_DIR}/db_definitions/#{db_definitions_file}") # SQLite-Ruby has problems with semi-colon separated commands, so split and execute one at a time script.split(';').each do @@ -26,9 +25,7 @@ def make_connection(clazz, db_file, db_definitions_file) clazz.connection.execute(command) unless command.strip.empty? end else - clazz.establish_connection( - :adapter => "sqlite3", - :database => db_file) + clazz.establish_connection(clazz.name) end end diff --git a/activerecord/test/connections/native_sqlserver/connection.rb b/activerecord/test/connections/native_sqlserver/connection.rb index 24658d7157..626a72b8d7 100644 --- a/activerecord/test/connections/native_sqlserver/connection.rb +++ b/activerecord/test/connections/native_sqlserver/connection.rb @@ -4,21 +4,20 @@ require 'logger' ActiveRecord::Base.logger = Logger.new("debug.log") -db1 = 'activerecord_unittest' -db2 = 'activerecord_unittest2' +ActiveRecord::Base.configurations = { + 'arunit' => { + :adapter => 'sqlserver', + :host => 'localhost', + :username => 'sa', + :database => 'activerecord_unittest' + }, + 'arunit2' => { + :adapter => 'sqlserver', + :host => 'localhost', + :username => 'sa', + :database => 'activerecord_unittest2' + } +} -ActiveRecord::Base.establish_connection( - :adapter => "sqlserver", - :host => "localhost", - :username => "sa", - :password => "", - :database => db1 -) - -Course.establish_connection( - :adapter => "sqlserver", - :host => "localhost", - :username => "sa", - :password => "", - :database => db2 -) +ActiveRecord::Base.establish_connection 'arunit' +Course.establish_connection 'arunit2' diff --git a/activerecord/test/connections/native_sqlserver_odbc/connection.rb b/activerecord/test/connections/native_sqlserver_odbc/connection.rb index 918be3eda7..41fd672ec0 100644 --- a/activerecord/test/connections/native_sqlserver_odbc/connection.rb +++ b/activerecord/test/connections/native_sqlserver_odbc/connection.rb @@ -4,23 +4,22 @@ require 'logger' ActiveRecord::Base.logger = Logger.new("debug.log") -dsn1 = 'activerecord_unittest' -dsn2 = 'activerecord_unittest2' +ActiveRecord::Base.configurations = { + 'arunit' => { + :adapter => 'sqlserver', + :mode => 'ODBC', + :host => 'localhost', + :username => 'sa', + :dsn => 'activerecord_unittest' + }, + 'arunit2' => { + :adapter => 'sqlserver', + :mode => 'ODBC', + :host => 'localhost', + :username => 'sa', + :dsn => 'activerecord_unittest2' + } +} -ActiveRecord::Base.establish_connection( - :adapter => "sqlserver", - :mode => "ODBC", - :host => "localhost", - :username => "sa", - :password => "", - :dsn => dsn1 -) - -Course.establish_connection( - :adapter => "sqlserver", - :mode => "ODBC", - :host => "localhost", - :username => "sa", - :password => "", - :dsn => dsn2 -) +ActiveRecord::Base.establish_connection 'arunit' +Course.establish_connection 'arunit2' diff --git a/activerecord/test/connections/native_sybase/connection.rb b/activerecord/test/connections/native_sybase/connection.rb index a3ecf85326..ec3e9ebfc3 100644 --- a/activerecord/test/connections/native_sybase/connection.rb +++ b/activerecord/test/connections/native_sybase/connection.rb @@ -4,21 +4,20 @@ require 'logger' ActiveRecord::Base.logger = Logger.new("debug.log") -db1 = 'activerecord_unittest' -db2 = 'activerecord_unittest2' +ActiveRecord::Base.configurations = { + 'arunit' => { + :adapter => 'sybase', + :host => 'database_ASE', + :username => 'sa', + :database => 'activerecord_unittest' + }, + 'arunit2' => { + :adapter => 'sybase', + :host => 'database_ASE', + :username => 'sa', + :database => 'activerecord_unittest2' + } +} -ActiveRecord::Base.establish_connection( - :adapter => "sybase", - :host => "database_ASE", - :username => "sa", - :password => "", - :database => db1 -) - -Course.establish_connection( - :adapter => "sybase", - :host => "database_ASE", - :username => "sa", - :password => "", - :database => db2 -) +ActiveRecord::Base.establish_connection 'arunit' +Course.establish_connection 'arunit2' |