Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #3194 from avakhov/patch-ac-test-case-tests

normalize arg for AC::TestCase tests class method
  • Loading branch information...
commit daca35c394dd490aeeaad9074141d7d86e9efb2c 2 parents d68884f + 8e946da
@josevalim josevalim authored
View
16 actionpack/lib/action_controller/test_case.rb
@@ -333,9 +333,21 @@ module Behavior
module ClassMethods
# Sets the controller class name. Useful if the name can't be inferred from test class.
- # Expects +controller_class+ as a constant. Example: <tt>tests WidgetController</tt>.
+ # Normalizes +controller_class+ before using. Examples:
+ #
+ # tests WidgetController
+ # tests :widget
+ # tests 'widget'
+ #
def tests(controller_class)
- self.controller_class = controller_class
+ case controller_class
+ when String, Symbol
+ self.controller_class = "#{controller_class.to_s.underscore}_controller".camelize.constantize
+ when Class
+ self.controller_class = controller_class
+ else
+ raise ArgumentError, "controller class must be a String, Symbol, or Class"
+ end
end
def controller_class=(new_class)
View
16 actionpack/test/controller/test_test.rb
@@ -774,6 +774,22 @@ def test_controller_class_can_be_set_manually_not_just_inferred
end
end
+class CrazySymbolNameTest < ActionController::TestCase
+ tests :content
+
+ def test_set_controller_class_using_symbol
+ assert_equal ContentController, self.class.controller_class
+ end
+end
+
+class CrazyStringNameTest < ActionController::TestCase
+ tests 'content'
+
+ def test_set_controller_class_using_string
+ assert_equal ContentController, self.class.controller_class
+ end
+end
+
class NamedRoutesControllerTest < ActionController::TestCase
tests ContentController
Please sign in to comment.
Something went wrong with that request. Please try again.