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

Ticket #10379: make_fixture_setup_support_testcase_classes_loaded_multiple_times.patch

File make_fixture_setup_support_testcase_classes_loaded_multiple_times.patch, 2.6 kB (added by brynary, 7 months ago)
  • test/fixtures_test.rb

    old new  
    324324  end 
    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 
    329345  fixtures :developers, :accounts 
  • lib/active_record/fixtures.rb

    old new  
    911911      end 
    912912 
    913913      def setup_with_fixtures 
     914        return if @fixtures_setup 
     915        @fixtures_setup = true 
    914916        return unless defined?(ActiveRecord::Base) && !ActiveRecord::Base.configurations.blank? 
    915917 
    916918        if pre_loaded_fixtures && !use_transactional_fixtures 
     
    942944      alias_method :setup, :setup_with_fixtures 
    943945 
    944946      def teardown_with_fixtures 
     947        return if @fixtures_teardown 
     948        @fixtures_teardown = true 
    945949        return unless defined?(ActiveRecord::Base) && !ActiveRecord::Base.configurations.blank? 
    946950 
    947951        unless use_transactional_fixtures? 
     
    958962      alias_method :teardown, :teardown_with_fixtures 
    959963 
    960964      def self.method_added(method) 
     965        return if @__disable_method_added__ 
     966        @__disable_method_added__ = true 
     967         
    961968        case method.to_s 
    962969        when 'setup' 
    963970          unless method_defined?(:setup_without_fixtures) 
    964971            alias_method :setup_without_fixtures, :setup 
    965             define_method(:setup) do 
     972            define_method(:full_setup) do 
    966973              setup_with_fixtures 
    967974              setup_without_fixtures 
    968975            end 
    969976          end 
     977          alias_method :setup, :full_setup 
    970978        when 'teardown' 
    971979          unless method_defined?(:teardown_without_fixtures) 
    972980            alias_method :teardown_without_fixtures, :teardown 
    973             define_method(:teardown) do 
     981            define_method(:full_teardown) do 
    974982              teardown_without_fixtures 
    975983              teardown_with_fixtures 
    976984            end 
    977985          end 
     986          alias_method :teardown, :full_teardown 
    978987        end 
     988         
     989        @__disable_method_added__ = false 
    979990      end 
    980991 
    981992      private