From 4bddc06e83acecce662b4282159c5eb0096c4783 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 3 May 2011 00:37:40 +0200 Subject: Move most processing to load time for performance and improve test suite. --- actionpack/test/controller/params_wrapper_test.rb | 39 ++++++++++++++++------- 1 file changed, 27 insertions(+), 12 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/params_wrapper_test.rb b/actionpack/test/controller/params_wrapper_test.rb index 2e5d096fcd..314b27cf47 100644 --- a/actionpack/test/controller/params_wrapper_test.rb +++ b/actionpack/test/controller/params_wrapper_test.rb @@ -80,6 +80,15 @@ class ParamsWrapperTest < ActionController::TestCase end end + def test_wrap_parameters_false + with_default_wrapper_options do + UsersController.wrap_parameters false + @request.env['CONTENT_TYPE'] = 'application/json' + post :test, { 'username' => 'sikachu', 'title' => 'Developer' } + assert_equal '{"username":"sikachu","title":"Developer"}', @response.body + end + end + def test_specify_format with_default_wrapper_options do UsersController.wrap_parameters :format => :xml @@ -115,10 +124,10 @@ class ParamsWrapperTest < ActionController::TestCase end def test_derived_wrapped_keys_from_matching_model - with_default_wrapper_options do - User.expects(:respond_to?).with(:column_names).returns(true) - User.expects(:column_names).returns(["username"]) + User.expects(:respond_to?).with(:column_names).returns(true) + User.expects(:column_names).returns(["username"]) + with_default_wrapper_options do @request.env['CONTENT_TYPE'] = 'application/json' post :test, { 'username' => 'sikachu', 'title' => 'Developer' } assert_equal '{"username":"sikachu","title":"Developer","user":{"username":"sikachu"}}', @response.body @@ -153,11 +162,13 @@ class NamespacedParamsWrapperTest < ActionController::TestCase render :json => params.except(:controller, :action) end end + end - class User; end + class Sample + def self.column_names + ["username"] + end end - class User; end - class Person; end tests Admin::UsersController @@ -169,12 +180,16 @@ class NamespacedParamsWrapperTest < ActionController::TestCase end end - def test_namespace_lookup_when_namespaced_model_available - with_default_wrapper_options do - Admin::User.expects(:respond_to?).with(:column_names).returns(false) - - @request.env['CONTENT_TYPE'] = 'application/json' - post :test, { 'username' => 'sikachu' } + def test_namespace_lookup_from_model + Admin.const_set(:User, Class.new(Sample)) + begin + with_default_wrapper_options do + @request.env['CONTENT_TYPE'] = 'application/json' + post :test, { 'username' => 'sikachu', 'title' => 'Developer' } + assert_equal '{"username":"sikachu","title":"Developer","user":{"username":"sikachu"}}', @response.body + end + ensure + Admin.send :remove_const, :User end end -- cgit v1.2.3