Skip to content

Commit

Permalink
Merge branch 'ar-test-cleanup' of git://git.geeksomnia.com/rails
Browse files Browse the repository at this point in the history
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8681 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
jeremy committed Jan 21, 2008
1 parent 1d4f4cd commit 39814fc
Show file tree
Hide file tree
Showing 70 changed files with 296 additions and 320 deletions.
1 change: 1 addition & 0 deletions activerecord/.gitignore
@@ -0,0 +1 @@
debug.log
4 changes: 2 additions & 2 deletions activerecord/RUNNING_UNIT_TESTS
Expand Up @@ -5,7 +5,7 @@ The default names for the test databases are "activerecord_unittest" and
to update the connection adapter setups you want to test with in
test/connections/<your database>/connection.rb.
When you have the database online, you can import the fixture tables with
the test/fixtures/db_definitions/*.sql files.
the test/schema/*.sql files.

Make sure that you create database objects with the same user that you specified in
connection.rb otherwise (on Postgres, at least) tests for default values will fail.
Expand All @@ -22,7 +22,7 @@ Rake can be found at http://rake.rubyforge.org

== Running by hand

Unit tests are located in test directory. If you only want to run a single test suite,
Unit tests are located in test/cases directory. If you only want to run a single test suite,
you can do so with:

rake test_mysql TEST=base_test.rb
Expand Down
22 changes: 11 additions & 11 deletions activerecord/Rakefile
Expand Up @@ -4,7 +4,9 @@ require 'rake/testtask'
require 'rake/rdoctask'
require 'rake/packagetask'
require 'rake/gempackagetask'

require File.join(File.dirname(__FILE__), 'lib', 'active_record', 'version')
require File.expand_path(File.dirname(__FILE__)) + "/test/config"

PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
PKG_NAME = 'activerecord'
Expand All @@ -31,7 +33,7 @@ for adapter in %w( mysql postgresql sqlite sqlite3 firebird db2 oracle sybase op
Rake::TestTask.new("test_#{adapter}") { |t|
t.libs << "test" << "test/connections/native_#{adapter}"
adapter_short = adapter == 'db2' ? adapter : adapter[/^[a-z]+/]
t.pattern = "test/**/*_test{,_#{adapter_short}}.rb"
t.pattern = "test/cases/**/*_test{,_#{adapter_short}}.rb"
t.verbose = true
}

Expand All @@ -40,8 +42,6 @@ for adapter in %w( mysql postgresql sqlite sqlite3 firebird db2 oracle sybase op
end
end

SCHEMA_PATH = File.join(File.dirname(__FILE__), *%w(test fixtures db_definitions))

namespace :mysql do
desc 'Build the MySQL test databases'
task :build_databases do
Expand Down Expand Up @@ -71,8 +71,8 @@ namespace :postgresql do
task :build_databases do
%x( createdb -U postgres activerecord_unittest )
%x( createdb -U postgres activerecord_unittest2 )
%x( psql activerecord_unittest -f #{File.join(SCHEMA_PATH, 'postgresql.sql')} postgres )
%x( psql activerecord_unittest2 -f #{File.join(SCHEMA_PATH, 'postgresql2.sql')} postgres )
%x( psql activerecord_unittest -f #{File.join(SCHEMA_ROOT, 'postgresql.sql')} postgres )
%x( psql activerecord_unittest2 -f #{File.join(SCHEMA_ROOT, 'postgresql2.sql')} postgres )
end

desc 'Drop the PostgreSQL test databases'
Expand Down Expand Up @@ -117,8 +117,8 @@ namespace :frontbase do
DISCONNECT ALL;
)
end
create_activerecord_unittest = build_frontbase_database['activerecord_unittest', File.join(SCHEMA_PATH, 'frontbase.sql')]
create_activerecord_unittest2 = build_frontbase_database['activerecord_unittest2', File.join(SCHEMA_PATH, 'frontbase2.sql')]
create_activerecord_unittest = build_frontbase_database['activerecord_unittest', File.join(SCHEMA_ROOT, 'frontbase.sql')]
create_activerecord_unittest2 = build_frontbase_database['activerecord_unittest2', File.join(SCHEMA_ROOT, 'frontbase2.sql')]
execute_frontbase_sql = Proc.new do |sql|
system(<<-SHELL)
/Library/FrontBase/bin/sql92 <<-SQL
Expand Down Expand Up @@ -174,10 +174,10 @@ spec = Gem::Specification.new do |s|

s.add_dependency('activesupport', '= 2.0.2' + PKG_BUILD)

s.files.delete "test/fixtures/fixture_database.sqlite"
s.files.delete "test/fixtures/fixture_database_2.sqlite"
s.files.delete "test/fixtures/fixture_database.sqlite3"
s.files.delete "test/fixtures/fixture_database_2.sqlite3"
s.files.delete FIXTURES_ROOT + "/fixture_database.sqlite"
s.files.delete FIXTURES_ROOT + "/fixture_database_2.sqlite"
s.files.delete FIXTURES_ROOT + "/fixture_database.sqlite3"
s.files.delete FIXTURES_ROOT + "/fixture_database_2.sqlite3"
s.require_path = 'lib'
s.autorequire = 'active_record'

Expand Down
35 changes: 35 additions & 0 deletions activerecord/lib/active_record/test_case.rb
@@ -0,0 +1,35 @@
require "active_support/test_case"

module ActiveRecord
class TestCase < ActiveSupport::TestCase #:nodoc:
self.fixture_path = FIXTURES_ROOT
self.use_instantiated_fixtures = false

def create_fixtures(*table_names, &block)
Fixtures.create_fixtures(FIXTURES_ROOT, table_names, {}, &block)
end

def assert_date_from_db(expected, actual, message = nil)
# SQL Server doesn't have a separate column type just for dates,
# so the time is in the string and incorrectly formatted
if current_adapter?(:SQLServerAdapter)
assert_equal expected.strftime("%Y/%m/%d 00:00:00"), actual.strftime("%Y/%m/%d 00:00:00")
elsif current_adapter?(:SybaseAdapter)
assert_equal expected.to_s, actual.to_date.to_s, message
else
assert_equal expected.to_s, actual.to_s, message
end
end

def assert_queries(num = 1)
$query_count = 0
yield
ensure
assert_equal num, $query_count, "#{$query_count} instead of #{num} queries were executed."
end

def assert_no_queries(&block)
assert_queries(0, &block)
end
end
end
84 changes: 0 additions & 84 deletions activerecord/test/abstract_unit.rb

This file was deleted.

8 changes: 0 additions & 8 deletions activerecord/test/all.sh

This file was deleted.

14 changes: 0 additions & 14 deletions activerecord/test/association_inheritance_reload.rb

This file was deleted.

20 changes: 8 additions & 12 deletions activerecord/test/cases/aaa_create_tables_test.rb
@@ -1,21 +1,17 @@
# The filename begins with "aaa" to ensure this is the first test.
require 'abstract_unit'
require "cases/helper"

class AAACreateTablesTest < ActiveSupport::TestCase
class AAACreateTablesTest < ActiveRecord::TestCase
self.use_transactional_fixtures = false

def setup
@base_path = "#{File.dirname(__FILE__)}/../schema"
end

def test_drop_and_create_main_tables
recreate ActiveRecord::Base unless use_migrations?
assert true
end

def test_load_schema
if ActiveRecord::Base.connection.supports_migrations?
eval(File.read("#{File.dirname(__FILE__)}/../schema/schema.rb"))
eval(File.read(SCHEMA_ROOT + "/schema.rb"))
else
recreate ActiveRecord::Base, '3'
end
Expand All @@ -24,7 +20,7 @@ def test_load_schema

def test_drop_and_create_courses_table
if Course.connection.supports_migrations?
eval(File.read("#{File.dirname(__FILE__)}/../schema/schema2.rb"))
eval(File.read(SCHEMA_ROOT + "/schema2.rb"))
end
recreate Course, '2' unless use_migrations_for_courses?
assert true
Expand All @@ -33,19 +29,19 @@ def test_drop_and_create_courses_table
private
def use_migrations?
unittest_sql_filename = ActiveRecord::Base.connection.adapter_name.downcase + ".sql"
not File.exist? "#{@base_path}/#{unittest_sql_filename}"
not File.exist? SCHEMA_ROOT + "/#{unittest_sql_filename}"
end

def use_migrations_for_courses?
unittest2_sql_filename = ActiveRecord::Base.connection.adapter_name.downcase + "2.sql"
not File.exist? "#{@base_path}/#{unittest2_sql_filename}"
not File.exist? SCHEMA_ROOT + "/#{unittest2_sql_filename}"
end

def recreate(base, suffix = nil)
connection = base.connection
adapter_name = connection.adapter_name.downcase + suffix.to_s
execute_sql_file "#{@base_path}/#{adapter_name}.drop.sql", connection
execute_sql_file "#{@base_path}/#{adapter_name}.sql", connection
execute_sql_file SCHEMA_ROOT + "/#{adapter_name}.drop.sql", connection
execute_sql_file SCHEMA_ROOT + "/#{adapter_name}.sql", connection
end

def execute_sql_file(path, connection)
Expand Down
4 changes: 2 additions & 2 deletions activerecord/test/cases/active_schema_test_mysql.rb
@@ -1,6 +1,6 @@
require 'abstract_unit'
require "cases/helper"

class ActiveSchemaTest < ActiveSupport::TestCase
class ActiveSchemaTest < ActiveRecord::TestCase
def setup
ActiveRecord::ConnectionAdapters::MysqlAdapter.class_eval do
alias_method :execute_without_stub, :execute
Expand Down
4 changes: 2 additions & 2 deletions activerecord/test/cases/adapter_test.rb
@@ -1,6 +1,6 @@
require 'abstract_unit'
require "cases/helper"

class AdapterTest < ActiveSupport::TestCase
class AdapterTest < ActiveRecord::TestCase
def setup
@connection = ActiveRecord::Base.connection
end
Expand Down
4 changes: 2 additions & 2 deletions activerecord/test/cases/adapter_test_sqlserver.rb
@@ -1,9 +1,9 @@
require 'abstract_unit'
require "cases/helper"
require 'models/default'
require 'models/post'
require 'models/task'

class SqlServerAdapterTest < ActiveSupport::TestCase
class SqlServerAdapterTest < ActiveRecord::TestCase
class TableWithRealColumn < ActiveRecord::Base; end

fixtures :posts, :tasks
Expand Down
6 changes: 3 additions & 3 deletions activerecord/test/cases/aggregations_test.rb
@@ -1,7 +1,7 @@
require 'abstract_unit'
require "cases/helper"
require 'models/customer'

class AggregationsTest < ActiveSupport::TestCase
class AggregationsTest < ActiveRecord::TestCase
fixtures :customers

def test_find_single_value_object
Expand Down Expand Up @@ -109,7 +109,7 @@ def test_nil_assignment_results_in_nil
end
end

class OverridingAggregationsTest < ActiveSupport::TestCase
class OverridingAggregationsTest < ActiveRecord::TestCase
class Name; end
class DifferentName; end

Expand Down
4 changes: 2 additions & 2 deletions activerecord/test/cases/ar_schema_test.rb
@@ -1,9 +1,9 @@
require 'abstract_unit'
require "cases/helper"
require 'active_record/schema'

if ActiveRecord::Base.connection.supports_migrations?

class ActiveRecordSchemaTest < ActiveSupport::TestCase
class ActiveRecordSchemaTest < ActiveRecord::TestCase
self.use_transactional_fixtures = false

def setup
Expand Down
4 changes: 2 additions & 2 deletions activerecord/test/cases/associations/callbacks_test.rb
@@ -1,12 +1,12 @@
require 'abstract_unit'
require "cases/helper"
require 'models/post'
require 'models/comment'
require 'models/author'
require 'models/category'
require 'models/project'
require 'models/developer'

class AssociationCallbacksTest < ActiveSupport::TestCase
class AssociationCallbacksTest < ActiveRecord::TestCase
fixtures :posts, :authors, :projects, :developers

def setup
Expand Down
@@ -1,4 +1,4 @@
require 'abstract_unit'
require "cases/helper"
require 'models/post'
require 'models/comment'
require 'models/author'
Expand All @@ -8,7 +8,7 @@
require 'models/topic'
require 'models/reply'

class CascadedEagerLoadingTest < ActiveSupport::TestCase
class CascadedEagerLoadingTest < ActiveRecord::TestCase
fixtures :authors, :mixins, :companies, :posts, :topics

def test_eager_association_loading_with_cascaded_two_levels
Expand Down Expand Up @@ -95,7 +95,7 @@ def test_eager_association_loading_of_stis_with_multiple_references

require 'models/vertex'
require 'models/edge'
class CascadedEagerLoadingTest < ActiveSupport::TestCase
class CascadedEagerLoadingTest < ActiveRecord::TestCase
fixtures :edges, :vertices

def test_eager_association_loading_with_recursive_cascading_four_levels_has_many_through
Expand Down

0 comments on commit 39814fc

Please sign in to comment.