Browse files

* Continue evolution toward ActiveSupport::TestCase and friends. #10679

… [Josh Peek]

* TestCase: introduce declared setup and teardown callbacks. Pass a list of methods and an optional block to call before setup or after teardown. Setup callbacks are run in the order declared; teardown callbacks are run in reverse.  [Jeremy Kemper]


git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8570 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent fe66397 commit 139b92495fa7697cdd619c549d4c7b263562b761 @jeremy jeremy committed Jan 5, 2008
Showing with 393 additions and 260 deletions.
  1. +14 −22 actionmailer/lib/action_mailer/test_case.rb
  2. +2 −8 actionmailer/test/test_helper_test.rb
  3. +12 −20 actionpack/lib/action_controller/test_case.rb
  4. +1 −0 actionpack/lib/action_controller/test_process.rb
  5. +1 −1 actionpack/test/active_record_unit.rb
  6. +1 −10 actionpack/test/controller/test_test.rb
  7. +67 −82 activerecord/lib/active_record/fixtures.rb
  8. +1 −1 activerecord/test/aaa_create_tables_test.rb
  9. +1 −1 activerecord/test/abstract_unit.rb
  10. +1 −1 activerecord/test/active_schema_test_mysql.rb
  11. +1 −1 activerecord/test/adapter_test.rb
  12. +1 −1 activerecord/test/adapter_test_sqlserver.rb
  13. +2 −2 activerecord/test/aggregations_test.rb
  14. +1 −1 activerecord/test/ar_schema_test.rb
  15. +1 −1 activerecord/test/association_inheritance_reload.rb
  16. +1 −1 activerecord/test/associations/callbacks_test.rb
  17. +2 −2 activerecord/test/associations/cascaded_eager_loading_test.rb
  18. +1 −1 activerecord/test/associations/eager_singularization_test.rb
  19. +1 −1 activerecord/test/associations/eager_test.rb
  20. +1 −1 activerecord/test/associations/extension_test.rb
  21. +1 −1 activerecord/test/associations/inner_join_association_test.rb
  22. +1 −1 activerecord/test/associations/join_model_test.rb
  23. +7 −7 activerecord/test/associations_test.rb
  24. +1 −1 activerecord/test/attribute_methods_test.rb
  25. +1 −1 activerecord/test/base_test.rb
  26. +1 −1 activerecord/test/binary_test.rb
  27. +1 −1 activerecord/test/calculations_test.rb
  28. +1 −1 activerecord/test/callbacks_test.rb
  29. +1 −1 activerecord/test/class_inheritable_attributes_test.rb
  30. +1 −1 activerecord/test/column_alias_test.rb
  31. +1 −1 activerecord/test/connection_test_firebird.rb
  32. +1 −1 activerecord/test/connection_test_mysql.rb
  33. +1 −1 activerecord/test/copy_table_test_sqlite.rb
  34. +1 −1 activerecord/test/datatype_test_postgresql.rb
  35. +1 −1 activerecord/test/date_time_test.rb
  36. +1 −1 activerecord/test/default_test_firebird.rb
  37. +1 −1 activerecord/test/defaults_test.rb
  38. +1 −1 activerecord/test/deprecated_finder_test.rb
  39. +1 −1 activerecord/test/finder_test.rb
  40. +24 −24 activerecord/test/fixtures_test.rb
  41. +2 −2 activerecord/test/inheritance_test.rb
  42. +2 −2 activerecord/test/json_serialization_test.rb
  43. +1 −1 activerecord/test/lifecycle_test.rb
  44. +2 −2 activerecord/test/locking_test.rb
  45. +6 −6 activerecord/test/method_scoping_test.rb
  46. +2 −2 activerecord/test/migration_test.rb
  47. +1 −1 activerecord/test/migration_test_firebird.rb
  48. +1 −1 activerecord/test/mixin_test.rb
  49. +1 −1 activerecord/test/modules_test.rb
  50. +1 −1 activerecord/test/multiple_db_test.rb
  51. +1 −1 activerecord/test/pk_test.rb
  52. +2 −2 activerecord/test/query_cache_test.rb
  53. +1 −1 activerecord/test/readonly_test.rb
  54. +1 −1 activerecord/test/reflection_test.rb
  55. +1 −1 activerecord/test/reserved_word_test_mysql.rb
  56. +1 −1 activerecord/test/schema_authorization_test_postgresql.rb
  57. +1 −1 activerecord/test/schema_dumper_test.rb
  58. +1 −1 activerecord/test/schema_test_postgresql.rb
  59. +1 −1 activerecord/test/serialization_test.rb
  60. +1 −1 activerecord/test/synonym_test_oracle.rb
  61. +1 −1 activerecord/test/table_name_test_sqlserver.rb
  62. +1 −1 activerecord/test/threaded_connections_test.rb
  63. +1 −1 activerecord/test/transactions_test.rb
  64. +1 −1 activerecord/test/unconnected_test.rb
  65. +2 −2 activerecord/test/validations_test.rb
  66. +4 −4 activerecord/test/xml_serialization_test.rb
  67. +4 −0 activesupport/CHANGELOG
  68. +0 −3 activesupport/lib/active_support.rb
  69. +10 −2 activesupport/lib/active_support/test_case.rb
  70. +0 −1 activesupport/lib/active_support/testing.rb
  71. +3 −6 activesupport/lib/active_support/testing/default.rb
  72. +127 −0 activesupport/lib/active_support/testing/setup_and_teardown.rb
  73. +1 −1 activesupport/test/core_ext/{load_error_tests.rb → load_error_test.rb}
  74. +46 −0 activesupport/test/test_test.rb
View
36 actionmailer/lib/action_mailer/test_case.rb
@@ -8,11 +8,13 @@ def initialize(name)
"test case definition"
end
end
- # New Test Super class for forward compatibility.
- # To override
+
class TestCase < ActiveSupport::TestCase
include ActionMailer::Quoting
+ setup :initialize_test_deliveries
+ setup :set_expected_mail
+
class << self
def tests(mailer)
write_inheritable_attribute(:mailer_class, mailer)
@@ -33,28 +35,18 @@ def determine_default_mailer(name)
end
end
- def setup_with_mailer
- ActionMailer::Base.delivery_method = :test
- ActionMailer::Base.perform_deliveries = true
- ActionMailer::Base.deliveries = []
-
- @expected = TMail::Mail.new
- @expected.set_content_type "text", "plain", { "charset" => charset }
- @expected.mime_version = '1.0'
- end
- alias_method :setup, :setup_with_mailer
+ protected
+ def initialize_test_deliveries
+ ActionMailer::Base.delivery_method = :test
+ ActionMailer::Base.perform_deliveries = true
+ ActionMailer::Base.deliveries = []
+ end
- def self.method_added(method)
- if method.to_s == 'setup'
- unless method_defined?(:setup_without_mailer)
- alias_method :setup_without_mailer, :setup
- define_method(:setup) do
- setup_with_mailer
- setup_without_mailer
- end
- end
+ def set_expected_mail
+ @expected = TMail::Mail.new
+ @expected.set_content_type "text", "plain", { "charset" => charset }
+ @expected.mime_version = '1.0'
end
- end
private
def charset
View
10 actionmailer/test/test_helper_test.rb
@@ -9,7 +9,6 @@ def test
end
class TestHelperMailerTest < ActionMailer::TestCase
-
def test_setup_sets_right_action_mailer_options
assert_equal :test, ActionMailer::Base.delivery_method
assert ActionMailer::Base.perform_deliveries
@@ -117,19 +116,14 @@ def test_assert_no_emails_failure
end
class AnotherTestHelperMailerTest < ActionMailer::TestCase
-
tests TestHelperMailer
def setup
- # Should not override ActionMailer setup methods
@test_var = "a value"
end
- def test_should_still_setup_mailer
+ def test_setup_shouldnt_conflict_with_mailer_setup
assert @expected.is_a?(TMail::Mail)
- end
-
- def test_should_run_overridden_setup_method
- assert @test_var
+ assert_equal 'a value', @test_var
end
end
View
32 actionpack/lib/action_controller/test_case.rb
@@ -10,7 +10,16 @@ def initialize(name)
end
class TestCase < ActiveSupport::TestCase
+ module RaiseActionExceptions
+ def rescue_action(e)
+ raise e
+ end
+ end
+
+ setup :setup_controller_request_and_response
+
@@controller_class = nil
+
class << self
def tests(controller_class)
self.controller_class = controller_class
@@ -25,7 +34,7 @@ def controller_class
if current_controller_class = read_inheritable_attribute(:controller_class)
current_controller_class
else
- self.controller_class= determine_default_controller_class(name)
+ self.controller_class = determine_default_controller_class(name)
end
end
@@ -36,31 +45,14 @@ def determine_default_controller_class(name)
end
def prepare_controller_class(new_class)
- new_class.class_eval do
- def rescue_action(e)
- raise e
- end
- end
+ new_class.send :include, RaiseActionExceptions
end
end
- def setup_with_controller
+ def setup_controller_request_and_response
@controller = self.class.controller_class.new
@request = TestRequest.new
@response = TestResponse.new
end
- alias_method :setup, :setup_with_controller
-
- def self.method_added(method)
- if method.to_s == 'setup'
- unless method_defined?(:setup_without_controller)
- alias_method :setup_without_controller, :setup
- define_method(:setup) do
- setup_with_controller
- setup_without_controller
- end
- end
- end
- end
end
end
View
1 actionpack/lib/action_controller/test_process.rb
@@ -1,4 +1,5 @@
require 'action_controller/assertions'
+require 'action_controller/test_case'
module ActionController #:nodoc:
class Base
View
2 actionpack/test/active_record_unit.rb
@@ -84,7 +84,7 @@ def require_fixture_models
end
end
-class ActiveRecordTestCase < Test::Unit::TestCase
+class ActiveRecordTestCase < ActiveSupport::TestCase
# Set our fixture path
if ActiveRecordTestConnector.able_to_connect
self.fixture_path = "#{File.dirname(__FILE__)}/fixtures/"
View
11 actionpack/test/controller/test_test.rb
@@ -613,18 +613,9 @@ def determine_class(name)
end
end
-class ContentControllerTest < ActionController::TestCase
- def setup
- # Should not override ActionController setup methods
- end
-
- def test_should_still_setup_controller
- assert_kind_of(ContentController, @controller)
- end
-end
-
class CrazyNameTest < ActionController::TestCase
tests ContentController
+
def test_controller_class_can_be_set_manually_not_just_inferred
assert_equal ContentController, self.class.controller_class
end
View
149 activerecord/lib/active_record/fixtures.rb
@@ -1,11 +1,14 @@
require 'erb'
require 'yaml'
require 'csv'
+require 'active_support/test_case'
-module YAML #:nodoc:
- class Omap #:nodoc:
- def keys; map { |k, v| k } end
- def values; map { |k, v| v } end
+if RUBY_VERSION < '1.9'
+ module YAML #:nodoc:
+ class Omap #:nodoc:
+ def keys; map { |k, v| k } end
+ def values; map { |k, v| v } end
+ end
end
end
@@ -29,7 +32,7 @@ class FixtureClassNotFound < StandardError #:nodoc:
# in a non-verbose, human-readable format. It ships with Ruby 1.8.1+.
#
# Unlike single-file fixtures, YAML fixtures are stored in a single file per model, which are placed in the directory appointed
-# by <tt>Test::Unit::TestCase.fixture_path=(path)</tt> (this is automatically configured for Rails, so you can just
+# by <tt>ActiveSupport::TestCase.fixture_path=(path)</tt> (this is automatically configured for Rails, so you can just
# put your files in <your-rails-app>/test/fixtures/). The fixture file ends with the .yml file extension (Rails example:
# "<your-rails-app>/test/fixtures/web_sites.yml"). The format of a YAML fixture file looks like this:
#
@@ -89,7 +92,7 @@ class FixtureClassNotFound < StandardError #:nodoc:
#
# This type of fixture was the original format for Active Record that has since been deprecated in favor of the YAML and CSV formats.
# Fixtures for this format are created by placing text files in a sub-directory (with the name of the model) to the directory
-# appointed by <tt>Test::Unit::TestCase.fixture_path=(path)</tt> (this is automatically configured for Rails, so you can just
+# appointed by <tt>ActiveSupport::TestCase.fixture_path=(path)</tt> (this is automatically configured for Rails, so you can just
# put your files in <your-rails-app>/test/fixtures/<your-model-name>/ -- like <your-rails-app>/test/fixtures/web_sites/ for the WebSite
# model).
#
@@ -115,7 +118,7 @@ class FixtureClassNotFound < StandardError #:nodoc:
#
# require 'web_site'
#
-# class WebSiteTest < Test::Unit::TestCase
+# class WebSiteTest < ActiveSupport::TestCase
# def test_web_site_count
# assert_equal 2, WebSite.count
# end
@@ -125,7 +128,7 @@ class FixtureClassNotFound < StandardError #:nodoc:
# easiest way to add fixtures to the database:
#
# ...
-# class WebSiteTest < Test::Unit::TestCase
+# class WebSiteTest < ActiveSupport::TestCase
# fixtures :web_sites # add more by separating the symbols with commas
# ...
#
@@ -191,7 +194,7 @@ class FixtureClassNotFound < StandardError #:nodoc:
# TestCases can use begin+rollback to isolate their changes to the database instead of having to delete+insert for every test case.
# They can also turn off auto-instantiation of fixture data since the feature is costly and often unused.
#
-# class FooTest < Test::Unit::TestCase
+# class FooTest < ActiveSupport::TestCase
# self.use_transactional_fixtures = true
# self.use_instantiated_fixtures = false
#
@@ -842,6 +845,9 @@ def read_fixture_file(fixture_file_path)
module Test #:nodoc:
module Unit #:nodoc:
class TestCase #:nodoc:
+ setup :setup_fixtures
+ teardown :teardown_fixtures
+
superclass_delegating_accessor :fixture_path
superclass_delegating_accessor :fixture_table_names
superclass_delegating_accessor :fixture_class_names
@@ -857,77 +863,79 @@ class TestCase #:nodoc:
@@already_loaded_fixtures = {}
self.fixture_class_names = {}
- def self.set_fixture_class(class_names = {})
- self.fixture_class_names = self.fixture_class_names.merge(class_names)
- end
-
- def self.fixtures(*table_names)
- if table_names.first == :all
- table_names = Dir["#{fixture_path}/*.yml"] + Dir["#{fixture_path}/*.csv"]
- table_names.map! { |f| File.basename(f).split('.')[0..-2].join('.') }
- else
- table_names = table_names.flatten.map { |n| n.to_s }
+ class << self
+ def set_fixture_class(class_names = {})
+ self.fixture_class_names = self.fixture_class_names.merge(class_names)
end
- self.fixture_table_names |= table_names
- require_fixture_classes(table_names)
- setup_fixture_accessors(table_names)
- end
+ def fixtures(*table_names)
+ if table_names.first == :all
+ table_names = Dir["#{fixture_path}/*.yml"] + Dir["#{fixture_path}/*.csv"]
+ table_names.map! { |f| File.basename(f).split('.')[0..-2].join('.') }
+ else
+ table_names = table_names.flatten.map { |n| n.to_s }
+ end
- def self.require_fixture_classes(table_names = nil)
- (table_names || fixture_table_names).each do |table_name|
- file_name = table_name.to_s
- file_name = file_name.singularize if ActiveRecord::Base.pluralize_table_names
- begin
- require_dependency file_name
- rescue LoadError
- # Let's hope the developer has included it himself
+ self.fixture_table_names |= table_names
+ require_fixture_classes(table_names)
+ setup_fixture_accessors(table_names)
+ end
+
+ def require_fixture_classes(table_names = nil)
+ (table_names || fixture_table_names).each do |table_name|
+ file_name = table_name.to_s
+ file_name = file_name.singularize if ActiveRecord::Base.pluralize_table_names
+ begin
+ require_dependency file_name
+ rescue LoadError
+ # Let's hope the developer has included it himself
+ end
end
end
- end
- def self.setup_fixture_accessors(table_names = nil)
- table_names = [table_names] if table_names && !table_names.respond_to?(:each)
- (table_names || fixture_table_names).each do |table_name|
- table_name = table_name.to_s.tr('.', '_')
+ def setup_fixture_accessors(table_names = nil)
+ table_names = [table_names] if table_names && !table_names.respond_to?(:each)
+ (table_names || fixture_table_names).each do |table_name|
+ table_name = table_name.to_s.tr('.', '_')
- define_method(table_name) do |*fixtures|
- force_reload = fixtures.pop if fixtures.last == true || fixtures.last == :reload
+ define_method(table_name) do |*fixtures|
+ force_reload = fixtures.pop if fixtures.last == true || fixtures.last == :reload
- @fixture_cache[table_name] ||= {}
+ @fixture_cache[table_name] ||= {}
- instances = fixtures.map do |fixture|
- @fixture_cache[table_name].delete(fixture) if force_reload
+ instances = fixtures.map do |fixture|
+ @fixture_cache[table_name].delete(fixture) if force_reload
- if @loaded_fixtures[table_name][fixture.to_s]
- @fixture_cache[table_name][fixture] ||= @loaded_fixtures[table_name][fixture.to_s].find
- else
- raise StandardError, "No fixture with name '#{fixture}' found for table '#{table_name}'"
+ if @loaded_fixtures[table_name][fixture.to_s]
+ @fixture_cache[table_name][fixture] ||= @loaded_fixtures[table_name][fixture.to_s].find
+ else
+ raise StandardError, "No fixture with name '#{fixture}' found for table '#{table_name}'"
+ end
end
- end
- instances.size == 1 ? instances.first : instances
+ instances.size == 1 ? instances.first : instances
+ end
end
end
- end
- def self.uses_transaction(*methods)
- @uses_transaction = [] unless defined?(@uses_transaction)
- @uses_transaction.concat methods.map(&:to_s)
- end
+ def uses_transaction(*methods)
+ @uses_transaction = [] unless defined?(@uses_transaction)
+ @uses_transaction.concat methods.map(&:to_s)
+ end
- def self.uses_transaction?(method)
- @uses_transaction = [] unless defined?(@uses_transaction)
- @uses_transaction.include?(method.to_s)
+ def uses_transaction?(method)
+ @uses_transaction = [] unless defined?(@uses_transaction)
+ @uses_transaction.include?(method.to_s)
+ end
end
def use_transactional_fixtures?
use_transactional_fixtures &&
!self.class.uses_transaction?(method_name)
end
- def setup_with_fixtures
- return unless defined?(ActiveRecord::Base) && !ActiveRecord::Base.configurations.blank?
+ def setup_fixtures
+ return unless defined?(ActiveRecord) && !ActiveRecord::Base.configurations.blank?
if pre_loaded_fixtures && !use_transactional_fixtures
raise RuntimeError, 'pre_loaded_fixtures requires use_transactional_fixtures'
@@ -955,10 +963,9 @@ def setup_with_fixtures
# Instantiate fixtures for every test if requested.
instantiate_fixtures if use_instantiated_fixtures
end
- alias_method :setup, :setup_with_fixtures
- def teardown_with_fixtures
- return unless defined?(ActiveRecord::Base) && !ActiveRecord::Base.configurations.blank?
+ def teardown_fixtures
+ return unless defined?(ActiveRecord) && !ActiveRecord::Base.configurations.blank?
unless use_transactional_fixtures?
Fixtures.reset_cache
@@ -971,28 +978,6 @@ def teardown_with_fixtures
end
ActiveRecord::Base.verify_active_connections!
end
- alias_method :teardown, :teardown_with_fixtures
-
- def self.method_added(method)
- case method.to_s
- when 'setup'
- unless method_defined?(:setup_without_fixtures)
- alias_method :setup_without_fixtures, :setup
- define_method(:setup) do
- setup_with_fixtures
- setup_without_fixtures
- end
- end
- when 'teardown'
- unless method_defined?(:teardown_without_fixtures)
- alias_method :teardown_without_fixtures, :teardown
- define_method(:teardown) do
- teardown_without_fixtures
- teardown_with_fixtures
- end
- end
- end
- end
private
def load_fixtures
View
2 activerecord/test/aaa_create_tables_test.rb
@@ -1,7 +1,7 @@
# The filename begins with "aaa" to ensure this is the first test.
require 'abstract_unit'
-class AAACreateTablesTest < Test::Unit::TestCase
+class AAACreateTablesTest < ActiveSupport::TestCase
self.use_transactional_fixtures = false
def setup
View
2 activerecord/test/abstract_unit.rb
@@ -13,7 +13,7 @@
QUOTED_TYPE = ActiveRecord::Base.connection.quote_column_name('type') unless Object.const_defined?(:QUOTED_TYPE)
-class Test::Unit::TestCase #:nodoc:
+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")
View
2 activerecord/test/active_schema_test_mysql.rb
@@ -1,6 +1,6 @@
require 'abstract_unit'
-class ActiveSchemaTest < Test::Unit::TestCase
+class ActiveSchemaTest < ActiveSupport::TestCase
def setup
ActiveRecord::ConnectionAdapters::MysqlAdapter.class_eval do
alias_method :execute_without_stub, :execute
View
2 activerecord/test/adapter_test.rb
@@ -1,6 +1,6 @@
require 'abstract_unit'
-class AdapterTest < Test::Unit::TestCase
+class AdapterTest < ActiveSupport::TestCase
def setup
@connection = ActiveRecord::Base.connection
end
View
2 activerecord/test/adapter_test_sqlserver.rb
@@ -3,7 +3,7 @@
require 'fixtures/post'
require 'fixtures/task'
-class SqlServerAdapterTest < Test::Unit::TestCase
+class SqlServerAdapterTest < ActiveSupport::TestCase
class TableWithRealColumn < ActiveRecord::Base; end
fixtures :posts, :tasks
View
4 activerecord/test/aggregations_test.rb
@@ -1,7 +1,7 @@
require 'abstract_unit'
require 'fixtures/customer'
-class AggregationsTest < Test::Unit::TestCase
+class AggregationsTest < ActiveSupport::TestCase
fixtures :customers
def test_find_single_value_object
@@ -109,7 +109,7 @@ def test_nil_assignment_results_in_nil
end
end
-class OverridingAggregationsTest < Test::Unit::TestCase
+class OverridingAggregationsTest < ActiveSupport::TestCase
class Name; end
class DifferentName; end
View
2 activerecord/test/ar_schema_test.rb
@@ -3,7 +3,7 @@
if ActiveRecord::Base.connection.supports_migrations?
- class ActiveRecordSchemaTest < Test::Unit::TestCase
+ class ActiveRecordSchemaTest < ActiveSupport::TestCase
self.use_transactional_fixtures = false
def setup
View
2 activerecord/test/association_inheritance_reload.rb
@@ -1,7 +1,7 @@
require 'abstract_unit'
require 'fixtures/company'
-class AssociationInheritanceReloadTest < Test::Unit::TestCase
+class AssociationInheritanceReloadTest < ActiveSupport::TestCase
fixtures :companies
def test_set_attributes
View
2 activerecord/test/associations/callbacks_test.rb
@@ -6,7 +6,7 @@
require 'fixtures/project'
require 'fixtures/developer'
-class AssociationCallbacksTest < Test::Unit::TestCase
+class AssociationCallbacksTest < ActiveSupport::TestCase
fixtures :posts, :authors, :projects, :developers
def setup
View
4 activerecord/test/associations/cascaded_eager_loading_test.rb
@@ -8,7 +8,7 @@
require 'fixtures/topic'
require 'fixtures/reply'
-class CascadedEagerLoadingTest < Test::Unit::TestCase
+class CascadedEagerLoadingTest < ActiveSupport::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 'fixtures/vertex'
require 'fixtures/edge'
-class CascadedEagerLoadingTest < Test::Unit::TestCase
+class CascadedEagerLoadingTest < ActiveSupport::TestCase
fixtures :edges, :vertices
def test_eager_association_loading_with_recursive_cascading_four_levels_has_many_through
View
2 activerecord/test/associations/eager_singularization_test.rb
@@ -39,7 +39,7 @@ class Compress < ActiveRecord::Base
end
-class EagerSingularizationTest < Test::Unit::TestCase
+class EagerSingularizationTest < ActiveSupport::TestCase
def setup
if ActiveRecord::Base.connection.supports_migrations?
View
2 activerecord/test/associations/eager_test.rb
@@ -7,7 +7,7 @@
require 'fixtures/person'
require 'fixtures/reader'
-class EagerAssociationTest < Test::Unit::TestCase
+class EagerAssociationTest < ActiveSupport::TestCase
fixtures :posts, :comments, :authors, :categories, :categories_posts,
:companies, :accounts, :tags, :people, :readers
View
2 activerecord/test/associations/extension_test.rb
@@ -4,7 +4,7 @@
require 'fixtures/project'
require 'fixtures/developer'
-class AssociationsExtensionsTest < Test::Unit::TestCase
+class AssociationsExtensionsTest < ActiveSupport::TestCase
fixtures :projects, :developers, :developers_projects, :comments, :posts
def test_extension_on_has_many
View
2 activerecord/test/associations/inner_join_association_test.rb
@@ -5,7 +5,7 @@
require 'fixtures/category'
require 'fixtures/categorization'
-class InnerJoinAssociationTest < Test::Unit::TestCase
+class InnerJoinAssociationTest < ActiveSupport::TestCase
fixtures :authors, :posts, :comments, :categories, :categories_posts, :categorizations
def test_construct_finder_sql_creates_inner_joins
View
2 activerecord/test/associations/join_model_test.rb
@@ -12,7 +12,7 @@
require 'fixtures/book'
require 'fixtures/citation'
-class AssociationsJoinModelTest < Test::Unit::TestCase
+class AssociationsJoinModelTest < ActiveSupport::TestCase
self.use_transactional_fixtures = false
fixtures :posts, :authors, :categories, :categorizations, :comments, :tags, :taggings, :author_favorites, :vertices, :items, :books
View
14 activerecord/test/associations_test.rb
@@ -17,7 +17,7 @@
require 'fixtures/person'
require 'fixtures/reader'
-class AssociationsTest < Test::Unit::TestCase
+class AssociationsTest < ActiveSupport::TestCase
fixtures :accounts, :companies, :developers, :projects, :developers_projects,
:computers
@@ -73,7 +73,7 @@ def test_storing_in_pstore
end
end
-class AssociationProxyTest < Test::Unit::TestCase
+class AssociationProxyTest < ActiveSupport::TestCase
fixtures :authors, :posts, :categorizations, :categories, :developers, :projects, :developers_projects
def test_proxy_accessors
@@ -166,7 +166,7 @@ def setup_dangling_association
end
end
-class HasOneAssociationsTest < Test::Unit::TestCase
+class HasOneAssociationsTest < ActiveSupport::TestCase
fixtures :accounts, :companies, :developers, :projects, :developers_projects
def setup
@@ -463,7 +463,7 @@ def test_save_still_works_after_accessing_nil_has_one
end
-class HasManyAssociationsTest < Test::Unit::TestCase
+class HasManyAssociationsTest < ActiveSupport::TestCase
fixtures :accounts, :companies, :developers, :projects,
:developers_projects, :topics, :authors, :comments
@@ -1196,7 +1196,7 @@ def test_dynamic_find_all_order_should_override_association_limit_for_through
end
-class BelongsToAssociationsTest < Test::Unit::TestCase
+class BelongsToAssociationsTest < ActiveSupport::TestCase
fixtures :accounts, :companies, :developers, :projects, :topics,
:developers_projects, :computers, :authors, :posts, :tags, :taggings
@@ -1572,7 +1572,7 @@ class DeveloperForProjectWithAfterCreateHook < ActiveRecord::Base
end
-class HasAndBelongsToManyAssociationsTest < Test::Unit::TestCase
+class HasAndBelongsToManyAssociationsTest < ActiveSupport::TestCase
fixtures :accounts, :companies, :categories, :posts, :categories_posts, :developers, :projects, :developers_projects
def test_has_and_belongs_to_many
@@ -2112,7 +2112,7 @@ def test_scoped_find_on_through_association_doesnt_return_read_only_records
end
-class OverridingAssociationsTest < Test::Unit::TestCase
+class OverridingAssociationsTest < ActiveSupport::TestCase
class Person < ActiveRecord::Base; end
class DifferentPerson < ActiveRecord::Base; end
View
2 activerecord/test/attribute_methods_test.rb
@@ -1,7 +1,7 @@
require 'abstract_unit'
require 'fixtures/topic'
-class AttributeMethodsTest < Test::Unit::TestCase
+class AttributeMethodsTest < ActiveSupport::TestCase
fixtures :topics
def setup
@old_suffixes = ActiveRecord::Base.send(:attribute_method_suffixes).dup
View
2 activerecord/test/base_test.rb
@@ -70,7 +70,7 @@ class TopicWithProtectedContentAndAccessibleAuthorName < ActiveRecord::Base
attr_protected :content
end
-class BasicsTest < Test::Unit::TestCase
+class BasicsTest < ActiveSupport::TestCase
fixtures :topics, :companies, :developers, :projects, :computers, :accounts, :minimalistics
def test_table_exists
View
2 activerecord/test/binary_test.rb
@@ -10,7 +10,7 @@
unless current_adapter?(:SQLServerAdapter, :SybaseAdapter, :DB2Adapter, :FirebirdAdapter)
require 'fixtures/binary'
- class BinaryTest < Test::Unit::TestCase
+ class BinaryTest < ActiveSupport::TestCase
FIXTURES = %w(flowers.jpg example.log)
def test_load_save
View
2 activerecord/test/calculations_test.rb
@@ -8,7 +8,7 @@ class NumericData < ActiveRecord::Base
self.table_name = 'numeric_data'
end
-class CalculationsTest < Test::Unit::TestCase
+class CalculationsTest < ActiveSupport::TestCase
fixtures :companies, :accounts, :topics
def test_should_sum_field
View
2 activerecord/test/callbacks_test.rb
@@ -126,7 +126,7 @@ def before_create
end
end
-class CallbacksTest < Test::Unit::TestCase
+class CallbacksTest < ActiveSupport::TestCase
fixtures :developers
def test_initialize
View
2 activerecord/test/class_inheritable_attributes_test.rb
@@ -19,7 +19,7 @@ class D < B
end
-class ClassInheritableAttributesTest < Test::Unit::TestCase
+class ClassInheritableAttributesTest < ActiveSupport::TestCase
def test_first_level
assert_equal [ :one, :two ], B.read_inheritable_attribute("first")
assert_equal [ :three ], C.read_inheritable_attribute("first")
View
2 activerecord/test/column_alias_test.rb
@@ -1,7 +1,7 @@
require 'abstract_unit'
require 'fixtures/topic'
-class TestColumnAlias < Test::Unit::TestCase
+class TestColumnAlias < ActiveSupport::TestCase
fixtures :topics
QUERY = if 'Oracle' == ActiveRecord::Base.connection.adapter_name
View
2 activerecord/test/connection_test_firebird.rb
@@ -1,6 +1,6 @@
require "#{File.dirname(__FILE__)}/abstract_unit"
-class FirebirdConnectionTest < Test::Unit::TestCase
+class FirebirdConnectionTest < ActiveSupport::TestCase
def test_charset_properly_set
fb_conn = ActiveRecord::Base.connection.instance_variable_get(:@connection)
assert_equal 'UTF8', fb_conn.database.character_set
View
2 activerecord/test/connection_test_mysql.rb
@@ -1,6 +1,6 @@
require "#{File.dirname(__FILE__)}/abstract_unit"
-class MysqlConnectionTest < Test::Unit::TestCase
+class MysqlConnectionTest < ActiveSupport::TestCase
def setup
@connection = ActiveRecord::Base.connection
end
View
2 activerecord/test/copy_table_test_sqlite.rb
@@ -1,6 +1,6 @@
require 'abstract_unit'
-class CopyTableTest < Test::Unit::TestCase
+class CopyTableTest < ActiveSupport::TestCase
fixtures :companies, :comments
def setup
View
2 activerecord/test/datatype_test_postgresql.rb
@@ -21,7 +21,7 @@ class PostgresqlBitString < ActiveRecord::Base
class PostgresqlOid < ActiveRecord::Base
end
-class PostgresqlDataTypeTest < Test::Unit::TestCase
+class PostgresqlDataTypeTest < ActiveSupport::TestCase
self.use_transactional_fixtures = false
def setup
View
2 activerecord/test/date_time_test.rb
@@ -2,7 +2,7 @@
require 'fixtures/topic'
require 'fixtures/task'
-class DateTimeTest < Test::Unit::TestCase
+class DateTimeTest < ActiveSupport::TestCase
def test_saves_both_date_and_time
time_values = [1807, 2, 10, 15, 30, 45]
now = DateTime.civil(*time_values)
View
2 activerecord/test/default_test_firebird.rb
@@ -1,7 +1,7 @@
require 'abstract_unit'
require 'fixtures/default'
-class DefaultTest < Test::Unit::TestCase
+class DefaultTest < ActiveSupport::TestCase
def test_default_timestamp
default = Default.new
assert_instance_of(Time, default.default_timestamp)
View
2 activerecord/test/defaults_test.rb
@@ -2,7 +2,7 @@
require 'fixtures/default'
require 'fixtures/entrant'
-class DefaultTest < Test::Unit::TestCase
+class DefaultTest < ActiveSupport::TestCase
def test_nil_defaults_for_not_null_columns
column_defaults =
if current_adapter?(:MysqlAdapter)
View
2 activerecord/test/deprecated_finder_test.rb
@@ -1,7 +1,7 @@
require 'abstract_unit'
require 'fixtures/entrant'
-class DeprecatedFinderTest < Test::Unit::TestCase
+class DeprecatedFinderTest < ActiveSupport::TestCase
fixtures :entrants
def test_deprecated_find_all_was_removed
View
2 activerecord/test/finder_test.rb
@@ -8,7 +8,7 @@
require 'fixtures/developer'
require 'fixtures/post'
-class FinderTest < Test::Unit::TestCase
+class FinderTest < ActiveSupport::TestCase
fixtures :companies, :topics, :entrants, :developers, :developers_projects, :posts, :comments, :accounts, :authors
def test_find
View
48 activerecord/test/fixtures_test.rb
@@ -16,7 +16,7 @@
require 'fixtures/matey'
require 'fixtures/ship'
-class FixturesTest < Test::Unit::TestCase
+class FixturesTest < ActiveSupport::TestCase
self.use_instantiated_fixtures = true
self.use_transactional_fixtures = false
@@ -204,7 +204,7 @@ def test_binary_in_fixtures
end
if Account.connection.respond_to?(:reset_pk_sequence!)
- class FixturesResetPkSequenceTest < Test::Unit::TestCase
+ class FixturesResetPkSequenceTest < ActiveSupport::TestCase
fixtures :accounts
fixtures :companies
@@ -250,7 +250,7 @@ def test_create_fixtures_resets_sequences_when_not_cached
end
end
-class FixturesWithoutInstantiationTest < Test::Unit::TestCase
+class FixturesWithoutInstantiationTest < ActiveSupport::TestCase
self.use_instantiated_fixtures = false
fixtures :topics, :developers, :accounts
@@ -285,7 +285,7 @@ def test_reloading_fixtures_through_accessor_methods
end
end
-class FixturesWithoutInstanceInstantiationTest < Test::Unit::TestCase
+class FixturesWithoutInstanceInstantiationTest < ActiveSupport::TestCase
self.use_instantiated_fixtures = true
self.use_instantiated_fixtures = :no_instances
@@ -299,7 +299,7 @@ def test_without_instance_instantiation
end
end
-class TransactionalFixturesTest < Test::Unit::TestCase
+class TransactionalFixturesTest < ActiveSupport::TestCase
self.use_instantiated_fixtures = true
self.use_transactional_fixtures = true
@@ -315,7 +315,7 @@ def test_destroy_just_kidding
end
end
-class MultipleFixturesTest < Test::Unit::TestCase
+class MultipleFixturesTest < ActiveSupport::TestCase
fixtures :topics
fixtures :developers, :accounts
@@ -324,7 +324,7 @@ def test_fixture_table_names
end
end
-class SetupTest < Test::Unit::TestCase
+class SetupTest < ActiveSupport::TestCase
# fixtures :topics
def setup
@@ -348,7 +348,7 @@ def test_subclassing_should_preserve_setups
end
-class OverlappingFixturesTest < Test::Unit::TestCase
+class OverlappingFixturesTest < ActiveSupport::TestCase
fixtures :topics, :developers
fixtures :developers, :accounts
@@ -357,7 +357,7 @@ def test_fixture_table_names
end
end
-class ForeignKeyFixturesTest < Test::Unit::TestCase
+class ForeignKeyFixturesTest < ActiveSupport::TestCase
fixtures :fk_test_has_pk, :fk_test_has_fk
# if foreign keys are implemented and fixtures
@@ -373,7 +373,7 @@ def test_number2
end
end
-class SetTableNameFixturesTest < Test::Unit::TestCase
+class SetTableNameFixturesTest < ActiveSupport::TestCase
set_fixture_class :funny_jokes => 'Joke'
fixtures :funny_jokes
@@ -382,7 +382,7 @@ def test_table_method
end
end
-class CustomConnectionFixturesTest < Test::Unit::TestCase
+class CustomConnectionFixturesTest < ActiveSupport::TestCase
set_fixture_class :courses => Course
fixtures :courses
@@ -392,7 +392,7 @@ def test_connection
end
end
-class InvalidTableNameFixturesTest < Test::Unit::TestCase
+class InvalidTableNameFixturesTest < ActiveSupport::TestCase
fixtures :funny_jokes
def test_raises_error
@@ -402,7 +402,7 @@ def test_raises_error
end
end
-class CheckEscapedYamlFixturesTest < Test::Unit::TestCase
+class CheckEscapedYamlFixturesTest < ActiveSupport::TestCase
set_fixture_class :funny_jokes => 'Joke'
fixtures :funny_jokes
@@ -412,30 +412,30 @@ def test_proper_escaped_fixture
end
class DevelopersProject; end
-class ManyToManyFixturesWithClassDefined < Test::Unit::TestCase
+class ManyToManyFixturesWithClassDefined < ActiveSupport::TestCase
fixtures :developers_projects
def test_this_should_run_cleanly
assert true
end
end
-class FixturesBrokenRollbackTest < Test::Unit::TestCase
+class FixturesBrokenRollbackTest < ActiveSupport::TestCase
def blank_setup; end
- alias_method :ar_setup_with_fixtures, :setup_with_fixtures
- alias_method :setup_with_fixtures, :blank_setup
+ alias_method :ar_setup_fixtures, :setup_fixtures
+ alias_method :setup_fixtures, :blank_setup
alias_method :setup, :blank_setup
def blank_teardown; end
- alias_method :ar_teardown_with_fixtures, :teardown_with_fixtures
- alias_method :teardown_with_fixtures, :blank_teardown
+ alias_method :ar_teardown_fixtures, :teardown_fixtures
+ alias_method :teardown_fixtures, :blank_teardown
alias_method :teardown, :blank_teardown
def test_no_rollback_in_teardown_unless_transaction_active
assert_equal 0, Thread.current['open_transactions']
- assert_raise(RuntimeError) { ar_setup_with_fixtures }
+ assert_raise(RuntimeError) { ar_setup_fixtures }
assert_equal 0, Thread.current['open_transactions']
- assert_nothing_raised { ar_teardown_with_fixtures }
+ assert_nothing_raised { ar_teardown_fixtures }
assert_equal 0, Thread.current['open_transactions']
end
@@ -445,7 +445,7 @@ def load_fixtures
end
end
-class LoadAllFixturesTest < Test::Unit::TestCase
+class LoadAllFixturesTest < ActiveSupport::TestCase
self.fixture_path= File.join(File.dirname(__FILE__), '/fixtures/all')
fixtures :all
@@ -454,7 +454,7 @@ def test_all_there
end
end
-class FasterFixturesTest < Test::Unit::TestCase
+class FasterFixturesTest < ActiveSupport::TestCase
fixtures :categories, :authors
def load_extra_fixture(name)
@@ -479,7 +479,7 @@ def test_cache
end
end
-class FoxyFixturesTest < Test::Unit::TestCase
+class FoxyFixturesTest < ActiveSupport::TestCase
fixtures :parrots, :parrots_pirates, :pirates, :treasures, :mateys, :ships, :computers, :developers
def test_identifies_strings
View
4 activerecord/test/inheritance_test.rb
@@ -3,7 +3,7 @@
require 'fixtures/project'
require 'fixtures/subscriber'
-class InheritanceTest < Test::Unit::TestCase
+class InheritanceTest < ActiveSupport::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 < Test::Unit::TestCase
+class InheritanceComputeTypeTest < ActiveSupport::TestCase
fixtures :companies
def setup
View
4 activerecord/test/json_serialization_test.rb
@@ -6,7 +6,7 @@
require 'fixtures/tag'
require 'fixtures/comment'
-class JsonSerializationTest < Test::Unit::TestCase
+class JsonSerializationTest < ActiveSupport::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 < Test::Unit::TestCase
+class DatabaseConnectedJsonEncodingTest < ActiveSupport::TestCase
fixtures :authors, :posts, :comments, :tags, :taggings
def setup
View
2 activerecord/test/lifecycle_test.rb
@@ -64,7 +64,7 @@ def after_find(record)
end
end
-class LifecycleTest < Test::Unit::TestCase
+class LifecycleTest < ActiveSupport::TestCase
fixtures :topics, :developers
def test_before_destroy
View
4 activerecord/test/locking_test.rb
@@ -14,7 +14,7 @@ class ReadonlyFirstNamePerson < Person
attr_readonly :first_name
end
-class OptimisticLockingTest < Test::Unit::TestCase
+class OptimisticLockingTest < ActiveSupport::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 < Test::Unit::TestCase
+ class PessimisticLockingTest < ActiveSupport::TestCase
self.use_transactional_fixtures = false
fixtures :people, :readers
View
12 activerecord/test/method_scoping_test.rb
@@ -5,7 +5,7 @@
require 'fixtures/post'
require 'fixtures/category'
-class MethodScopingTest < Test::Unit::TestCase
+class MethodScopingTest < ActiveSupport::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 < Test::Unit::TestCase
+class NestedScopingTest < ActiveSupport::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< Test::Unit::TestCase
+class HasManyScopingTest< ActiveSupport::TestCase
fixtures :comments, :posts
def setup
@@ -343,7 +343,7 @@ def test_nested_scope
end
-class HasAndBelongsToManyScopingTest< Test::Unit::TestCase
+class HasAndBelongsToManyScopingTest< ActiveSupport::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< Test::Unit::TestCase
+class BelongsToScopingTest< ActiveSupport::TestCase
fixtures :comments, :posts
def setup
@@ -393,7 +393,7 @@ def test_forwarding_to_dynamic_finders
end
-class HasOneScopingTest< Test::Unit::TestCase
+class HasOneScopingTest< ActiveSupport::TestCase
fixtures :comments, :posts
def setup
View
4 activerecord/test/migration_test.rb
@@ -22,7 +22,7 @@ def puts(text="")
end
end
- class MigrationTest < Test::Unit::TestCase
+ class MigrationTest < ActiveSupport::TestCase
self.use_transactional_fixtures = false
fixtures :people
@@ -909,7 +909,7 @@ def test_create_table_with_custom_sequence_name
end
uses_mocha 'Sexy migration tests' do
- class SexyMigrationsTest < Test::Unit::TestCase
+ class SexyMigrationsTest < ActiveSupport::TestCase
def test_references_column_type_adds_id
with_new_table do |t|
t.expects(:column).with('customer_id', :integer, {})
View
2 activerecord/test/migration_test_firebird.rb
@@ -1,7 +1,7 @@
require 'abstract_unit'
require 'fixtures/course'
-class FirebirdMigrationTest < Test::Unit::TestCase
+class FirebirdMigrationTest < ActiveSupport::TestCase
self.use_transactional_fixtures = false
def setup
View
2 activerecord/test/mixin_test.rb
@@ -21,7 +21,7 @@ def now_with_forcing
end
-class TouchTest < Test::Unit::TestCase
+class TouchTest < ActiveSupport::TestCase
fixtures :mixins
def setup
View
2 activerecord/test/modules_test.rb
@@ -1,7 +1,7 @@
require 'abstract_unit'
require 'fixtures/company_in_module'
-class ModulesTest < Test::Unit::TestCase
+class ModulesTest < ActiveSupport::TestCase
fixtures :accounts, :companies, :projects, :developers
def test_module_spanning_associations
View
2 activerecord/test/multiple_db_test.rb
@@ -4,7 +4,7 @@
# So we can test whether Course.connection survives a reload.
require_dependency 'fixtures/course'
-class MultipleDbTest < Test::Unit::TestCase
+class MultipleDbTest < ActiveSupport::TestCase
self.use_transactional_fixtures = false
def setup
View
2 activerecord/test/pk_test.rb
@@ -6,7 +6,7 @@
require 'fixtures/keyboard'
require 'fixtures/mixed_case_monkey'
-class PrimaryKeysTest < Test::Unit::TestCase
+class PrimaryKeysTest < ActiveSupport::TestCase
fixtures :topics, :subscribers, :movies, :mixed_case_monkeys
def test_integer_key
View
4 activerecord/test/query_cache_test.rb
@@ -5,7 +5,7 @@
require 'fixtures/course'
-class QueryCacheTest < Test::Unit::TestCase
+class QueryCacheTest < ActiveSupport::TestCase
fixtures :tasks, :topics
def test_find_queries
@@ -55,7 +55,7 @@ def test_cache_does_not_wrap_string_results_in_arrays
uses_mocha 'QueryCacheExpiryTest' do
-class QueryCacheExpiryTest < Test::Unit::TestCase
+class QueryCacheExpiryTest < ActiveSupport::TestCase
fixtures :tasks
def test_find
View
2 activerecord/test/readonly_test.rb
@@ -11,7 +11,7 @@ def Comment.foo() find :first end
def Project.foo() find :first end
-class ReadOnlyTest < Test::Unit::TestCase
+class ReadOnlyTest < ActiveSupport::TestCase
fixtures :posts, :comments, :developers, :projects, :developers_projects
def test_cant_save_readonly_record
View
2 activerecord/test/reflection_test.rb
@@ -5,7 +5,7 @@
require 'fixtures/company_in_module'
require 'fixtures/subscriber'
-class ReflectionTest < Test::Unit::TestCase
+class ReflectionTest < ActiveSupport::TestCase
fixtures :topics, :customers, :companies, :subscribers
def setup
View
2 activerecord/test/reserved_word_test_mysql.rb
@@ -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 < Test::Unit::TestCase
+class MysqlReservedWordTest < ActiveSupport::TestCase
def setup
@connection = ActiveRecord::Base.connection
View
2 activerecord/test/schema_authorization_test_postgresql.rb
@@ -3,7 +3,7 @@
class SchemaThing < ActiveRecord::Base
end
-class SchemaAuthorizationTest < Test::Unit::TestCase
+class SchemaAuthorizationTest < ActiveSupport::TestCase
self.use_transactional_fixtures = false
TABLE_NAME = 'schema_things'
View
2 activerecord/test/schema_dumper_test.rb
@@ -4,7 +4,7 @@
if ActiveRecord::Base.connection.respond_to?(:tables)
- class SchemaDumperTest < Test::Unit::TestCase
+ class SchemaDumperTest < ActiveSupport::TestCase
def standard_dump
stream = StringIO.new
ActiveRecord::SchemaDumper.ignore_tables = []
View
2 activerecord/test/schema_test_postgresql.rb
@@ -1,6 +1,6 @@
require 'abstract_unit'
-class SchemaTest < Test::Unit::TestCase
+class SchemaTest < ActiveSupport::TestCase
self.use_transactional_fixtures = false
SCHEMA_NAME = 'test_schema'
View
2 activerecord/test/serialization_test.rb
@@ -1,7 +1,7 @@
require 'abstract_unit'
require 'fixtures/contact'
-class SerializationTest < Test::Unit::TestCase
+class SerializationTest < ActiveSupport::TestCase
FORMATS = [ :xml, :json ]
def setup
View
2 activerecord/test/synonym_test_oracle.rb
@@ -6,7 +6,7 @@
# the "subjects" table in Oracle (defined in oci.sql) is just
# a synonym to the "topics" table
-class TestOracleSynonym < Test::Unit::TestCase
+class TestOracleSynonym < ActiveSupport::TestCase
def test_oracle_synonym
topic = Topic.new
View
2 activerecord/test/table_name_test_sqlserver.rb
@@ -6,7 +6,7 @@ class Order < ActiveRecord::Base
self.table_name = '[order]'
end
- class TableNameTest < Test::Unit::TestCase
+ class TableNameTest < ActiveSupport::TestCase
self.use_transactional_fixtures = false
# Ensures Model.columns works when using SQLServer escape characters.
View
2 activerecord/test/threaded_connections_test.rb
@@ -3,7 +3,7 @@
require 'fixtures/reply'
unless %w(FrontBase).include? ActiveRecord::Base.connection.adapter_name
- class ThreadedConnectionsTest < Test::Unit::TestCase
+ class ThreadedConnectionsTest < ActiveSupport::TestCase
self.use_transactional_fixtures = false
fixtures :topics
View
2 activerecord/test/transactions_test.rb
@@ -3,7 +3,7 @@
require 'fixtures/reply'
require 'fixtures/developer'
-class TransactionTest < Test::Unit::TestCase
+class TransactionTest < ActiveSupport::TestCase
self.use_transactional_fixtures = false
fixtures :topics, :developers
View
2 activerecord/test/unconnected_test.rb
@@ -3,7 +3,7 @@
class TestRecord < ActiveRecord::Base
end
-class TestUnconnectedAdapter < Test::Unit::TestCase
+class TestUnconnectedAdapter < ActiveSupport::TestCase
self.use_transactional_fixtures = false
def setup
View
4 activerecord/test/validations_test.rb
@@ -53,7 +53,7 @@ class Conjurer < IneptWizard
class Thaumaturgist < IneptWizard
end
-class ValidationsTest < Test::Unit::TestCase
+class ValidationsTest < ActiveSupport::TestCase
fixtures :topics, :developers
def setup
@@ -1273,7 +1273,7 @@ def with_kcode(kcode)
end
-class ValidatesNumericalityTest < Test::Unit::TestCase
+class ValidatesNumericalityTest < ActiveSupport::TestCase
NIL = [nil]
BLANK = ["", " ", " \t \r \n"]
BIGDECIMAL_STRINGS = %w(12345678901234567890.1234567890) # 30 significent digits
View
8 activerecord/test/xml_serialization_test.rb
@@ -5,7 +5,7 @@
require 'fixtures/tagging'
require 'fixtures/comment'
-class XmlSerializationTest < Test::Unit::TestCase
+class XmlSerializationTest < ActiveSupport::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 < Test::Unit::TestCase
+class DefaultXmlSerializationTest < ActiveSupport::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 < Test::Unit::TestCase
+class NilXmlSerializationTest < ActiveSupport::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 < Test::Unit::TestCase
+class DatabaseConnectedXmlSerializationTest < ActiveSupport::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
4 activesupport/CHANGELOG
@@ -1,5 +1,9 @@
*SVN*
+* Continue evolution toward ActiveSupport::TestCase. #10679 [Josh Peek]
+
+* TestCase: introduce declared setup and teardown callbacks. Pass a list of methods and an optional block to call before setup or after teardown. Setup callbacks are run in the order declared; teardown callbacks are run in reverse. [Jeremy Kemper]
+
* Added ActiveSupport::Gzip.decompress/compress(source) as an easy wrapper for Zlib [Tobias Luetke]
* Included MemCache-Client to make the improved ActiveSupport::Cache::MemCacheStore work out of the box [Bob Cottrell, Eric Hodel]
View
3 activesupport/lib/active_support.rb
@@ -49,6 +49,3 @@
require 'active_support/multibyte'
require 'active_support/base64'
-
-require 'active_support/testing'
-
View
12 activesupport/lib/active_support/test_case.rb
@@ -1,5 +1,13 @@
+require 'test/unit/testcase'
+require 'active_support/testing/setup_and_teardown'
+require 'active_support/testing/default'
+
+# TODO: move to core_ext
+class Test::Unit::TestCase #:nodoc:
+ include ActiveSupport::Testing::SetupAndTeardown
+end
+
module ActiveSupport
class TestCase < Test::Unit::TestCase
- include ActiveSupport::Testing::Default
end
-end
+end
View
1 activesupport/lib/active_support/testing.rb
@@ -1 +0,0 @@
-require 'active_support/testing/default'
View
9 activesupport/lib/active_support/testing/default.rb
@@ -1,12 +1,9 @@
module ActiveSupport
module Testing
- module Default
- def run(*args)
- #method_name appears to be a symbol on 1.8.4 and a string on 1.8.6
- return if @method_name.to_s == "default_test"
- super
+ module Default #:nodoc:
+ # Placeholder so test/unit ignores test cases without any tests.
+ def default_test
end
end
end
end
-
View
127 activesupport/lib/active_support/testing/setup_and_teardown.rb
@@ -0,0 +1,127 @@
+module ActiveSupport
+ module Testing
+ module SetupAndTeardown
+ def self.included(base)
+ base.extend ClassMethods
+
+ begin
+ require 'mocha'
+ base.alias_method_chain :run, :callbacks_and_mocha
+ rescue LoadError
+ base.alias_method_chain :run, :callbacks
+ end
+ end
+
+ module ClassMethods
+ def setup(*method_names, &block)
+ method_names << block if block_given?
+ (@setup_callbacks ||= []).concat method_names
+ end
+
+ def teardown(*method_names, &block)
+ method_names << block if block_given?
+ (@teardown_callbacks ||= []).concat method_names
+ end
+
+ def setup_callback_chain
+ @setup_callbacks ||= []
+
+ if superclass.respond_to?(:setup_callback_chain)
+ superclass.setup_callback_chain + @setup_callbacks
+ else
+ @setup_callbacks
+ end
+ end
+
+ def teardown_callback_chain
+ @teardown_callbacks ||= []
+
+ if superclass.respond_to?(:teardown_callback_chain)
+ superclass.teardown_callback_chain + @teardown_callbacks
+ else
+ @teardown_callbacks
+ end
+ end
+ end
+
+ # This redefinition is unfortunate but test/unit shows us no alternative.
+ def run_with_callbacks(result) #:nodoc:
+ return if @method_name.to_s == "default_test"
+
+ yield(Test::Unit::TestCase::STARTED, name)
+ @_result = result
+ begin
+ run_callbacks :setup
+ setup
+ __send__(@method_name)
+ rescue Test::Unit::AssertionFailedError => e
+ add_failure(e.message, e.backtrace)
+ rescue *Test::Unit::TestCase::PASSTHROUGH_EXCEPTIONS
+ raise
+ rescue Exception
+ add_error($!)
+ ensure
+ begin
+ teardown
+ run_callbacks :teardown, :reverse_each
+ rescue Test::Unit::AssertionFailedError => e
+ add_failure(e.message, e.backtrace)
+ rescue *Test::Unit::TestCase::PASSTHROUGH_EXCEPTIONS
+ raise
+ rescue Exception
+ add_error($!)
+ end
+ end
+ result.add_run
+ yield(Test::Unit::TestCase::FINISHED, name)
+ end
+
+ # Doubly unfortunate: mocha does the same so we have to hax their hax.
+ def run_with_callbacks_and_mocha(result)
+ return if @method_name.to_s == "default_test"
+
+ yield(Test::Unit::TestCase::STARTED, name)
+ @_result = result
+ begin
+ mocha_setup
+ begin
+ run_callbacks :setup
+ setup
+ __send__(@method_name)
+ mocha_verify { add_assertion }
+ rescue Mocha::ExpectationError => e
+ add_failure(e.message, e.backtrace)
+ rescue Test::Unit::AssertionFailedError => e
+ add_failure(e.message, e.backtrace)
+ rescue StandardError, ScriptError
+ add_error($!)
+ ensure
+ begin
+ teardown
+ run_callbacks :teardown, :reverse_each
+ rescue Test::Unit::AssertionFailedError => e
+ add_failure(e.message, e.backtrace)
+ rescue StandardError, ScriptError
+ add_error($!)
+ end
+ end
+ ensure
+ mocha_teardown
+ end
+ result.add_run
+ yield(Test::Unit::TestCase::FINISHED, name)
+ end
+
+ protected
+ def run_callbacks(kind, enumerator = :each)
+ self.class.send("#{kind}_callback_chain").send(enumerator) do |callback|
+ case callback
+ when Proc; callback.call(self)
+ when String, Symbol; send!(callback)
+ else raise ArgumentError, "Unrecognized callback #{callback.inspect}"
+ end
+ end
+ end
+ end
+ end
+end
View
2 ...support/test/core_ext/load_error_tests.rb → ...esupport/test/core_ext/load_error_test.rb
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/../abstract_unit'
+require 'abstract_unit'
class TestMissingSourceFile < Test::Unit::TestCase
def test_with_require
View
46 activesupport/test/test_test.rb
@@ -72,3 +72,49 @@ class NotTestingThingsTest < Test::Unit::TestCase
class AlsoDoingNothingTest < ActiveSupport::TestCase
end
+
+# Setup and teardown callbacks.
+class SetupAndTeardownTest < Test::Unit::TestCase
+ setup :reset_callback_record, :foo
+ teardown :foo, :sentinel, :foo
+
+ def test_inherited_setup_callbacks
+ assert_equal [:reset_callback_record, :foo], self.class.setup_callback_chain
+ assert_equal [:foo], @called_back
+ assert_equal [:foo, :sentinel, :foo], self.class.teardown_callback_chain
+ end
+
+ protected
+ def reset_callback_record
+ @called_back = []
+ end
+
+ def foo
+ @called_back << :foo
+ end
+
+ def sentinel
+ assert_equal [:foo, :foo], @called_back
+ end
+end
+
+
+class SubclassSetupAndTeardownTest < SetupAndTeardownTest
+ setup :bar
+ teardown :bar
+
+ def test_inherited_setup_callbacks
+ assert_equal [:reset_callback_record, :foo, :bar], self.class.setup_callback_chain
+ assert_equal [:foo, :bar], @called_back
+ assert_equal [:foo, :sentinel, :foo, :bar], self.class.teardown_callback_chain
+ end
+