Ticket #10379: make_subclassed_testcase_and_testcase_loaded_multiple_times_both_work.patch
| File make_subclassed_testcase_and_testcase_loaded_multiple_times_both_work.patch, 2.9 kB (added by kasatani, 7 months ago) |
|---|
-
activerecord/test/fixtures_test.rb
old new 348 348 end 349 349 350 350 351 # This is to reproduce a bug where if a TestCase is loaded 352 # twice by Ruby, it loses its fixture setup hook. 353 class_def = <<-CODE 354 class DoubleLoadedTestCase < Test::Unit::TestCase 355 fixtures :topics 356 357 def setup 358 end 359 360 def test_should_properly_setup_fixtures 361 assert_nothing_raised { topics(:first) } 362 end 363 end 364 CODE 365 2.times { eval(class_def) } 366 351 367 class OverlappingFixturesTest < Test::Unit::TestCase 352 368 fixtures :topics, :developers 353 369 fixtures :developers, :accounts -
activerecord/lib/active_record/fixtures.rb
old new 916 916 end 917 917 918 918 def setup_with_fixtures 919 return if @fixtures_setup 920 @fixtures_setup = true 919 921 return unless defined?(ActiveRecord::Base) && !ActiveRecord::Base.configurations.blank? 920 922 921 923 if pre_loaded_fixtures && !use_transactional_fixtures … … 947 949 alias_method :setup, :setup_with_fixtures 948 950 949 951 def teardown_with_fixtures 952 return if @fixtures_teardown 953 @fixtures_teardown = true 950 954 return unless defined?(ActiveRecord::Base) && !ActiveRecord::Base.configurations.blank? 951 955 952 956 unless use_transactional_fixtures? … … 963 967 alias_method :teardown, :teardown_with_fixtures 964 968 965 969 def self.method_added(method) 970 return if @__disable_method_added__ 971 @__disable_method_added__ = true 972 966 973 case method.to_s 967 974 when 'setup' 968 unless method_defined?(:setup_without_fixtures) 969 alias_method :setup_without_fixtures, :setup 970 define_method(:setup) do 971 setup_with_fixtures 972 setup_without_fixtures 973 end 974 end 975 original_setup = "setup_without_fixtures_for_#{self.name.underscore.gsub('/', '__')}" 976 alias_method original_setup, :setup 977 class_eval "def setup; setup_with_fixtures; #{original_setup}; end" 975 978 when 'teardown' 976 unless method_defined?(:teardown_without_fixtures) 977 alias_method :teardown_without_fixtures, :teardown 978 define_method(:teardown) do 979 teardown_without_fixtures 980 teardown_with_fixtures 981 end 982 end 979 original_teardown = "teardown_without_fixtures_for_#{self.name.underscore.gsub('/', '__')}" 980 alias_method original_teardown, :teardown 981 class_eval "def teardown; #{original_teardown}; teardown_with_fixtures; end" 983 982 end 983 984 @__disable_method_added__ = false 984 985 end 985 986 986 987 private