aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/.gitignore1
-rw-r--r--activerecord/test/cases/adapter_test.rb9
-rw-r--r--activerecord/test/cases/adapters/mysql/quoting_test.rb1
-rw-r--r--activerecord/test/cases/adapters/postgresql/timestamp_test.rb2
-rw-r--r--activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb2
-rw-r--r--activerecord/test/cases/fixtures/file_test.rb2
-rw-r--r--activerecord/test/cases/helper.rb18
-rw-r--r--activerecord/test/cases/i18n_test.rb1
-rw-r--r--activerecord/test/cases/identity_map_test.rb2
-rw-r--r--activerecord/test/cases/named_scope_test.rb8
-rw-r--r--activerecord/test/cases/schema_dumper_test.rb1
-rw-r--r--activerecord/test/config.example.yml136
-rw-r--r--activerecord/test/connections/jdbc_jdbcderby/connection.rb18
-rw-r--r--activerecord/test/connections/jdbc_jdbch2/connection.rb18
-rw-r--r--activerecord/test/connections/jdbc_jdbchsqldb/connection.rb18
-rw-r--r--activerecord/test/connections/jdbc_jdbcmysql/connection.rb26
-rw-r--r--activerecord/test/connections/jdbc_jdbcpostgresql/connection.rb26
-rw-r--r--activerecord/test/connections/jdbc_jdbcsqlite3/connection.rb25
-rw-r--r--activerecord/test/connections/native_db2/connection.rb25
-rw-r--r--activerecord/test/connections/native_firebird/connection.rb26
-rw-r--r--activerecord/test/connections/native_frontbase/connection.rb27
-rw-r--r--activerecord/test/connections/native_mysql/connection.rb25
-rw-r--r--activerecord/test/connections/native_mysql2/connection.rb25
-rw-r--r--activerecord/test/connections/native_openbase/connection.rb21
-rw-r--r--activerecord/test/connections/native_oracle/connection.rb35
-rw-r--r--activerecord/test/connections/native_postgresql/connection.rb21
-rw-r--r--activerecord/test/connections/native_sqlite3/connection.rb16
-rw-r--r--activerecord/test/connections/native_sqlite3_mem/connection.rb19
-rw-r--r--activerecord/test/connections/native_sybase/connection.rb23
-rw-r--r--activerecord/test/models/comment.rb3
-rw-r--r--activerecord/test/models/post.rb4
-rw-r--r--activerecord/test/support/config.rb39
-rw-r--r--activerecord/test/support/connection.rb20
33 files changed, 228 insertions, 415 deletions
diff --git a/activerecord/test/.gitignore b/activerecord/test/.gitignore
new file mode 100644
index 0000000000..a0ec5967dd
--- /dev/null
+++ b/activerecord/test/.gitignore
@@ -0,0 +1 @@
+/config.yml
diff --git a/activerecord/test/cases/adapter_test.rb b/activerecord/test/cases/adapter_test.rb
index 49b2e945c3..07de544868 100644
--- a/activerecord/test/cases/adapter_test.rb
+++ b/activerecord/test/cases/adapter_test.rb
@@ -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'
diff --git a/activerecord/test/cases/adapters/mysql/quoting_test.rb b/activerecord/test/cases/adapters/mysql/quoting_test.rb
index 9673e2bb46..3d1330efb8 100644
--- a/activerecord/test/cases/adapters/mysql/quoting_test.rb
+++ b/activerecord/test/cases/adapters/mysql/quoting_test.rb
@@ -23,4 +23,3 @@ module ActiveRecord
end
end
end
-
diff --git a/activerecord/test/cases/adapters/postgresql/timestamp_test.rb b/activerecord/test/cases/adapters/postgresql/timestamp_test.rb
index 337f43c421..fb4616dc76 100644
--- a/activerecord/test/cases/adapters/postgresql/timestamp_test.rb
+++ b/activerecord/test/cases/adapters/postgresql/timestamp_test.rb
@@ -1,4 +1,4 @@
-require 'cases/helper'
+require File.expand_path('../../../helper', __FILE__)
require 'models/developer'
class TimestampTest < ActiveRecord::TestCase
diff --git a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
index e5735988d0..d8d2a113ff 100644
--- a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
@@ -100,7 +100,7 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
assert_equal 'c1', record[0]
assert_equal 't1', record[1]
end
-
+
def test_proper_usage_of_primary_keys_and_join_table
setup_data_for_habtm_case
diff --git a/activerecord/test/cases/fixtures/file_test.rb b/activerecord/test/cases/fixtures/file_test.rb
index 8dbf92ae9a..9ff4455394 100644
--- a/activerecord/test/cases/fixtures/file_test.rb
+++ b/activerecord/test/cases/fixtures/file_test.rb
@@ -1,4 +1,4 @@
-require "cases/helper"
+require File.expand_path('../../helper', __FILE__)
require 'tempfile'
module ActiveRecord
diff --git a/activerecord/test/cases/helper.rb b/activerecord/test/cases/helper.rb
index 9644ac1b02..110f6b97c6 100644
--- a/activerecord/test/cases/helper.rb
+++ b/activerecord/test/cases/helper.rb
@@ -1,8 +1,5 @@
require File.expand_path('../../../../load_paths', __FILE__)
-lib = File.expand_path("#{File.dirname(__FILE__)}/../../lib")
-$:.unshift(lib) unless $:.include?('lib') || $:.include?(lib)
-
require 'config'
require 'test/unit'
@@ -11,14 +8,13 @@ require 'mocha'
require 'active_record'
require 'active_support/dependencies'
-begin
- require 'connection'
-rescue LoadError
- # If we cannot load connection we assume that driver was not loaded for this test case, so we load sqlite3 as default one.
- # This allows for running separate test cases by simply running test file.
- connection_type = defined?(JRUBY_VERSION) ? 'jdbc' : 'native'
- require "test/connections/#{connection_type}_sqlite3/connection"
-end
+
+require 'support/config'
+require 'support/connection'
+
+ARTest.connect
+
+# TODO: Move all these random hacks into the ARTest namespace and into the support/ dir
# Show backtraces for deprecated behavior for quicker cleanup.
ActiveSupport::Deprecation.debug = true
diff --git a/activerecord/test/cases/i18n_test.rb b/activerecord/test/cases/i18n_test.rb
index 469f513e68..a428f1d87b 100644
--- a/activerecord/test/cases/i18n_test.rb
+++ b/activerecord/test/cases/i18n_test.rb
@@ -43,4 +43,3 @@ class ActiveRecordI18nTests < ActiveRecord::TestCase
assert_equal 'topic model', Reply.model_name.human
end
end
-
diff --git a/activerecord/test/cases/identity_map_test.rb b/activerecord/test/cases/identity_map_test.rb
index a0e16400d2..cd9c358799 100644
--- a/activerecord/test/cases/identity_map_test.rb
+++ b/activerecord/test/cases/identity_map_test.rb
@@ -140,7 +140,7 @@ class IdentityMapTest < ActiveRecord::TestCase
assert_not_same(p1, p2)
end
end
-
+
def test_inherited_with_type_attribute_without_identity_map
ActiveRecord::IdentityMap.without do
c = comments(:sub_special_comment)
diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb
index 34188e4915..2afe3c8f32 100644
--- a/activerecord/test/cases/named_scope_test.rb
+++ b/activerecord/test/cases/named_scope_test.rb
@@ -456,6 +456,14 @@ class NamedScopeTest < ActiveRecord::TestCase
end
end
+ def test_scopes_to_get_newest
+ post = posts(:welcome)
+ old_last_comment = post.comments.newest
+ new_comment = post.comments.create(:body => "My new comment")
+ assert_equal new_comment, post.comments.newest
+ assert_not_equal old_last_comment, post.comments.newest
+ end
+
def test_scopes_are_reset_on_association_reload
post = posts(:welcome)
diff --git a/activerecord/test/cases/schema_dumper_test.rb b/activerecord/test/cases/schema_dumper_test.rb
index e8f2f44189..4adecf8e83 100644
--- a/activerecord/test/cases/schema_dumper_test.rb
+++ b/activerecord/test/cases/schema_dumper_test.rb
@@ -230,4 +230,3 @@ class SchemaDumperTest < ActiveRecord::TestCase
assert_match %r{t.string[[:space:]]+"id",[[:space:]]+:null => false$}, match[2], "non-primary key id column not preserved"
end
end
-
diff --git a/activerecord/test/config.example.yml b/activerecord/test/config.example.yml
new file mode 100644
index 0000000000..8c1a45430e
--- /dev/null
+++ b/activerecord/test/config.example.yml
@@ -0,0 +1,136 @@
+default_connection: <%= defined?(JRUBY_VERSION) ? 'jdbcsqlite3' : 'sqlite3' %>
+
+connections:
+ jdbcderby:
+ arunit: activerecord_unittest
+ arunit2: activerecord_unittest2
+
+ jdbch2:
+ arunit: activerecord_unittest
+ arunit2: activerecord_unittest2
+
+ jdbchsqldb:
+ arunit: activerecord_unittest
+ arunit2: activerecord_unittest2
+
+ jdbcmysql:
+ arunit:
+ username: rails
+ encoding: utf8
+ arunit2:
+ username: rails
+ encoding: utf8
+
+ jdbcpostgresql:
+ arunit:
+ username: <%= ENV['user'] || 'rails' %>
+ arunit2:
+ username: <%= ENV['user'] || 'rails' %>
+
+ jdbcsqlite3:
+ arunit:
+ database: <%= FIXTURES_ROOT %>/fixture_database.sqlite3
+ timeout: 5000
+ arunit2:
+ database: <%= FIXTURES_ROOT %>/fixture_database_2.sqlite3
+ timeout: 5000
+
+ db2:
+ arunit:
+ host: localhost
+ username: arunit
+ password: arunit
+ database: arunit
+ arunit2:
+ host: localhost
+ username: arunit
+ password: arunit
+ database: arunit2
+
+ firebird:
+ arunit:
+ host: localhost
+ username: rails
+ password: rails
+ charset: UTF8
+ arunit2:
+ host: localhost
+ username: rails
+ password: rails
+ charset: UTF8
+
+ frontbase:
+ arunit:
+ host: localhost
+ username: rails
+ session_name: unittest-<%= $$ %>
+ arunit2:
+ host: localhost
+ username: rails
+ session_name: unittest-<%= $$ %>
+
+ mysql:
+ arunit:
+ username: rails
+ encoding: utf8
+ arunit2:
+ username: rails
+ encoding: utf8
+
+ mysql2:
+ arunit:
+ username: rails
+ encoding: utf8
+ arunit2:
+ username: rails
+ encoding: utf8
+
+ openbase:
+ arunit:
+ username: admin
+ arunit2:
+ username: admin
+
+ oracle:
+ arunit:
+ adapter: oracle_enhanced
+ database: <%= ENV['ARUNIT_DB_NAME'] || 'orcl' %>
+ username: <%= ENV['ARUNIT_USER_NAME'] || 'arunit' %>
+ password: <%= ENV['ARUNIT_PASSWORD'] || 'arunit' %>
+ emulate_oracle_adapter: true
+ arunit2:
+ adapter: oracle_enhanced
+ database: <%= ENV['ARUNIT_DB_NAME'] || 'orcl' %>
+ username: <%= ENV['ARUNIT2_USER_NAME'] || 'arunit2' %>
+ password: <%= ENV['ARUNIT2_PASSWORD'] || 'arunit2' %>
+ emulate_oracle_adapter: true
+
+ postgresql:
+ arunit:
+ min_messages: warning
+ arunit2:
+ min_messages: warning
+
+ sqlite3:
+ arunit:
+ database: <%= FIXTURES_ROOT %>/fixture_database.sqlite3
+ timeout: 5000
+ arunit2:
+ database: <%= FIXTURES_ROOT %>/fixture_database_2.sqlite3
+ timeout: 5000
+
+ sqlite3_mem:
+ arunit:
+ adapter: sqlite3
+ database: ':memory:'
+ arunit2:
+ adapter: sqlite3
+ database: ':memory:'
+
+ sybase:
+ arunit:
+ host: database_ASE
+ username: sa
+ arunit2:
+ host: database_ASE
+ username: sa
diff --git a/activerecord/test/connections/jdbc_jdbcderby/connection.rb b/activerecord/test/connections/jdbc_jdbcderby/connection.rb
deleted file mode 100644
index 222ef5db38..0000000000
--- a/activerecord/test/connections/jdbc_jdbcderby/connection.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-print "Using Derby via JRuby, activerecord-jdbc-adapter and activerecord-jdbcderby-adapter\n"
-require_dependency 'models/course'
-require 'logger'
-ActiveRecord::Base.logger = Logger.new("debug.log")
-
-ActiveRecord::Base.configurations = {
- 'arunit' => {
- :adapter => 'jdbcderby',
- :database => 'activerecord_unittest'
- },
- 'arunit2' => {
- :adapter => 'jdbcderby',
- :database => 'activerecord_unittest2'
- }
-}
-
-ActiveRecord::Base.establish_connection 'arunit'
-Course.establish_connection 'arunit2'
diff --git a/activerecord/test/connections/jdbc_jdbch2/connection.rb b/activerecord/test/connections/jdbc_jdbch2/connection.rb
deleted file mode 100644
index 9d2875e8e7..0000000000
--- a/activerecord/test/connections/jdbc_jdbch2/connection.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-print "Using H2 via JRuby, activerecord-jdbc-adapter and activerecord-jdbch2-adapter\n"
-require_dependency 'models/course'
-require 'logger'
-ActiveRecord::Base.logger = Logger.new("debug.log")
-
-ActiveRecord::Base.configurations = {
- 'arunit' => {
- :adapter => 'jdbch2',
- :database => 'activerecord_unittest'
- },
- 'arunit2' => {
- :adapter => 'jdbch2',
- :database => 'activerecord_unittest2'
- }
-}
-
-ActiveRecord::Base.establish_connection 'arunit'
-Course.establish_connection 'arunit2'
diff --git a/activerecord/test/connections/jdbc_jdbchsqldb/connection.rb b/activerecord/test/connections/jdbc_jdbchsqldb/connection.rb
deleted file mode 100644
index fa943c2c76..0000000000
--- a/activerecord/test/connections/jdbc_jdbchsqldb/connection.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-print "Using HSQLDB via JRuby, activerecord-jdbc-adapter and activerecord-jdbchsqldb-adapter\n"
-require_dependency 'models/course'
-require 'logger'
-ActiveRecord::Base.logger = Logger.new("debug.log")
-
-ActiveRecord::Base.configurations = {
- 'arunit' => {
- :adapter => 'jdbchsqldb',
- :database => 'activerecord_unittest'
- },
- 'arunit2' => {
- :adapter => 'jdbchsqldb',
- :database => 'activerecord_unittest2'
- }
-}
-
-ActiveRecord::Base.establish_connection 'arunit'
-Course.establish_connection 'arunit2'
diff --git a/activerecord/test/connections/jdbc_jdbcmysql/connection.rb b/activerecord/test/connections/jdbc_jdbcmysql/connection.rb
deleted file mode 100644
index e2517a50eb..0000000000
--- a/activerecord/test/connections/jdbc_jdbcmysql/connection.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-print "Using MySQL via JRuby, activerecord-jdbc-adapter and activerecord-jdbcmysql-adapter\n"
-require_dependency 'models/course'
-require 'logger'
-
-ActiveRecord::Base.logger = Logger.new("debug.log")
-
-# GRANT ALL PRIVILEGES ON activerecord_unittest.* to 'rails'@'localhost';
-# GRANT ALL PRIVILEGES ON activerecord_unittest2.* to 'rails'@'localhost';
-
-ActiveRecord::Base.configurations = {
- 'arunit' => {
- :adapter => 'jdbcmysql',
- :username => 'rails',
- :encoding => 'utf8',
- :database => 'activerecord_unittest',
- },
- 'arunit2' => {
- :adapter => 'jdbcmysql',
- :username => 'rails',
- :database => 'activerecord_unittest2'
- }
-}
-
-ActiveRecord::Base.establish_connection 'arunit'
-Course.establish_connection 'arunit2'
-
diff --git a/activerecord/test/connections/jdbc_jdbcpostgresql/connection.rb b/activerecord/test/connections/jdbc_jdbcpostgresql/connection.rb
deleted file mode 100644
index 0685da4433..0000000000
--- a/activerecord/test/connections/jdbc_jdbcpostgresql/connection.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-print "Using Postgrsql via JRuby, activerecord-jdbc-adapter and activerecord-postgresql-adapter\n"
-require_dependency 'models/course'
-require 'logger'
-
-ActiveRecord::Base.logger = Logger.new("debug.log")
-
-# createuser rails --createdb --no-superuser --no-createrole
-# createdb -O rails activerecord_unittest
-# createdb -O rails activerecord_unittest2
-
-ActiveRecord::Base.configurations = {
- 'arunit' => {
- :adapter => 'jdbcpostgresql',
- :username => ENV['USER'] || 'rails',
- :database => 'activerecord_unittest'
- },
- 'arunit2' => {
- :adapter => 'jdbcpostgresql',
- :username => ENV['USER'] || 'rails',
- :database => 'activerecord_unittest2'
- }
-}
-
-ActiveRecord::Base.establish_connection 'arunit'
-Course.establish_connection 'arunit2'
-
diff --git a/activerecord/test/connections/jdbc_jdbcsqlite3/connection.rb b/activerecord/test/connections/jdbc_jdbcsqlite3/connection.rb
deleted file mode 100644
index 26d4676ff3..0000000000
--- a/activerecord/test/connections/jdbc_jdbcsqlite3/connection.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-print "Using SQLite3 via JRuby, activerecord-jdbc-adapter and activerecord-jdbcsqlite3-adapter\n"
-require_dependency 'models/course'
-require 'logger'
-ActiveRecord::Base.logger = Logger.new("debug.log")
-
-class SqliteError < StandardError
-end
-
-BASE_DIR = FIXTURES_ROOT
-sqlite_test_db = "#{BASE_DIR}/fixture_database.sqlite3"
-sqlite_test_db2 = "#{BASE_DIR}/fixture_database_2.sqlite3"
-
-def make_connection(clazz, db_file)
- ActiveRecord::Base.configurations = { clazz.name => { :adapter => 'jdbcsqlite3', :database => db_file, :timeout => 5000 } }
- 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)
- end
- clazz.establish_connection(clazz.name)
-end
-
-make_connection(ActiveRecord::Base, sqlite_test_db)
-make_connection(Course, sqlite_test_db2)
diff --git a/activerecord/test/connections/native_db2/connection.rb b/activerecord/test/connections/native_db2/connection.rb
deleted file mode 100644
index 324315d2c8..0000000000
--- a/activerecord/test/connections/native_db2/connection.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-print "Using native DB2\n"
-require_dependency 'models/course'
-require 'logger'
-
-ActiveRecord::Base.logger = Logger.new("debug.log")
-
-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 'arunit'
-Course.establish_connection 'arunit2'
diff --git a/activerecord/test/connections/native_firebird/connection.rb b/activerecord/test/connections/native_firebird/connection.rb
deleted file mode 100644
index 67a936ca97..0000000000
--- a/activerecord/test/connections/native_firebird/connection.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-print "Using native Firebird\n"
-require_dependency 'models/course'
-require 'logger'
-
-ActiveRecord::Base.logger = Logger.new("debug.log")
-
-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 'arunit'
-Course.establish_connection 'arunit2'
diff --git a/activerecord/test/connections/native_frontbase/connection.rb b/activerecord/test/connections/native_frontbase/connection.rb
deleted file mode 100644
index c01d864a8b..0000000000
--- a/activerecord/test/connections/native_frontbase/connection.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-puts 'Using native Frontbase'
-require_dependency 'models/course'
-require 'logger'
-
-ActiveRecord::Base.logger = Logger.new("debug.log")
-
-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 'arunit'
-Course.establish_connection 'arunit2'
diff --git a/activerecord/test/connections/native_mysql/connection.rb b/activerecord/test/connections/native_mysql/connection.rb
deleted file mode 100644
index 140e06d631..0000000000
--- a/activerecord/test/connections/native_mysql/connection.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-print "Using native MySQL\n"
-require_dependency 'models/course'
-require 'logger'
-
-ActiveRecord::Base.logger = Logger.new("debug.log")
-
-# GRANT ALL PRIVILEGES ON activerecord_unittest.* to 'rails'@'localhost';
-# GRANT ALL PRIVILEGES ON activerecord_unittest2.* to 'rails'@'localhost';
-
-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 'arunit'
-Course.establish_connection 'arunit2'
diff --git a/activerecord/test/connections/native_mysql2/connection.rb b/activerecord/test/connections/native_mysql2/connection.rb
deleted file mode 100644
index c6f198b1ac..0000000000
--- a/activerecord/test/connections/native_mysql2/connection.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-print "Using native Mysql2\n"
-require_dependency 'models/course'
-require 'logger'
-
-ActiveRecord::Base.logger = Logger.new("debug.log")
-
-# GRANT ALL PRIVILEGES ON activerecord_unittest.* to 'rails'@'localhost';
-# GRANT ALL PRIVILEGES ON activerecord_unittest2.* to 'rails'@'localhost';
-
-ActiveRecord::Base.configurations = {
- 'arunit' => {
- :adapter => 'mysql2',
- :username => 'rails',
- :encoding => 'utf8',
- :database => 'activerecord_unittest',
- },
- 'arunit2' => {
- :adapter => 'mysql2',
- :username => 'rails',
- :database => 'activerecord_unittest2'
- }
-}
-
-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
deleted file mode 100644
index 655cb9ca26..0000000000
--- a/activerecord/test/connections/native_openbase/connection.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-print "Using native OpenBase\n"
-require_dependency 'models/course'
-require 'logger'
-
-ActiveRecord::Base.logger = Logger.new("debug.log")
-
-ActiveRecord::Base.configurations = {
- 'arunit' => {
- :adapter => 'openbase',
- :username => 'admin',
- :database => 'activerecord_unittest',
- },
- 'arunit2' => {
- :adapter => 'openbase',
- :username => 'admin',
- :database => 'activerecord_unittest2'
- }
-}
-
-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
deleted file mode 100644
index 99f921879c..0000000000
--- a/activerecord/test/connections/native_oracle/connection.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-# uses oracle_enhanced adapter in ENV['ORACLE_ENHANCED_PATH'] or from github.com/rsim/oracle-enhanced.git
-require 'active_record/connection_adapters/oracle_enhanced_adapter'
-
-# otherwise failed with silence_warnings method missing exception
-require 'active_support/core_ext/kernel/reporting'
-
-print "Using Oracle\n"
-require_dependency 'models/course'
-require 'logger'
-
-ActiveRecord::Base.logger = Logger.new("debug.log")
-
-# Set these to your database connection strings
-ENV['ARUNIT_DB_NAME'] ||= 'orcl'
-
-ActiveRecord::Base.configurations = {
- 'arunit' => {
- :adapter => 'oracle_enhanced',
- :database => ENV['ARUNIT_DB_NAME'],
- :username => 'arunit',
- :password => 'arunit',
- :emulate_oracle_adapter => true
- },
- 'arunit2' => {
- :adapter => 'oracle_enhanced',
- :database => ENV['ARUNIT_DB_NAME'],
- :username => 'arunit2',
- :password => 'arunit2',
- :emulate_oracle_adapter => true
- }
-}
-
-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
deleted file mode 100644
index 3b5ff90003..0000000000
--- a/activerecord/test/connections/native_postgresql/connection.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-print "Using native PostgreSQL\n"
-require_dependency 'models/course'
-require 'logger'
-
-ActiveRecord::Base.logger = Logger.new("debug.log")
-
-ActiveRecord::Base.configurations = {
- 'arunit' => {
- :adapter => 'postgresql',
- :database => 'activerecord_unittest',
- :min_messages => 'warning'
- },
- 'arunit2' => {
- :adapter => 'postgresql',
- :database => 'activerecord_unittest2',
- :min_messages => 'warning'
- }
-}
-
-ActiveRecord::Base.establish_connection 'arunit'
-Course.establish_connection 'arunit2'
diff --git a/activerecord/test/connections/native_sqlite3/connection.rb b/activerecord/test/connections/native_sqlite3/connection.rb
deleted file mode 100644
index c2aff5551f..0000000000
--- a/activerecord/test/connections/native_sqlite3/connection.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-print "Using native SQLite3\n"
-require_dependency 'models/course'
-require 'logger'
-ActiveRecord::Base.logger = Logger.new("debug.log")
-
-BASE_DIR = FIXTURES_ROOT
-sqlite_test_db = "#{BASE_DIR}/fixture_database.sqlite3"
-sqlite_test_db2 = "#{BASE_DIR}/fixture_database_2.sqlite3"
-
-def make_connection(clazz, db_file)
- ActiveRecord::Base.configurations = { clazz.name => { :adapter => 'sqlite3', :database => db_file, :timeout => 5000 } }
- clazz.establish_connection(clazz.name)
-end
-
-make_connection(ActiveRecord::Base, sqlite_test_db)
-make_connection(Course, sqlite_test_db2)
diff --git a/activerecord/test/connections/native_sqlite3_mem/connection.rb b/activerecord/test/connections/native_sqlite3_mem/connection.rb
deleted file mode 100644
index 14e10900d1..0000000000
--- a/activerecord/test/connections/native_sqlite3_mem/connection.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# This file connects to an in-memory SQLite3 database, which is a very fast way to run the tests.
-# The downside is that disconnect from the database results in the database effectively being
-# wiped. For this reason, pooled_connections_test.rb is disabled when using an in-memory database.
-
-print "Using native SQLite3 (in memory)\n"
-require_dependency 'models/course'
-require 'logger'
-ActiveRecord::Base.logger = Logger.new("debug.log")
-
-class SqliteError < StandardError
-end
-
-def make_connection(clazz)
- ActiveRecord::Base.configurations = { clazz.name => { :adapter => 'sqlite3', :database => ':memory:' } }
- clazz.establish_connection(clazz.name)
-end
-
-make_connection(ActiveRecord::Base)
-make_connection(Course)
diff --git a/activerecord/test/connections/native_sybase/connection.rb b/activerecord/test/connections/native_sybase/connection.rb
deleted file mode 100644
index 3282d26922..0000000000
--- a/activerecord/test/connections/native_sybase/connection.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-print "Using native Sybase Open Client\n"
-require_dependency 'models/course'
-require 'logger'
-
-ActiveRecord::Base.logger = Logger.new("debug.log")
-
-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 'arunit'
-Course.establish_connection 'arunit2'
diff --git a/activerecord/test/models/comment.rb b/activerecord/test/models/comment.rb
index 2a4c37089a..43650c0427 100644
--- a/activerecord/test/models/comment.rb
+++ b/activerecord/test/models/comment.rb
@@ -6,7 +6,8 @@ class Comment < ActiveRecord::Base
scope :for_first_author,
:joins => :post,
:conditions => { "posts.author_id" => 1 }
-
+ scope :created
+
belongs_to :post, :counter_cache => true
has_many :ratings
diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb
index f2ab7b053e..affa37b02d 100644
--- a/activerecord/test/models/post.rb
+++ b/activerecord/test/models/post.rb
@@ -36,6 +36,10 @@ class Post < ActiveRecord::Base
def find_most_recent
find(:first, :order => "id DESC")
end
+
+ def newest
+ created.last
+ end
end
has_many :author_favorites, :through => :author
diff --git a/activerecord/test/support/config.rb b/activerecord/test/support/config.rb
new file mode 100644
index 0000000000..3b1598e368
--- /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_unittest2']]
+ 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
diff --git a/activerecord/test/support/connection.rb b/activerecord/test/support/connection.rb
new file mode 100644
index 0000000000..fcd2e4dee5
--- /dev/null
+++ b/activerecord/test/support/connection.rb
@@ -0,0 +1,20 @@
+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
+ puts "Using #{connection_name}"
+ ActiveRecord::Base.logger = Logger.new("debug.log")
+ ActiveRecord::Base.configurations = connection_config
+ ActiveRecord::Base.establish_connection 'arunit'
+ Course.establish_connection 'arunit2'
+ end
+end