aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller
diff options
context:
space:
mode:
authorDavid Chelimsky <dchelimsky@gmail.com>2011-05-17 06:55:03 -0400
committerDavid Chelimsky <dchelimsky@gmail.com>2011-05-17 06:57:14 -0400
commit13950a8cc94ab93bb20976f2797b1df9740849b3 (patch)
treedf46d1c28141145fc9b4c654a00391f6696fe488 /actionpack/test/controller
parentee82e1c3015392c87c88ee32003763210a75d1ec (diff)
downloadrails-13950a8cc94ab93bb20976f2797b1df9740849b3.tar.gz
rails-13950a8cc94ab93bb20976f2797b1df9740849b3.tar.bz2
rails-13950a8cc94ab93bb20976f2797b1df9740849b3.zip
add more robust test for wrapping params with anonymous class
Diffstat (limited to 'actionpack/test/controller')
-rw-r--r--actionpack/test/controller/params_wrapper_test.rb70
1 files changed, 45 insertions, 25 deletions
diff --git a/actionpack/test/controller/params_wrapper_test.rb b/actionpack/test/controller/params_wrapper_test.rb
index 98f4c27a01..a50065bcc7 100644
--- a/actionpack/test/controller/params_wrapper_test.rb
+++ b/actionpack/test/controller/params_wrapper_test.rb
@@ -2,7 +2,21 @@ require 'abstract_unit'
module Admin; class User; end; end
+module ParamsWrapperTestHelp
+ def with_default_wrapper_options(&block)
+ @controller.class._wrapper_options = {:format => [:json]}
+ @controller.class.inherited(@controller.class)
+ yield
+ end
+
+ def assert_parameters(expected)
+ assert_equal expected, self.class.controller_class.last_parameters
+ end
+end
+
class ParamsWrapperTest < ActionController::TestCase
+ include ParamsWrapperTestHelp
+
class UsersController < ActionController::Base
class << self
attr_accessor :last_parameters
@@ -31,13 +45,6 @@ class ParamsWrapperTest < ActionController::TestCase
end
end
- def test_allow_anonymous_controller
- with_default_wrapper_options do
- # This should not raise an error.
- Class.new(UsersController)
- end
- end
-
def test_specify_wrapper_name
with_default_wrapper_options do
UsersController.wrap_parameters :person
@@ -173,20 +180,11 @@ class ParamsWrapperTest < ActionController::TestCase
assert_parameters({ 'username' => 'sikachu', 'title' => 'Developer', 'user' => { 'username' => 'sikachu', 'title' => 'Developer' }})
end
end
-
- private
- def with_default_wrapper_options(&block)
- @controller.class._wrapper_options = {:format => [:json]}
- @controller.class.inherited(@controller.class)
- yield
- end
-
- def assert_parameters(expected)
- assert_equal expected, UsersController.last_parameters
- end
end
class NamespacedParamsWrapperTest < ActionController::TestCase
+ include ParamsWrapperTestHelp
+
module Admin
module Users
class UsersController < ActionController::Base;
@@ -254,14 +252,36 @@ class NamespacedParamsWrapperTest < ActionController::TestCase
end
end
- private
- def with_default_wrapper_options(&block)
- @controller.class._wrapper_options = {:format => [:json]}
- @controller.class.inherited(@controller.class)
- yield
+end
+
+class AnonymousControllerParamsWrapperTest < ActionController::TestCase
+ include ParamsWrapperTestHelp
+
+ tests(Class.new(ActionController::Base) do
+ class << self
+ attr_accessor :last_parameters
end
- def assert_parameters(expected)
- assert_equal expected, Admin::Users::UsersController.last_parameters
+ def parse
+ self.class.last_parameters = request.params.except(:controller, :action)
+ head :ok
end
+ end)
+
+ def test_does_not_implicitly_wrap_params
+ with_default_wrapper_options do
+ @request.env['CONTENT_TYPE'] = 'application/json'
+ post :parse, { 'username' => 'sikachu' }
+ assert_parameters({ 'username' => 'sikachu' })
+ end
+ end
+
+ def test_does_wrap_params_if_name_provided
+ with_default_wrapper_options do
+ @controller.class.wrap_parameters(:name => "guest")
+ @request.env['CONTENT_TYPE'] = 'application/json'
+ post :parse, { 'username' => 'sikachu' }
+ assert_parameters({ 'username' => 'sikachu', 'guest' => { 'username' => 'sikachu' }})
+ end
+ end
end