Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix adapter_test.rb to make no assumptions about the database name

  • Loading branch information...
commit 523c7c233052a3f3e1ac99adad4aad66f33a9364 1 parent 3b7d100
@jonleighton jonleighton authored
View
9 activerecord/test/cases/adapter_test.rb
@@ -43,7 +43,7 @@ def test_indexes
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 @@ def test_not_specifying_database_name_for_cross_database_selects
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'
View
11 activerecord/test/support/connection.rb
@@ -2,11 +2,18 @@
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
Please sign in to comment.
Something went wrong with that request. Please try again.