aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-05-03 00:37:40 +0200
committerJosé Valim <jose.valim@gmail.com>2011-05-03 01:04:57 +0200
commit4bddc06e83acecce662b4282159c5eb0096c4783 (patch)
treed4df2ac421af379bdcd16162d25fdb7da0f47ef7 /actionpack/test
parent3cca86641e91400e3317ce2d03b483edf1db3ec2 (diff)
downloadrails-4bddc06e83acecce662b4282159c5eb0096c4783.tar.gz
rails-4bddc06e83acecce662b4282159c5eb0096c4783.tar.bz2
rails-4bddc06e83acecce662b4282159c5eb0096c4783.zip
Move most processing to load time for performance and improve test suite.
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/controller/params_wrapper_test.rb39
1 files changed, 27 insertions, 12 deletions
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