Ticket #10536: call_setup_method_in_subclassed_test_case.patch
| File call_setup_method_in_subclassed_test_case.patch, 2.7 kB (added by kasatani, 10 months ago) |
|---|
-
activerecord/test/fixtures_test.rb
old new 331 331 fixtures :topics 332 332 333 333 def setup 334 @setup_done = true 334 335 end 335 336 336 337 def test_should_properly_setup_fixtures 338 assert @setup_done 337 339 assert_nothing_raised { topics(:first) } 338 340 end 339 341 end 340 342 CODE 341 343 2.times { eval(class_def) } 342 344 345 class BaseOfSubclassedTestCase < ActiveSupport::TestCase 346 def setup 347 @base_setup_done = true 348 end 349 350 def teardown 351 assert @subclass_teardown_done 352 @base_teardown_done = true 353 end 354 end 355 class SubclassedTestCase < BaseOfSubclassedTestCase 356 fixtures :topics 357 358 def setup 359 super 360 @subclass_setup_done = true 361 end 362 363 def teardown 364 @subclass_teardown_done = true 365 super 366 assert @base_teardown_done 367 end 368 369 def test_should_properly_call_all_setup_and_teardown_methods 370 assert @base_setup_done 371 assert @subclass_setup_done 372 assert_nothing_raised { topics(:first) } 373 end 374 end 375 343 376 class OverlappingFixturesTest < Test::Unit::TestCase 344 377 fixtures :topics, :developers 345 378 fixtures :developers, :accounts -
activerecord/lib/active_record/fixtures.rb
old new 972 972 973 973 case method.to_s 974 974 when 'setup' 975 unless method_defined?(:setup_without_fixtures) 976 alias_method :setup_without_fixtures, :setup 977 define_method(:full_setup) do 978 setup_with_fixtures 979 setup_without_fixtures 980 end 981 end 982 alias_method :setup, :full_setup 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" 983 978 when 'teardown' 984 unless method_defined?(:teardown_without_fixtures) 985 alias_method :teardown_without_fixtures, :teardown 986 define_method(:full_teardown) do 987 teardown_without_fixtures 988 teardown_with_fixtures 989 end 990 end 991 alias_method :teardown, :full_teardown 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" 992 982 end 993 983 994 984 @__disable_method_added__ = false