Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 8392

Show
Ignore:
Timestamp:
12/15/07 01:23:05 (7 months ago)
Author:
rick
Message:

Make the Fixtures Test::Unit enhancements more supporting for double-loaded test cases. Closes #10379 [brynary]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/CHANGELOG

    r8377 r8392  
    11*SVN* 
     2 
     3* Make the Fixtures Test::Unit enhancements more supporting for double-loaded test cases.  Closes #10379 [brynary] 
    24 
    35* Fix that validates_acceptance_of still works for non-existent tables (useful for bootstrapping new databases).  Closes #10474 [hasmanyjosh] 
  • trunk/activerecord/lib/active_record/fixtures.rb

    r8339 r8392  
    917917 
    918918      def setup_with_fixtures 
     919        return if @fixtures_setup 
     920        @fixtures_setup = true 
    919921        return unless defined?(ActiveRecord::Base) && !ActiveRecord::Base.configurations.blank? 
    920922 
     
    948950 
    949951      def teardown_with_fixtures 
     952        return if @fixtures_teardown 
     953        @fixtures_teardown = true 
    950954        return unless defined?(ActiveRecord::Base) && !ActiveRecord::Base.configurations.blank? 
    951955 
     
    964968 
    965969      def self.method_added(method) 
     970        return if @__disable_method_added__ 
     971        @__disable_method_added__ = true 
     972         
    966973        case method.to_s 
    967974        when 'setup' 
    968975          unless method_defined?(:setup_without_fixtures) 
    969976            alias_method :setup_without_fixtures, :setup 
    970             define_method(:setup) do 
     977            define_method(:full_setup) do 
    971978              setup_with_fixtures 
    972979              setup_without_fixtures 
    973980            end 
    974981          end 
     982          alias_method :setup, :full_setup 
    975983        when 'teardown' 
    976984          unless method_defined?(:teardown_without_fixtures) 
    977985            alias_method :teardown_without_fixtures, :teardown 
    978             define_method(:teardown) do 
     986            define_method(:full_teardown) do 
    979987              teardown_without_fixtures 
    980988              teardown_with_fixtures 
    981989            end 
    982990          end 
    983         end 
     991          alias_method :teardown, :full_teardown 
     992        end 
     993         
     994        @__disable_method_added__ = false 
    984995      end 
    985996 
  • trunk/activerecord/test/fixtures_test.rb

    r8219 r8392  
    325325end 
    326326 
     327# This is to reproduce a bug where if a TestCase is loaded 
     328# twice by Ruby, it loses its fixture setup hook. 
     329class_def = <<-CODE 
     330  class DoubleLoadedTestCase < Test::Unit::TestCase 
     331    fixtures :topics 
     332 
     333    def setup 
     334    end 
     335   
     336    def test_should_properly_setup_fixtures 
     337      assert_nothing_raised { topics(:first) } 
     338    end 
     339  end 
     340CODE 
     3412.times { eval(class_def) } 
     342 
    327343class OverlappingFixturesTest < Test::Unit::TestCase 
    328344  fixtures :topics, :developers