Permalink
Browse files

Ensure that test case setup is run even if overridden. Closes #10382.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8497 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 0c0610d commit 16558f6dd83d514f783ed13e9bc24d6b66e5aefd @jeremy jeremy committed Dec 28, 2007
Showing with 28 additions and 4 deletions.
  1. +2 −0 actionpack/CHANGELOG
  2. +16 −3 actionpack/lib/action_controller/test_case.rb
  3. +10 −1 actionpack/test/controller/test_test.rb
View
2 actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Ensure that test case setup is run even if overridden. #10382 [Josh Peek]
+
* Fix HTML Sanitizer to allow trailing spaces in CSS style attributes. Closes #10566 [wesley.moxam]
* Add :default option to time_zone_select. #10590 [Matt Aimonetti]
View
19 actionpack/lib/action_controller/test_case.rb
@@ -44,10 +44,23 @@ def rescue_action(e)
end
end
- def setup
+ def setup_with_controller
@controller = self.class.controller_class.new
@request = TestRequest.new
@response = TestResponse.new
end
- end
-end
+ alias_method :setup, :setup_with_controller
+
+ def self.method_added(method)
+ if method.to_s == 'setup'
+ unless method_defined?(:setup_without_controller)
+ alias_method :setup_without_controller, :setup
+ define_method(:setup) do
+ setup_with_controller
+ setup_without_controller
+ end
+ end
+ end
+ end
+ end
+end
View
11 actionpack/test/controller/test_test.rb
@@ -614,10 +614,19 @@ def determine_class(name)
end
end
+class ContentControllerTest < ActionController::TestCase
+ def setup
+ # Should not override ActionController setup methods
+ end
+
+ def test_should_still_setup_controller
+ assert_kind_of(ContentController, @controller)
+ end
+end
+
class CrazyNameTest < ActionController::TestCase
tests ContentController
def test_controller_class_can_be_set_manually_not_just_inferred
assert_equal ContentController, self.class.controller_class
end
end
-

0 comments on commit 16558f6

Please sign in to comment.