diff options
author | José Valim <jose.valim@gmail.com> | 2011-10-03 02:10:29 -0700 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-10-03 02:10:29 -0700 |
commit | daca35c394dd490aeeaad9074141d7d86e9efb2c (patch) | |
tree | 6389c3d2ebc82de712d62612f80e0e4996f18b97 | |
parent | d68884f4fddf5452f1dcbdf1a7b35d5889926fe5 (diff) | |
parent | 8e946daf6957b46744a90d25266b0ec5e8537079 (diff) | |
download | rails-daca35c394dd490aeeaad9074141d7d86e9efb2c.tar.gz rails-daca35c394dd490aeeaad9074141d7d86e9efb2c.tar.bz2 rails-daca35c394dd490aeeaad9074141d7d86e9efb2c.zip |
Merge pull request #3194 from avakhov/patch-ac-test-case-tests
normalize arg for AC::TestCase tests class method
-rw-r--r-- | actionpack/lib/action_controller/test_case.rb | 16 | ||||
-rw-r--r-- | actionpack/test/controller/test_test.rb | 16 |
2 files changed, 30 insertions, 2 deletions
diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index a83fa74795..964ec6d5ae 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -333,9 +333,21 @@ module ActionController 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) diff --git a/actionpack/test/controller/test_test.rb b/actionpack/test/controller/test_test.rb index ca87cda2a3..b64e275363 100644 --- a/actionpack/test/controller/test_test.rb +++ b/actionpack/test/controller/test_test.rb @@ -774,6 +774,22 @@ class CrazyNameTest < ActionController::TestCase 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 |