mirror of
https://github.com/github/rails.git
synced 2026-02-03 02:35:08 -05:00
Make the Fixtures Test::Unit enhancements more supporting for double-loaded test cases. Closes #10379 [brynary]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8392 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
*SVN*
|
||||
|
||||
* Make the Fixtures Test::Unit enhancements more supporting for double-loaded test cases. Closes #10379 [brynary]
|
||||
|
||||
* Fix that validates_acceptance_of still works for non-existent tables (useful for bootstrapping new databases). Closes #10474 [hasmanyjosh]
|
||||
|
||||
* Ensure that the :uniq option for has_many :through associations retains the order. #10463 [remvee]
|
||||
|
||||
@@ -916,6 +916,8 @@ module Test #:nodoc:
|
||||
end
|
||||
|
||||
def setup_with_fixtures
|
||||
return if @fixtures_setup
|
||||
@fixtures_setup = true
|
||||
return unless defined?(ActiveRecord::Base) && !ActiveRecord::Base.configurations.blank?
|
||||
|
||||
if pre_loaded_fixtures && !use_transactional_fixtures
|
||||
@@ -947,6 +949,8 @@ module Test #:nodoc:
|
||||
alias_method :setup, :setup_with_fixtures
|
||||
|
||||
def teardown_with_fixtures
|
||||
return if @fixtures_teardown
|
||||
@fixtures_teardown = true
|
||||
return unless defined?(ActiveRecord::Base) && !ActiveRecord::Base.configurations.blank?
|
||||
|
||||
unless use_transactional_fixtures?
|
||||
@@ -963,24 +967,31 @@ module Test #:nodoc:
|
||||
alias_method :teardown, :teardown_with_fixtures
|
||||
|
||||
def self.method_added(method)
|
||||
return if @__disable_method_added__
|
||||
@__disable_method_added__ = true
|
||||
|
||||
case method.to_s
|
||||
when 'setup'
|
||||
unless method_defined?(:setup_without_fixtures)
|
||||
alias_method :setup_without_fixtures, :setup
|
||||
define_method(:setup) do
|
||||
define_method(:full_setup) do
|
||||
setup_with_fixtures
|
||||
setup_without_fixtures
|
||||
end
|
||||
end
|
||||
alias_method :setup, :full_setup
|
||||
when 'teardown'
|
||||
unless method_defined?(:teardown_without_fixtures)
|
||||
alias_method :teardown_without_fixtures, :teardown
|
||||
define_method(:teardown) do
|
||||
define_method(:full_teardown) do
|
||||
teardown_without_fixtures
|
||||
teardown_with_fixtures
|
||||
end
|
||||
end
|
||||
alias_method :teardown, :full_teardown
|
||||
end
|
||||
|
||||
@__disable_method_added__ = false
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -324,6 +324,22 @@ class MultipleFixturesTest < Test::Unit::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
# This is to reproduce a bug where if a TestCase is loaded
|
||||
# twice by Ruby, it loses its fixture setup hook.
|
||||
class_def = <<-CODE
|
||||
class DoubleLoadedTestCase < Test::Unit::TestCase
|
||||
fixtures :topics
|
||||
|
||||
def setup
|
||||
end
|
||||
|
||||
def test_should_properly_setup_fixtures
|
||||
assert_nothing_raised { topics(:first) }
|
||||
end
|
||||
end
|
||||
CODE
|
||||
2.times { eval(class_def) }
|
||||
|
||||
class OverlappingFixturesTest < Test::Unit::TestCase
|
||||
fixtures :topics, :developers
|
||||
fixtures :developers, :accounts
|
||||
|
||||
Reference in New Issue
Block a user