Permalink
Browse files

Test connections use AR::Base.configurations. References #5497.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4602 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 5ad4f1a commit 41f3b7ab56d1c90454c0c5db6cbf3e8982ac0f34 @jeremy jeremy committed Jul 10, 2006
@@ -4,21 +4,22 @@
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'
@@ -4,22 +4,23 @@
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'
@@ -4,23 +4,24 @@
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'
@@ -4,18 +4,19 @@
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'
@@ -4,19 +4,18 @@
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'
@@ -8,16 +8,20 @@
# 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'
@@ -4,21 +4,20 @@
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'
@@ -11,24 +11,21 @@ class SqliteError < StandardError
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
|command|
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
@@ -11,24 +11,21 @@ class SqliteError < StandardError
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
|command|
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
@@ -4,21 +4,20 @@
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'
Oops, something went wrong.

0 comments on commit 41f3b7a

Please sign in to comment.