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 324 324 end 325 325 end 326 326 327 # This is to reproduce a bug where if a TestCase is loaded 328 # twice by Ruby, it loses its fixture setup hook. 329 class_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 340 CODE 341 2.times { eval(class_def) } 342 327 343 class OverlappingFixturesTest < Test::Unit::TestCase 328 344 fixtures :topics, :developers 329 345 fixtures :developers, :accounts -
lib/active_record/fixtures.rb
old new 911 911 end 912 912 913 913 def setup_with_fixtures 914 return if @fixtures_setup 915 @fixtures_setup = true 914 916 return unless defined?(ActiveRecord::Base) && !ActiveRecord::Base.configurations.blank? 915 917 916 918 if pre_loaded_fixtures && !use_transactional_fixtures … … 942 944 alias_method :setup, :setup_with_fixtures 943 945 944 946 def teardown_with_fixtures 947 return if @fixtures_teardown 948 @fixtures_teardown = true 945 949 return unless defined?(ActiveRecord::Base) && !ActiveRecord::Base.configurations.blank? 946 950 947 951 unless use_transactional_fixtures? … … 958 962 alias_method :teardown, :teardown_with_fixtures 959 963 960 964 def self.method_added(method) 965 return if @__disable_method_added__ 966 @__disable_method_added__ = true 967 961 968 case method.to_s 962 969 when 'setup' 963 970 unless method_defined?(:setup_without_fixtures) 964 971 alias_method :setup_without_fixtures, :setup 965 define_method(: setup) do972 define_method(:full_setup) do 966 973 setup_with_fixtures 967 974 setup_without_fixtures 968 975 end 969 976 end 977 alias_method :setup, :full_setup 970 978 when 'teardown' 971 979 unless method_defined?(:teardown_without_fixtures) 972 980 alias_method :teardown_without_fixtures, :teardown 973 define_method(: teardown) do981 define_method(:full_teardown) do 974 982 teardown_without_fixtures 975 983 teardown_with_fixtures 976 984 end 977 985 end 986 alias_method :teardown, :full_teardown 978 987 end 988 989 @__disable_method_added__ = false 979 990 end 980 991 981 992 private