Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'ar-test-cleanup' of git://git.geeksomnia.com/rails

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8681 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 39814fcce0b429eb06654600e4669f1405ffa7d9 1 parent 1d4f4cd
@jeremy jeremy authored
Showing with 296 additions and 320 deletions.
  1. +1 −0  activerecord/.gitignore
  2. +2 −2 activerecord/RUNNING_UNIT_TESTS
  3. +11 −11 activerecord/Rakefile
  4. +35 −0 activerecord/lib/active_record/test_case.rb
  5. +0 −84 activerecord/test/abstract_unit.rb
  6. +0 −8 activerecord/test/all.sh
  7. +0 −14 activerecord/test/association_inheritance_reload.rb
  8. +8 −12 activerecord/test/cases/aaa_create_tables_test.rb
  9. +2 −2 activerecord/test/cases/active_schema_test_mysql.rb
  10. +2 −2 activerecord/test/cases/adapter_test.rb
  11. +2 −2 activerecord/test/cases/adapter_test_sqlserver.rb
  12. +3 −3 activerecord/test/cases/aggregations_test.rb
  13. +2 −2 activerecord/test/cases/ar_schema_test.rb
  14. +2 −2 activerecord/test/cases/associations/callbacks_test.rb
  15. +3 −3 activerecord/test/cases/associations/cascaded_eager_loading_test.rb
  16. +2 −2 activerecord/test/cases/associations/eager_singularization_test.rb
  17. +2 −2 activerecord/test/cases/associations/eager_test.rb
  18. +2 −2 activerecord/test/cases/associations/extension_test.rb
  19. +2 −2 activerecord/test/cases/associations/inner_join_association_test.rb
  20. +2 −2 activerecord/test/cases/associations/join_model_test.rb
  21. +8 −8 activerecord/test/cases/associations_test.rb
  22. +2 −2 activerecord/test/cases/attribute_methods_test.rb
  23. +2 −2 activerecord/test/cases/base_test.rb
  24. +3 −3 activerecord/test/cases/binary_test.rb
  25. +2 −2 activerecord/test/cases/calculations_test.rb
  26. +2 −2 activerecord/test/cases/callbacks_test.rb
  27. +2 −2 activerecord/test/cases/class_inheritable_attributes_test.rb
  28. +2 −2 activerecord/test/cases/column_alias_test.rb
  29. +2 −2 activerecord/test/cases/connection_test_firebird.rb
  30. +2 −2 activerecord/test/cases/connection_test_mysql.rb
  31. +2 −2 activerecord/test/cases/copy_table_test_sqlite.rb
  32. +2 −2 activerecord/test/cases/datatype_test_postgresql.rb
  33. +2 −2 activerecord/test/cases/date_time_test.rb
  34. +2 −2 activerecord/test/cases/default_test_firebird.rb
  35. +2 −2 activerecord/test/cases/defaults_test.rb
  36. +2 −2 activerecord/test/cases/deprecated_finder_test.rb
  37. +2 −2 activerecord/test/cases/finder_test.rb
  38. +27 −29 activerecord/test/cases/fixtures_test.rb
  39. +46 −0 activerecord/test/cases/helper.rb
  40. +3 −3 activerecord/test/cases/inheritance_test.rb
  41. +3 −3 activerecord/test/cases/json_serialization_test.rb
  42. +2 −2 activerecord/test/cases/lifecycle_test.rb
  43. +3 −3 activerecord/test/cases/locking_test.rb
  44. +7 −7 activerecord/test/cases/method_scoping_test.rb
  45. +25 −24 activerecord/test/cases/migration_test.rb
  46. +2 −2 activerecord/test/cases/migration_test_firebird.rb
  47. +2 −2 activerecord/test/cases/mixin_test.rb
  48. +2 −2 activerecord/test/cases/modules_test.rb
  49. +2 −2 activerecord/test/cases/multiple_db_test.rb
  50. +2 −2 activerecord/test/cases/pk_test.rb
  51. +3 −3 activerecord/test/cases/query_cache_test.rb
  52. +2 −2 activerecord/test/cases/readonly_test.rb
  53. +2 −2 activerecord/test/cases/reflection_test.rb
  54. +3 −4 activerecord/test/cases/reserved_word_test_mysql.rb
  55. +2 −2 activerecord/test/cases/schema_authorization_test_postgresql.rb
  56. +2 −2 activerecord/test/cases/schema_dumper_test.rb
  57. +2 −2 activerecord/test/cases/schema_test_postgresql.rb
  58. +2 −2 activerecord/test/cases/serialization_test.rb
  59. +2 −2 activerecord/test/cases/synonym_test_oracle.rb
  60. +2 −2 activerecord/test/cases/table_name_test_sqlserver.rb
  61. +2 −2 activerecord/test/cases/threaded_connections_test.rb
  62. +2 −2 activerecord/test/cases/transactions_test.rb
  63. +2 −2 activerecord/test/cases/unconnected_test.rb
  64. +3 −3 activerecord/test/cases/validations_test.rb
  65. +5 −5 activerecord/test/cases/xml_serialization_test.rb
  66. +5 −0 activerecord/test/config.rb
  67. +1 −1  activerecord/test/connections/native_sqlite/connection.rb
  68. +1 −1  activerecord/test/connections/native_sqlite3/connection.rb
  69. +2 −2 activerecord/test/connections/native_sqlite3/in_memory_connection.rb
  70. +1 −0  activerecord/test/fixtures/.gitignore
View
1  activerecord/.gitignore
@@ -0,0 +1 @@
+debug.log
View
4 activerecord/RUNNING_UNIT_TESTS
@@ -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.
@@ -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
View
22 activerecord/Rakefile
@@ -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'
@@ -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
}
@@ -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
@@ -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'
@@ -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
@@ -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'
View
35 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
View
84 activerecord/test/abstract_unit.rb
@@ -1,84 +0,0 @@
-$:.unshift(File.dirname(__FILE__) + '/../lib')
-$:.unshift(File.dirname(__FILE__) + '/../../activesupport/lib')
-
-require 'test/unit'
-require 'active_record'
-require 'active_record/fixtures'
-require 'active_support/test_case'
-require 'connection'
-
-# Show backtraces for deprecated behavior for quicker cleanup.
-ActiveSupport::Deprecation.debug = true
-
-
-QUOTED_TYPE = ActiveRecord::Base.connection.quote_column_name('type') unless Object.const_defined?(:QUOTED_TYPE)
-
-class ActiveSupport::TestCase #:nodoc:
- self.fixture_path = File.dirname(__FILE__) + "/fixtures/"
- self.use_instantiated_fixtures = false
- self.use_transactional_fixtures = (ENV['AR_NO_TX_FIXTURES'] != "yes")
-
- def create_fixtures(*table_names, &block)
- Fixtures.create_fixtures(File.dirname(__FILE__) + "/fixtures/", 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
-
-def current_adapter?(*types)
- types.any? do |type|
- ActiveRecord::ConnectionAdapters.const_defined?(type) &&
- ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters.const_get(type))
- end
-end
-
-def uses_mocha(test_name)
- require 'rubygems'
- require 'mocha'
- yield
-rescue LoadError
- $stderr.puts "Skipping #{test_name} tests. `gem install mocha` and try again."
-end
-
-ActiveRecord::Base.connection.class.class_eval do
- unless defined? IGNORED_SQL
- IGNORED_SQL = [/^PRAGMA/, /^SELECT currval/, /^SELECT CAST/, /^SELECT @@IDENTITY/, /^SELECT @@ROWCOUNT/]
-
- def execute_with_counting(sql, name = nil, &block)
- $query_count ||= 0
- $query_count += 1 unless IGNORED_SQL.any? { |r| sql =~ r }
- execute_without_counting(sql, name, &block)
- end
-
- alias_method_chain :execute, :counting
- end
-end
-
-# Make with_scope public for tests
-class << ActiveRecord::Base
- public :with_scope, :with_exclusive_scope
-end
-
-#ActiveRecord::Base.logger = Logger.new(STDOUT)
-#ActiveRecord::Base.colorize_logging = false
View
8 activerecord/test/all.sh
@@ -1,8 +0,0 @@
-#!/bin/sh
-
-if [ -z "$1" ]; then
- echo "Usage: $0 <database>" 1>&2
- exit 1
-fi
-
-ruby -I connections/native_$1 -e 'Dir["**/*_test.rb"].each { |path| require path }'
View
14 activerecord/test/association_inheritance_reload.rb
@@ -1,14 +0,0 @@
-require 'abstract_unit'
-require 'fixtures/company'
-
-class AssociationInheritanceReloadTest < ActiveSupport::TestCase
- fixtures :companies
-
- def test_set_attributes
- assert_equal ["errors.add_on_empty('name', \"can't be empty\")"], Firm.read_inheritable_attribute("validate"), "Second run"
- # ActiveRecord::Base.reset_column_information_and_inheritable_attributes_for_all_subclasses
- remove_subclass_of(ActiveRecord::Base)
- load 'fixtures/company.rb'
- assert_equal ["errors.add_on_empty('name', \"can't be empty\")"], Firm.read_inheritable_attribute("validate"), "Second run"
- end
-end
View
20 activerecord/test/cases/aaa_create_tables_test.rb
@@ -1,13 +1,9 @@
# 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
@@ -15,7 +11,7 @@ def test_drop_and_create_main_tables
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
@@ -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
@@ -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)
View
4 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
View
4 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
View
4 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
View
6 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
@@ -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
View
4 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
View
4 activerecord/test/cases/associations/callbacks_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit'
+require "cases/helper"
require 'models/post'
require 'models/comment'
require 'models/author'
@@ -6,7 +6,7 @@
require 'models/project'
require 'models/developer'
-class AssociationCallbacksTest < ActiveSupport::TestCase
+class AssociationCallbacksTest < ActiveRecord::TestCase
fixtures :posts, :authors, :projects, :developers
def setup
View
6 activerecord/test/cases/associations/cascaded_eager_loading_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit'
+require "cases/helper"
require 'models/post'
require 'models/comment'
require 'models/author'
@@ -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
@@ -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
View
4 activerecord/test/cases/associations/eager_singularization_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit'
+require "cases/helper"
class Virus < ActiveRecord::Base
belongs_to :octopus
@@ -39,7 +39,7 @@ class Compress < ActiveRecord::Base
end
-class EagerSingularizationTest < ActiveSupport::TestCase
+class EagerSingularizationTest < ActiveRecord::TestCase
def setup
if ActiveRecord::Base.connection.supports_migrations?
View
4 activerecord/test/cases/associations/eager_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit'
+require "cases/helper"
require 'models/post'
require 'models/tagging'
require 'models/comment'
@@ -8,7 +8,7 @@
require 'models/person'
require 'models/reader'
-class EagerAssociationTest < ActiveSupport::TestCase
+class EagerAssociationTest < ActiveRecord::TestCase
fixtures :posts, :comments, :authors, :categories, :categories_posts,
:companies, :accounts, :tags, :taggings, :people, :readers
View
4 activerecord/test/cases/associations/extension_test.rb
@@ -1,10 +1,10 @@
-require 'abstract_unit'
+require "cases/helper"
require 'models/post'
require 'models/comment'
require 'models/project'
require 'models/developer'
-class AssociationsExtensionsTest < ActiveSupport::TestCase
+class AssociationsExtensionsTest < ActiveRecord::TestCase
fixtures :projects, :developers, :developers_projects, :comments, :posts
def test_extension_on_has_many
View
4 activerecord/test/cases/associations/inner_join_association_test.rb
@@ -1,11 +1,11 @@
-require 'abstract_unit'
+require "cases/helper"
require 'models/post'
require 'models/comment'
require 'models/author'
require 'models/category'
require 'models/categorization'
-class InnerJoinAssociationTest < ActiveSupport::TestCase
+class InnerJoinAssociationTest < ActiveRecord::TestCase
fixtures :authors, :posts, :comments, :categories, :categories_posts, :categorizations
def test_construct_finder_sql_creates_inner_joins
View
4 activerecord/test/cases/associations/join_model_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit'
+require "cases/helper"
require 'models/tag'
require 'models/tagging'
require 'models/post'
@@ -12,7 +12,7 @@
require 'models/book'
require 'models/citation'
-class AssociationsJoinModelTest < ActiveSupport::TestCase
+class AssociationsJoinModelTest < ActiveRecord::TestCase
self.use_transactional_fixtures = false
fixtures :posts, :authors, :categories, :categorizations, :comments, :tags, :taggings, :author_favorites, :vertices, :items, :books
View
16 activerecord/test/cases/associations_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit'
+require "cases/helper"
require 'models/developer'
require 'models/project'
require 'models/company'
@@ -17,7 +17,7 @@
require 'models/person'
require 'models/reader'
-class AssociationsTest < ActiveSupport::TestCase
+class AssociationsTest < ActiveRecord::TestCase
fixtures :accounts, :companies, :developers, :projects, :developers_projects,
:computers
@@ -78,7 +78,7 @@ def test_storing_in_pstore
end
end
-class AssociationProxyTest < ActiveSupport::TestCase
+class AssociationProxyTest < ActiveRecord::TestCase
fixtures :authors, :posts, :categorizations, :categories, :developers, :projects, :developers_projects
def test_proxy_accessors
@@ -171,7 +171,7 @@ def setup_dangling_association
end
end
-class HasOneAssociationsTest < ActiveSupport::TestCase
+class HasOneAssociationsTest < ActiveRecord::TestCase
fixtures :accounts, :companies, :developers, :projects, :developers_projects
def setup
@@ -468,7 +468,7 @@ def test_save_still_works_after_accessing_nil_has_one
end
-class HasManyAssociationsTest < ActiveSupport::TestCase
+class HasManyAssociationsTest < ActiveRecord::TestCase
fixtures :accounts, :companies, :developers, :projects,
:developers_projects, :topics, :authors, :comments, :author_addresses
@@ -1218,7 +1218,7 @@ def test_dynamic_find_all_order_should_override_association_limit_for_through
end
-class BelongsToAssociationsTest < ActiveSupport::TestCase
+class BelongsToAssociationsTest < ActiveRecord::TestCase
fixtures :accounts, :companies, :developers, :projects, :topics,
:developers_projects, :computers, :authors, :posts, :tags, :taggings
@@ -1594,7 +1594,7 @@ class DeveloperForProjectWithAfterCreateHook < ActiveRecord::Base
end
-class HasAndBelongsToManyAssociationsTest < ActiveSupport::TestCase
+class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
fixtures :accounts, :companies, :categories, :posts, :categories_posts, :developers, :projects, :developers_projects
def test_has_and_belongs_to_many
@@ -2134,7 +2134,7 @@ def test_scoped_find_on_through_association_doesnt_return_read_only_records
end
-class OverridingAssociationsTest < ActiveSupport::TestCase
+class OverridingAssociationsTest < ActiveRecord::TestCase
class Person < ActiveRecord::Base; end
class DifferentPerson < ActiveRecord::Base; end
View
4 activerecord/test/cases/attribute_methods_test.rb
@@ -1,7 +1,7 @@
-require 'abstract_unit'
+require "cases/helper"
require 'models/topic'
-class AttributeMethodsTest < ActiveSupport::TestCase
+class AttributeMethodsTest < ActiveRecord::TestCase
fixtures :topics
def setup
@old_suffixes = ActiveRecord::Base.send(:attribute_method_suffixes).dup
View
4 activerecord/test/cases/base_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit'
+require "cases/helper"
require 'models/topic'
require 'models/reply'
require 'models/company'
@@ -71,7 +71,7 @@ class TopicWithProtectedContentAndAccessibleAuthorName < ActiveRecord::Base
attr_protected :content
end
-class BasicsTest < ActiveSupport::TestCase
+class BasicsTest < ActiveRecord::TestCase
fixtures :topics, :companies, :developers, :projects, :computers, :accounts, :minimalistics, 'warehouse-things'
def test_table_exists
View
6 activerecord/test/cases/binary_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit'
+require "cases/helper"
# Without using prepared statements, it makes no sense to test
# BLOB data with SQL Server, because the length of a statement is
@@ -10,14 +10,14 @@
unless current_adapter?(:SQLServerAdapter, :SybaseAdapter, :DB2Adapter, :FirebirdAdapter)
require 'models/binary'
- class BinaryTest < ActiveSupport::TestCase
+ class BinaryTest < ActiveRecord::TestCase
FIXTURES = %w(flowers.jpg example.log)
def test_load_save
Binary.delete_all
FIXTURES.each do |filename|
- data = File.read("#{File.dirname(__FILE__)}/../assets/#{filename}").freeze
+ data = File.read(ASSETS_ROOT + "/#{filename}").freeze
bin = Binary.new(:data => data)
assert_equal data, bin.data, 'Newly assigned data differs from original'
View
4 activerecord/test/cases/calculations_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit'
+require "cases/helper"
require 'models/company'
require 'models/topic'
@@ -8,7 +8,7 @@ class NumericData < ActiveRecord::Base
self.table_name = 'numeric_data'
end
-class CalculationsTest < ActiveSupport::TestCase
+class CalculationsTest < ActiveRecord::TestCase
fixtures :companies, :accounts, :topics
def test_should_sum_field
View
4 activerecord/test/cases/callbacks_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit'
+require "cases/helper"
class CallbackDeveloper < ActiveRecord::Base
set_table_name 'developers'
@@ -126,7 +126,7 @@ def before_create
end
end
-class CallbacksTest < ActiveSupport::TestCase
+class CallbacksTest < ActiveRecord::TestCase
fixtures :developers
def test_initialize
View
4 activerecord/test/cases/class_inheritable_attributes_test.rb
@@ -1,5 +1,5 @@
require 'test/unit'
-require 'abstract_unit'
+require "cases/helper"
require 'active_support/core_ext/class/inheritable_attributes'
class A
@@ -19,7 +19,7 @@ class D < B
end
-class ClassInheritableAttributesTest < ActiveSupport::TestCase
+class ClassInheritableAttributesTest < ActiveRecord::TestCase
def test_first_level
assert_equal [ :one, :two ], B.read_inheritable_attribute("first")
assert_equal [ :three ], C.read_inheritable_attribute("first")
View
4 activerecord/test/cases/column_alias_test.rb
@@ -1,7 +1,7 @@
-require 'abstract_unit'
+require "cases/helper"
require 'models/topic'
-class TestColumnAlias < ActiveSupport::TestCase
+class TestColumnAlias < ActiveRecord::TestCase
fixtures :topics
QUERY = if 'Oracle' == ActiveRecord::Base.connection.adapter_name
View
4 activerecord/test/cases/connection_test_firebird.rb
@@ -1,6 +1,6 @@
-require 'abstract_unit'
+require "cases/helper"
-class FirebirdConnectionTest < ActiveSupport::TestCase
+class FirebirdConnectionTest < ActiveRecord::TestCase
def test_charset_properly_set
fb_conn = ActiveRecord::Base.connection.instance_variable_get(:@connection)
assert_equal 'UTF8', fb_conn.database.character_set
View
4 activerecord/test/cases/connection_test_mysql.rb
@@ -1,6 +1,6 @@
-require 'abstract_unit'
+require "cases/helper"
-class MysqlConnectionTest < ActiveSupport::TestCase
+class MysqlConnectionTest < ActiveRecord::TestCase
def setup
@connection = ActiveRecord::Base.connection
end
View
4 activerecord/test/cases/copy_table_test_sqlite.rb
@@ -1,6 +1,6 @@
-require 'abstract_unit'
+require "cases/helper"
-class CopyTableTest < ActiveSupport::TestCase
+class CopyTableTest < ActiveRecord::TestCase
fixtures :companies, :comments
def setup
View
4 activerecord/test/cases/datatype_test_postgresql.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit'
+require "cases/helper"
class PostgresqlArray < ActiveRecord::Base
end
@@ -21,7 +21,7 @@ class PostgresqlBitString < ActiveRecord::Base
class PostgresqlOid < ActiveRecord::Base
end
-class PostgresqlDataTypeTest < ActiveSupport::TestCase
+class PostgresqlDataTypeTest < ActiveRecord::TestCase
self.use_transactional_fixtures = false
def setup
View
4 activerecord/test/cases/date_time_test.rb
@@ -1,8 +1,8 @@
-require 'abstract_unit'
+require "cases/helper"
require 'models/topic'
require 'models/task'
-class DateTimeTest < ActiveSupport::TestCase
+class DateTimeTest < ActiveRecord::TestCase
def test_saves_both_date_and_time
time_values = [1807, 2, 10, 15, 30, 45]
now = DateTime.civil(*time_values)
View
4 activerecord/test/cases/default_test_firebird.rb
@@ -1,7 +1,7 @@
-require 'abstract_unit'
+require "cases/helper"
require 'models/default'
-class DefaultTest < ActiveSupport::TestCase
+class DefaultTest < ActiveRecord::TestCase
def test_default_timestamp
default = Default.new
assert_instance_of(Time, default.default_timestamp)
View
4 activerecord/test/cases/defaults_test.rb
@@ -1,8 +1,8 @@
-require 'abstract_unit'
+require "cases/helper"
require 'models/default'
require 'models/entrant'
-class DefaultTest < ActiveSupport::TestCase
+class DefaultTest < ActiveRecord::TestCase
def test_nil_defaults_for_not_null_columns
column_defaults =
if current_adapter?(:MysqlAdapter)
View
4 activerecord/test/cases/deprecated_finder_test.rb
@@ -1,7 +1,7 @@
-require 'abstract_unit'
+require "cases/helper"
require 'models/entrant'
-class DeprecatedFinderTest < ActiveSupport::TestCase
+class DeprecatedFinderTest < ActiveRecord::TestCase
fixtures :entrants
def test_deprecated_find_all_was_removed
View
4 activerecord/test/cases/finder_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit'
+require "cases/helper"
require 'models/author'
require 'models/comment'
require 'models/company'
@@ -9,7 +9,7 @@
require 'models/post'
require 'models/customer'
-class FinderTest < ActiveSupport::TestCase
+class FinderTest < ActiveRecord::TestCase
fixtures :companies, :topics, :entrants, :developers, :developers_projects, :posts, :comments, :accounts, :authors, :customers
def test_find
View
56 activerecord/test/cases/fixtures_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit'
+require "cases/helper"
require 'models/post'
require 'models/binary'
require 'models/topic'
@@ -16,7 +16,7 @@
require 'models/matey'
require 'models/ship'
-class FixturesTest < ActiveSupport::TestCase
+class FixturesTest < ActiveRecord::TestCase
self.use_instantiated_fixtures = true
self.use_transactional_fixtures = false
@@ -27,8 +27,6 @@ class FixturesTest < ActiveSupport::TestCase
movies projects subscribers topics tasks )
MATCH_ATTRIBUTE_NAME = /[a-zA-Z][-_\w]*/
- BINARY_FIXTURE_PATH = File.dirname(__FILE__) + '/../assets/flowers.jpg'
-
def test_clean_fixtures
FIXTURES.each do |name|
fixtures = nil
@@ -140,26 +138,26 @@ def test_erb_in_fixtures
end
def test_empty_yaml_fixture
- assert_not_nil Fixtures.new( Account.connection, "accounts", 'Account', File.dirname(__FILE__) + "/../fixtures/naked/yml/accounts")
+ assert_not_nil Fixtures.new( Account.connection, "accounts", 'Account', FIXTURES_ROOT + "/naked/yml/accounts")
end
def test_empty_yaml_fixture_with_a_comment_in_it
- assert_not_nil Fixtures.new( Account.connection, "companies", 'Company', File.dirname(__FILE__) + "/../fixtures/naked/yml/companies")
+ assert_not_nil Fixtures.new( Account.connection, "companies", 'Company', FIXTURES_ROOT + "/naked/yml/companies")
end
def test_dirty_dirty_yaml_file
assert_raises(Fixture::FormatError) do
- Fixtures.new( Account.connection, "courses", 'Course', File.dirname(__FILE__) + "/../fixtures/naked/yml/courses")
+ Fixtures.new( Account.connection, "courses", 'Course', FIXTURES_ROOT + "/naked/yml/courses")
end
end
def test_empty_csv_fixtures
- assert_not_nil Fixtures.new( Account.connection, "accounts", 'Account', File.dirname(__FILE__) + "/../fixtures/naked/csv/accounts")
+ assert_not_nil Fixtures.new( Account.connection, "accounts", 'Account', FIXTURES_ROOT + "/naked/csv/accounts")
end
def test_omap_fixtures
assert_nothing_raised do
- fixtures = Fixtures.new(Account.connection, 'categories', 'Category', File.dirname(__FILE__) + '/../fixtures/categories_ordered')
+ fixtures = Fixtures.new(Account.connection, 'categories', 'Category', FIXTURES_ROOT + "/categories_ordered")
i = 0
fixtures.each do |name, fixture|
@@ -182,13 +180,13 @@ def test_subsubdir_file_with_arbitrary_name
def test_binary_in_fixtures
assert_equal 1, @binaries.size
- data = File.open(BINARY_FIXTURE_PATH, "rb").read.freeze
+ data = File.open(ASSETS_ROOT + "/flowers.jpg", "rb").read.freeze
assert_equal data, @flowers.data
end
end
if Account.connection.respond_to?(:reset_pk_sequence!)
- class FixturesResetPkSequenceTest < ActiveSupport::TestCase
+ class FixturesResetPkSequenceTest < ActiveRecord::TestCase
fixtures :accounts
fixtures :companies
@@ -234,7 +232,7 @@ def test_create_fixtures_resets_sequences_when_not_cached
end
end
-class FixturesWithoutInstantiationTest < ActiveSupport::TestCase
+class FixturesWithoutInstantiationTest < ActiveRecord::TestCase
self.use_instantiated_fixtures = false
fixtures :topics, :developers, :accounts
@@ -269,7 +267,7 @@ def test_reloading_fixtures_through_accessor_methods
end
end
-class FixturesWithoutInstanceInstantiationTest < ActiveSupport::TestCase
+class FixturesWithoutInstanceInstantiationTest < ActiveRecord::TestCase
self.use_instantiated_fixtures = true
self.use_instantiated_fixtures = :no_instances
@@ -283,7 +281,7 @@ def test_without_instance_instantiation
end
end
-class TransactionalFixturesTest < ActiveSupport::TestCase
+class TransactionalFixturesTest < ActiveRecord::TestCase
self.use_instantiated_fixtures = true
self.use_transactional_fixtures = true
@@ -299,7 +297,7 @@ def test_destroy_just_kidding
end
end
-class MultipleFixturesTest < ActiveSupport::TestCase
+class MultipleFixturesTest < ActiveRecord::TestCase
fixtures :topics
fixtures :developers, :accounts
@@ -308,7 +306,7 @@ def test_fixture_table_names
end
end
-class SetupTest < ActiveSupport::TestCase
+class SetupTest < ActiveRecord::TestCase
# fixtures :topics
def setup
@@ -332,7 +330,7 @@ def test_subclassing_should_preserve_setups
end
-class OverlappingFixturesTest < ActiveSupport::TestCase
+class OverlappingFixturesTest < ActiveRecord::TestCase
fixtures :topics, :developers
fixtures :developers, :accounts
@@ -341,7 +339,7 @@ def test_fixture_table_names
end
end
-class ForeignKeyFixturesTest < ActiveSupport::TestCase
+class ForeignKeyFixturesTest < ActiveRecord::TestCase
fixtures :fk_test_has_pk, :fk_test_has_fk
# if foreign keys are implemented and fixtures
@@ -357,7 +355,7 @@ def test_number2
end
end
-class SetTableNameFixturesTest < ActiveSupport::TestCase
+class SetTableNameFixturesTest < ActiveRecord::TestCase
set_fixture_class :funny_jokes => 'Joke'
fixtures :funny_jokes
@@ -366,7 +364,7 @@ def test_table_method
end
end
-class CustomConnectionFixturesTest < ActiveSupport::TestCase
+class CustomConnectionFixturesTest < ActiveRecord::TestCase
set_fixture_class :courses => Course
fixtures :courses
@@ -376,7 +374,7 @@ def test_connection
end
end
-class InvalidTableNameFixturesTest < ActiveSupport::TestCase
+class InvalidTableNameFixturesTest < ActiveRecord::TestCase
fixtures :funny_jokes
def test_raises_error
@@ -386,7 +384,7 @@ def test_raises_error
end
end
-class CheckEscapedYamlFixturesTest < ActiveSupport::TestCase
+class CheckEscapedYamlFixturesTest < ActiveRecord::TestCase
set_fixture_class :funny_jokes => 'Joke'
fixtures :funny_jokes
@@ -396,7 +394,7 @@ def test_proper_escaped_fixture
end
class DevelopersProject; end
-class ManyToManyFixturesWithClassDefined < ActiveSupport::TestCase
+class ManyToManyFixturesWithClassDefined < ActiveRecord::TestCase
fixtures :developers_projects
def test_this_should_run_cleanly
@@ -404,7 +402,7 @@ def test_this_should_run_cleanly
end
end
-class FixturesBrokenRollbackTest < ActiveSupport::TestCase
+class FixturesBrokenRollbackTest < ActiveRecord::TestCase
def blank_setup; end
alias_method :ar_setup_fixtures, :setup_fixtures
alias_method :setup_fixtures, :blank_setup
@@ -429,8 +427,8 @@ def load_fixtures
end
end
-class LoadAllFixturesTest < ActiveSupport::TestCase
- self.fixture_path= File.join(File.dirname(__FILE__), '/../fixtures/all')
+class LoadAllFixturesTest < ActiveRecord::TestCase
+ self.fixture_path = FIXTURES_ROOT + "/all"
fixtures :all
def test_all_there
@@ -438,7 +436,7 @@ def test_all_there
end
end
-class FasterFixturesTest < ActiveSupport::TestCase
+class FasterFixturesTest < ActiveRecord::TestCase
fixtures :categories, :authors
def load_extra_fixture(name)
@@ -463,7 +461,7 @@ def test_cache
end
end
-class FoxyFixturesTest < ActiveSupport::TestCase
+class FoxyFixturesTest < ActiveRecord::TestCase
fixtures :parrots, :parrots_pirates, :pirates, :treasures, :mateys, :ships, :computers, :developers
def test_identifies_strings
@@ -583,7 +581,7 @@ def test_supports_sti
end
end
-class ActiveSupportSubclassWithFixturesTest < ActiveSupport::TestCase
+class ActiveSupportSubclassWithFixturesTest < ActiveRecord::TestCase
fixtures :parrots
# This seemingly useless assertion catches a bug that caused the fixtures
View
46 activerecord/test/cases/helper.rb
@@ -0,0 +1,46 @@
+$:.unshift(File.dirname(__FILE__) + '/../../lib')
+
+require 'config'
+
+require 'active_record'
+require 'active_record/fixtures'
+require 'active_record/test_case'
+require 'connection'
+
+# Show backtraces for deprecated behavior for quicker cleanup.
+ActiveSupport::Deprecation.debug = true
+
+# Quote "type" if it's a reserved word for the current connection.
+QUOTED_TYPE = ActiveRecord::Base.connection.quote_column_name('type')
+
+def current_adapter?(*types)
+ types.any? do |type|
+ ActiveRecord::ConnectionAdapters.const_defined?(type) &&
+ ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters.const_get(type))
+ end
+end
+
+def uses_mocha(description)
+ require 'rubygems'
+ require 'mocha'
+ yield
+rescue LoadError
+ $stderr.puts "Skipping #{description} tests. `gem install mocha` and try again."
+end
+
+ActiveRecord::Base.connection.class.class_eval do
+ IGNORED_SQL = [/^PRAGMA/, /^SELECT currval/, /^SELECT CAST/, /^SELECT @@IDENTITY/, /^SELECT @@ROWCOUNT/]
+
+ def execute_with_counting(sql, name = nil, &block)
+ $query_count ||= 0
+ $query_count += 1 unless IGNORED_SQL.any? { |r| sql =~ r }
+ execute_without_counting(sql, name, &block)
+ end
+
+ alias_method_chain :execute, :counting
+end
+
+# Make with_scope public for tests
+class << ActiveRecord::Base
+ public :with_scope, :with_exclusive_scope
+end
View
6 activerecord/test/cases/inheritance_test.rb
@@ -1,9 +1,9 @@
-require 'abstract_unit'
+require "cases/helper"
require 'models/company'
require 'models/project'
require 'models/subscriber'
-class InheritanceTest < ActiveSupport::TestCase
+class InheritanceTest < ActiveRecord::TestCase
fixtures :companies, :projects, :subscribers, :accounts
def test_company_descends_from_active_record
@@ -175,7 +175,7 @@ def switch_to_default_inheritance_column
end
-class InheritanceComputeTypeTest < ActiveSupport::TestCase
+class InheritanceComputeTypeTest < ActiveRecord::TestCase
fixtures :companies
def setup
View
6 activerecord/test/cases/json_serialization_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit'
+require "cases/helper"
require 'models/contact'
require 'models/post'
require 'models/author'
@@ -6,7 +6,7 @@
require 'models/tag'
require 'models/comment'
-class JsonSerializationTest < ActiveSupport::TestCase
+class JsonSerializationTest < ActiveRecord::TestCase
def setup
@contact = Contact.new(
:name => 'Konata Izumi',
@@ -63,7 +63,7 @@ def @contact.favorite_quote; "Constraints are liberating"; end
end
end
-class DatabaseConnectedJsonEncodingTest < ActiveSupport::TestCase
+class DatabaseConnectedJsonEncodingTest < ActiveRecord::TestCase
fixtures :authors, :posts, :comments, :tags, :taggings
def setup
View
4 activerecord/test/cases/lifecycle_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit'
+require "cases/helper"
require 'models/topic'
require 'models/developer'
require 'models/reply'
@@ -64,7 +64,7 @@ def after_find(record)
end
end
-class LifecycleTest < ActiveSupport::TestCase
+class LifecycleTest < ActiveRecord::TestCase
fixtures :topics, :developers
def test_before_destroy
View
6 activerecord/test/cases/locking_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit'
+require "cases/helper"
require 'models/person'
require 'models/reader'
require 'models/legacy_thing'
@@ -14,7 +14,7 @@ class ReadonlyFirstNamePerson < Person
attr_readonly :first_name
end
-class OptimisticLockingTest < ActiveSupport::TestCase
+class OptimisticLockingTest < ActiveRecord::TestCase
fixtures :people, :legacy_things
# need to disable transactional fixtures, because otherwise the sqlite3
@@ -176,7 +176,7 @@ def counter_test(model, expected_count)
# TODO: The SQL Server, Sybase, and OpenBase adapters currently have no support for pessimistic locking
unless current_adapter?(:SQLServerAdapter, :SybaseAdapter, :OpenBaseAdapter)
- class PessimisticLockingTest < ActiveSupport::TestCase
+ class PessimisticLockingTest < ActiveRecord::TestCase
self.use_transactional_fixtures = false
fixtures :people, :readers
View
14 activerecord/test/cases/method_scoping_test.rb
@@ -1,11 +1,11 @@
-require 'abstract_unit'
+require "cases/helper"
require 'models/developer'
require 'models/project'
require 'models/comment'
require 'models/post'
require 'models/category'
-class MethodScopingTest < ActiveSupport::TestCase
+class MethodScopingTest < ActiveRecord::TestCase
fixtures :developers, :projects, :comments, :posts
def test_set_conditions
@@ -125,7 +125,7 @@ def test_ensure_that_method_scoping_is_correctly_restored
end
end
-class NestedScopingTest < ActiveSupport::TestCase
+class NestedScopingTest < ActiveRecord::TestCase
fixtures :developers, :projects, :comments, :posts
def test_merge_options
@@ -313,7 +313,7 @@ def test_ensure_that_method_scoping_is_correctly_restored
end
end
-class HasManyScopingTest< ActiveSupport::TestCase
+class HasManyScopingTest< ActiveRecord::TestCase
fixtures :comments, :posts
def setup
@@ -343,7 +343,7 @@ def test_nested_scope
end
-class HasAndBelongsToManyScopingTest< ActiveSupport::TestCase
+class HasAndBelongsToManyScopingTest< ActiveRecord::TestCase
fixtures :posts, :categories, :categories_posts
def setup
@@ -373,7 +373,7 @@ def test_nested_scope
# We disabled the scoping for has_one and belongs_to as we can't think of a proper use case
-class BelongsToScopingTest< ActiveSupport::TestCase
+class BelongsToScopingTest< ActiveRecord::TestCase
fixtures :comments, :posts
def setup
@@ -393,7 +393,7 @@ def test_forwarding_to_dynamic_finders
end
-class HasOneScopingTest< ActiveSupport::TestCase
+class HasOneScopingTest< ActiveRecord::TestCase
fixtures :comments, :posts
def setup
View
49 activerecord/test/cases/migration_test.rb
@@ -1,11 +1,12 @@
-require 'abstract_unit'
+require "cases/helper"
require 'bigdecimal/util'
require 'models/person'
require 'models/topic'
-require 'migrations/valid/1_people_have_last_names'
-require 'migrations/valid/2_we_need_reminders'
-require 'migrations/decimal/1_give_me_big_numbers'
+
+require MIGRATIONS_ROOT + "/valid/1_people_have_last_names"
+require MIGRATIONS_ROOT + "/valid/2_we_need_reminders"
+require MIGRATIONS_ROOT + "/decimal/1_give_me_big_numbers"
if ActiveRecord::Base.connection.supports_migrations?
class BigNumber < ActiveRecord::Base; end
@@ -22,7 +23,7 @@ def puts(text="")
end
end
- class MigrationTest < ActiveSupport::TestCase
+ class MigrationTest < ActiveRecord::TestCase
self.use_transactional_fixtures = false
fixtures :people
@@ -695,7 +696,7 @@ def test_migrator
assert !Person.column_methods_hash.include?(:last_name)
assert !Reminder.table_exists?
- ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/../migrations/valid')
+ ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/valid")
assert_equal 3, ActiveRecord::Migrator.current_version
Person.reset_column_information
@@ -703,7 +704,7 @@ def test_migrator
assert Reminder.create("content" => "hello world", "remind_at" => Time.now)
assert_equal "hello world", Reminder.find(:first).content
- ActiveRecord::Migrator.down(File.dirname(__FILE__) + '/../migrations/valid')
+ ActiveRecord::Migrator.down(MIGRATIONS_ROOT + "/valid")
assert_equal 0, ActiveRecord::Migrator.current_version
Person.reset_column_information
@@ -715,22 +716,22 @@ def test_migrator_one_up
assert !Person.column_methods_hash.include?(:last_name)
assert !Reminder.table_exists?
- ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/../migrations/valid', 1)
+ ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/valid", 1)
Person.reset_column_information
assert Person.column_methods_hash.include?(:last_name)
assert !Reminder.table_exists?
- ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/../migrations/valid', 2)
+ ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/valid", 2)
assert Reminder.create("content" => "hello world", "remind_at" => Time.now)
assert_equal "hello world", Reminder.find(:first).content
end
def test_migrator_one_down
- ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/../migrations/valid')
+ ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/valid")
- ActiveRecord::Migrator.down(File.dirname(__FILE__) + '/../migrations/valid', 1)
+ ActiveRecord::Migrator.down(MIGRATIONS_ROOT + "/valid", 1)
Person.reset_column_information
assert Person.column_methods_hash.include?(:last_name)
@@ -738,39 +739,39 @@ def test_migrator_one_down
end
def test_migrator_one_up_one_down
- ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/../migrations/valid', 1)
- ActiveRecord::Migrator.down(File.dirname(__FILE__) + '/../migrations/valid', 0)
+ ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/valid", 1)
+ ActiveRecord::Migrator.down(MIGRATIONS_ROOT + "/valid", 0)
assert !Person.column_methods_hash.include?(:last_name)
assert !Reminder.table_exists?
end
def test_migrator_verbosity
- ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/../migrations/valid', 1)
+ ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/valid", 1)
assert PeopleHaveLastNames.message_count > 0
PeopleHaveLastNames.message_count = 0
- ActiveRecord::Migrator.down(File.dirname(__FILE__) + '/../migrations/valid', 0)
+ ActiveRecord::Migrator.down(MIGRATIONS_ROOT + "/valid", 0)
assert PeopleHaveLastNames.message_count > 0
PeopleHaveLastNames.message_count = 0
end
def test_migrator_verbosity_off
PeopleHaveLastNames.verbose = false
- ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/../migrations/valid', 1)
+ ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/valid", 1)
assert PeopleHaveLastNames.message_count.zero?
- ActiveRecord::Migrator.down(File.dirname(__FILE__) + '/../migrations/valid', 0)
+ ActiveRecord::Migrator.down(MIGRATIONS_ROOT + "/valid", 0)
assert PeopleHaveLastNames.message_count.zero?
end
def test_migrator_going_down_due_to_version_target
- ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/../migrations/valid', 1)
- ActiveRecord::Migrator.migrate(File.dirname(__FILE__) + '/../migrations/valid', 0)
+ ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/valid", 1)
+ ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid", 0)
assert !Person.column_methods_hash.include?(:last_name)
assert !Reminder.table_exists?
- ActiveRecord::Migrator.migrate(File.dirname(__FILE__) + '/../migrations/valid')
+ ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid")
Person.reset_column_information
assert Person.column_methods_hash.include?(:last_name)
@@ -863,16 +864,16 @@ def test_create_table_with_binary_column
def test_migrator_with_duplicates
assert_raises(ActiveRecord::DuplicateMigrationVersionError) do
- ActiveRecord::Migrator.migrate(File.dirname(__FILE__) + '/../migrations/duplicate', nil)
+ ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/duplicate", nil)
end
end
def test_migrator_with_missing_version_numbers
- ActiveRecord::Migrator.migrate(File.dirname(__FILE__) + '/../migrations/missing', 500)
+ ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/missing", 500)
assert !Person.column_methods_hash.include?(:middle_name)
assert_equal 4, ActiveRecord::Migrator.current_version
- ActiveRecord::Migrator.migrate(File.dirname(__FILE__) + '/../migrations/missing', 2)
+ ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/missing", 2)
Person.reset_column_information
assert !Reminder.table_exists?
assert Person.column_methods_hash.include?(:last_name)
@@ -918,7 +919,7 @@ def test_create_table_with_custom_sequence_name
end
uses_mocha 'Sexy migration tests' do
- class SexyMigrationsTest < ActiveSupport::TestCase
+ class SexyMigrationsTest < ActiveRecord::TestCase
def test_references_column_type_adds_id
with_new_table do |t|
t.expects(:column).with('customer_id', :integer, {})
View
4 activerecord/test/cases/migration_test_firebird.rb
@@ -1,7 +1,7 @@
-require 'abstract_unit'
+require "cases/helper"
require 'models/course'
-class FirebirdMigrationTest < ActiveSupport::TestCase
+class FirebirdMigrationTest < ActiveRecord::TestCase
self.use_transactional_fixtures = false
def setup
View
4 activerecord/test/cases/mixin_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit'
+require "cases/helper"
class Mixin < ActiveRecord::Base
end
@@ -21,7 +21,7 @@ def now_with_forcing
end
-class TouchTest < ActiveSupport::TestCase
+class TouchTest < ActiveRecord::TestCase
fixtures :mixins
def setup
View
4 activerecord/test/cases/modules_test.rb
@@ -1,7 +1,7 @@
-require 'abstract_unit'
+require "cases/helper"
require 'models/company_in_module'
-class ModulesTest < ActiveSupport::TestCase
+class ModulesTest < ActiveRecord::TestCase
fixtures :accounts, :companies, :projects, :developers
def test_module_spanning_associations
View
4 activerecord/test/cases/multiple_db_test.rb
@@ -1,10 +1,10 @@
-require 'abstract_unit'
+require "cases/helper"
require 'models/entrant'
# So we can test whether Course.connection survives a reload.
require_dependency 'models/course'
-class MultipleDbTest < ActiveSupport::TestCase
+class MultipleDbTest < ActiveRecord::TestCase
self.use_transactional_fixtures = false
def setup
View
4 activerecord/test/cases/pk_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit'
+require "cases/helper"
require 'models/topic'
require 'models/reply'
require 'models/subscriber'
@@ -6,7 +6,7 @@
require 'models/keyboard'
require 'models/mixed_case_monkey'
-class PrimaryKeysTest < ActiveSupport::TestCase
+class PrimaryKeysTest < ActiveRecord::TestCase
fixtures :topics, :subscribers, :movies, :mixed_case_monkeys
def test_integer_key
View
6 activerecord/test/cases/query_cache_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit'
+require "cases/helper"
require 'models/topic'
require 'models/reply'
require 'models/task'
@@ -7,7 +7,7 @@
require 'models/post'
-class QueryCacheTest < ActiveSupport::TestCase
+class QueryCacheTest < ActiveRecord::TestCase
fixtures :tasks, :topics, :categories, :posts, :categories_posts
def test_find_queries
@@ -57,7 +57,7 @@ def test_cache_does_not_wrap_string_results_in_arrays
uses_mocha 'QueryCacheExpiryTest' do
-class QueryCacheExpiryTest < ActiveSupport::TestCase
+class QueryCacheExpiryTest < ActiveRecord::TestCase
fixtures :tasks
def test_find
View
4 activerecord/test/cases/readonly_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit'
+require "cases/helper"
require 'models/post'
require 'models/comment'
require 'models/developer'
@@ -11,7 +11,7 @@ def Comment.foo() find :first end
def Project.foo() find :first end
-class ReadOnlyTest < ActiveSupport::TestCase
+class ReadOnlyTest < ActiveRecord::TestCase
fixtures :posts, :comments, :developers, :projects, :developers_projects
def test_cant_save_readonly_record
View
4 activerecord/test/cases/reflection_test.rb
@@ -1,11 +1,11 @@
-require 'abstract_unit'
+require "cases/helper"
require 'models/topic'
require 'models/customer'
require 'models/company'
require 'models/company_in_module'
require 'models/subscriber'
-class ReflectionTest < ActiveSupport::TestCase
+class ReflectionTest < ActiveRecord::TestCase
fixtures :topics, :customers, :companies, :subscribers
def setup
View
7 activerecord/test/cases/reserved_word_test_mysql.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit'
+require "cases/helper"
class Group < ActiveRecord::Base
Group.table_name = 'group'
@@ -23,7 +23,7 @@ class Distinct < ActiveRecord::Base
# a suite of tests to ensure the ConnectionAdapters#MysqlAdapter can handle tables with
# reserved word names (ie: group, order, values, etc...)
-class MysqlReservedWordTest < ActiveSupport::TestCase
+class MysqlReservedWordTest < ActiveRecord::TestCase
def setup
@connection = ActiveRecord::Base.connection
@@ -156,8 +156,7 @@ def test_associations_work_with_reserved_words
private
# custom fixture loader, uses Fixtures#create_fixtures and appends base_path to the current file's path
def create_test_fixtures(*fixture_names)
- fixture_path = "./test/fixtures/reserved_words"
- Fixtures.create_fixtures(fixture_path, fixture_names)
+ Fixtures.create_fixtures(FIXTURES_ROOT + "/reserved_words", fixture_names)
end
# custom drop table, uses execute on connection to drop a table if it exists. note: escapes table_name
View
4 activerecord/test/cases/schema_authorization_test_postgresql.rb
@@ -1,9 +1,9 @@
-require 'abstract_unit'
+require "cases/helper"
class SchemaThing < ActiveRecord::Base
end
-class SchemaAuthorizationTest < ActiveSupport::TestCase
+class SchemaAuthorizationTest < ActiveRecord::TestCase
self.use_transactional_fixtures = false
TABLE_NAME = 'schema_things'
View
4 activerecord/test/cases/schema_dumper_test.rb
@@ -1,10 +1,10 @@
-require 'abstract_unit'
+require "cases/helper"
require 'active_record/schema_dumper'
require 'stringio'
if ActiveRecord::Base.connection.respond_to?(:tables)
- class SchemaDumperTest < ActiveSupport::TestCase
+ class SchemaDumperTest < ActiveRecord::TestCase
def standard_dump
stream = StringIO.new
ActiveRecord::SchemaDumper.ignore_tables = []
View
4 activerecord/test/cases/schema_test_postgresql.rb
@@ -1,6 +1,6 @@
-require 'abstract_unit'
+require "cases/helper"
-class SchemaTest < ActiveSupport::TestCase
+class SchemaTest < ActiveRecord::TestCase
self.use_transactional_fixtures = false
SCHEMA_NAME = 'test_schema'
View
4 activerecord/test/cases/serialization_test.rb
@@ -1,7 +1,7 @@
-require 'abstract_unit'
+require "cases/helper"
require 'models/contact'
-class SerializationTest < ActiveSupport::TestCase
+class SerializationTest < ActiveRecord::TestCase
FORMATS = [ :xml, :json ]
def setup
View
4 activerecord/test/cases/synonym_test_oracle.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit'
+require "cases/helper"
require 'models/topic'
require 'models/subject'
@@ -6,7 +6,7 @@
# the "subjects" table in Oracle (defined in oci.sql) is just
# a synonym to the "topics" table
-class TestOracleSynonym < ActiveSupport::TestCase
+class TestOracleSynonym < ActiveRecord::TestCase
def test_oracle_synonym
topic = Topic.new
View
4 activerecord/test/cases/table_name_test_sqlserver.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit'
+require "cases/helper"
require 'active_record/schema'
if ActiveRecord::Base.connection.supports_migrations?
@@ -6,7 +6,7 @@ class Order < ActiveRecord::Base
self.table_name = '[order]'
end
- class TableNameTest < ActiveSupport::TestCase
+ class TableNameTest < ActiveRecord::TestCase
self.use_transactional_fixtures = false
# Ensures Model.columns works when using SQLServer escape characters.
View
4 activerecord/test/cases/threaded_connections_test.rb
@@ -1,9 +1,9 @@
-require 'abstract_unit'
+require "cases/helper"
require 'models/topic'
require 'models/reply'
unless %w(FrontBase).include? ActiveRecord::Base.connection.adapter_name
- class ThreadedConnectionsTest < ActiveSupport::TestCase
+ class ThreadedConnectionsTest < ActiveRecord::TestCase
self.use_transactional_fixtures = false
fixtures :topics
View
4 activerecord/test/cases/transactions_test.rb
@@ -1,9 +1,9 @@
-require 'abstract_unit'
+require "cases/helper"
require 'models/topic'
require 'models/reply'
require 'models/developer'
-class TransactionTest < ActiveSupport::TestCase
+class TransactionTest < ActiveRecord::TestCase
self.use_transactional_fixtures = false
fixtures :topics, :developers
View
4 activerecord/test/cases/unconnected_test.rb
@@ -1,9 +1,9 @@
-require 'abstract_unit'
+require "cases/helper"
class TestRecord < ActiveRecord::Base
end
-class TestUnconnectedAdapter < ActiveSupport::TestCase
+class TestUnconnectedAdapter < ActiveRecord::TestCase
self.use_transactional_fixtures = false
def setup
View
6 activerecord/test/cases/validations_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit'
+require "cases/helper"
require 'models/topic'
require 'models/reply'
require 'models/person'
@@ -54,7 +54,7 @@ class Conjurer < IneptWizard
class Thaumaturgist < IneptWizard
end
-class ValidationsTest < ActiveSupport::TestCase
+class ValidationsTest < ActiveRecord::TestCase
fixtures :topics, :developers, 'warehouse-things'
def setup
@@ -1281,7 +1281,7 @@ def with_kcode(kcode)
end
-class ValidatesNumericalityTest < ActiveSupport::TestCase
+class ValidatesNumericalityTest < ActiveRecord::TestCase
NIL = [nil]
BLANK = ["", " ", " \t \r \n"]
BIGDECIMAL_STRINGS = %w(12345678901234567890.1234567890) # 30 significent digits
View
10 activerecord/test/cases/xml_serialization_test.rb
@@ -1,11 +1,11 @@
-require 'abstract_unit'
+require "cases/helper"
require 'models/contact'
require 'models/post'
require 'models/author'
require 'models/tagging'
require 'models/comment'
-class XmlSerializationTest < ActiveSupport::TestCase
+class XmlSerializationTest < ActiveRecord::TestCase
def test_should_serialize_default_root
@xml = Contact.new.to_xml
assert_match %r{^<contact>}, @xml
@@ -40,7 +40,7 @@ def test_should_include_yielded_additions
end
end
-class DefaultXmlSerializationTest < ActiveSupport::TestCase
+class DefaultXmlSerializationTest < ActiveRecord::TestCase
def setup
@xml = Contact.new(:name => 'aaron stack', :age => 25, :avatar => 'binarydata', :created_at => Time.utc(2006, 8, 1), :awesome => false, :preferences => { :gem => 'ruby' }).to_xml
end
@@ -72,7 +72,7 @@ def test_should_serialize_yaml
end
end
-class NilXmlSerializationTest < ActiveSupport::TestCase
+class NilXmlSerializationTest < ActiveRecord::TestCase
def setup
@xml = Contact.new.to_xml(:root => 'xml_contact')
end
@@ -118,7 +118,7 @@ def test_should_serialize_yaml
end
end
-class DatabaseConnectedXmlSerializationTest < ActiveSupport::TestCase
+class DatabaseConnectedXmlSerializationTest < ActiveRecord::TestCase
fixtures :authors, :posts
# to_xml used to mess with the hash the user provided which
# caused the builder to be reused. This meant the document kept
View
5 activerecord/test/config.rb
@@ -0,0 +1,5 @@
+TEST_ROOT = File.expand_path(File.dirname(__FILE__))
+ASSETS_ROOT = TEST_ROOT + "/assets"
+FIXTURES_ROOT = TEST_ROOT + "/fixtures"
+MIGRATIONS_ROOT = TEST_ROOT + "/migrations"
+SCHEMA_ROOT = TEST_ROOT + "/schema"
View
2  activerecord/test/connections/native_sqlite/connection.rb
@@ -6,7 +6,7 @@
class SqliteError < StandardError
end
-BASE_DIR = File.expand_path(File.dirname(__FILE__) + '/../../fixtures')
+BASE_DIR = FIXTURES_ROOT
sqlite_test_db = "#{BASE_DIR}/fixture_database.sqlite"
sqlite_test_db2 = "#{BASE_DIR}/fixture_database_2.sqlite"
View
2  activerecord/test/connections/native_sqlite3/connection.rb
@@ -6,7 +6,7 @@
class SqliteError < StandardError
end
-BASE_DIR = File.expand_path(File.dirname(__FILE__) + '/../../fixtures')
+BASE_DIR = FIXTURES_ROOT
sqlite_test_db = "#{BASE_DIR}/fixture_database.sqlite3"
sqlite_test_db2 = "#{BASE_DIR}/fixture_database_2.sqlite3"
View
4 activerecord/test/connections/native_sqlite3/in_memory_connection.rb
@@ -8,11 +8,11 @@ class SqliteError < StandardError
def make_connection(clazz, db_definitions_file)
clazz.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
- File.read("#{File.dirname(__FILE__)}/../../schema/#{db_definitions_file}").split(';').each do |command|
+ File.read(SCHEMA_ROOT + "/#{db_definitions_file}").split(';').each do |command|
clazz.connection.execute(command) unless command.strip.empty?
end
end
make_connection(ActiveRecord::Base, 'sqlite.sql')
make_connection(Course, 'sqlite2.sql')
-load("#{File.dirname(__FILE__)}/../../schema/schema.rb")
+load(SCHEMA_ROOT + "/schema.rb")
View
1  activerecord/test/fixtures/.gitignore
@@ -0,0 +1 @@
+*.sqlite*
Please sign in to comment.
Something went wrong with that request. Please try again.