mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix adapter_test.rb to make no assumptions about the database name
This commit is contained in:
parent
3b7d100b51
commit
523c7c2330
2 changed files with 16 additions and 4 deletions
|
@ -43,7 +43,7 @@ class AdapterTest < ActiveRecord::TestCase
|
|||
|
||||
def test_current_database
|
||||
if @connection.respond_to?(:current_database)
|
||||
assert_equal ENV['ARUNIT_DB_NAME'] || "activerecord_unittest", @connection.current_database
|
||||
assert_equal ARTest.connection_config['arunit']['database'], @connection.current_database
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -68,7 +68,12 @@ class AdapterTest < ActiveRecord::TestCase
|
|||
begin
|
||||
assert_nothing_raised do
|
||||
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['arunit'].except(:database))
|
||||
ActiveRecord::Base.connection.execute "SELECT activerecord_unittest.pirates.*, activerecord_unittest2.courses.* FROM activerecord_unittest.pirates, activerecord_unittest2.courses"
|
||||
|
||||
config = ARTest.connection_config
|
||||
ActiveRecord::Base.connection.execute(
|
||||
"SELECT #{config['arunit']['database']}.pirates.*, #{config['arunit2']['database']}.courses.* " \
|
||||
"FROM #{config['arunit']['database']}.pirates, #{config['arunit2']['database']}.courses"
|
||||
)
|
||||
end
|
||||
ensure
|
||||
ActiveRecord::Base.establish_connection 'arunit'
|
||||
|
|
|
@ -2,11 +2,18 @@ require 'logger'
|
|||
require_dependency 'models/course'
|
||||
|
||||
module ARTest
|
||||
def self.connection_name
|
||||
ENV['ARCONN'] || config['default_connection']
|
||||
end
|
||||
|
||||
def self.connection_config
|
||||
config['connections'][connection_name]
|
||||
end
|
||||
|
||||
def self.connect
|
||||
connection_name = ENV['ARCONN'] || config['default_connection']
|
||||
puts "Using #{connection_name}"
|
||||
ActiveRecord::Base.logger = Logger.new("debug.log")
|
||||
ActiveRecord::Base.configurations = config['connections'][connection_name]
|
||||
ActiveRecord::Base.configurations = connection_config
|
||||
ActiveRecord::Base.establish_connection 'arunit'
|
||||
Course.establish_connection 'arunit2'
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue