aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller/request_test.rb
diff options
context:
space:
mode:
authorYehuda Katz <wycats@gmail.com>2009-01-09 18:58:38 -0800
committerYehuda Katz <wycats@gmail.com>2009-01-09 18:58:47 -0800
commite8980ad278923e07eb1626908f40608db7f7a6ff (patch)
treef9b711d1f811b0e787a70ad2415f0189883f121d /actionpack/test/controller/request_test.rb
parentbb03719943ee5f8e357323f35aa7ffd083938fc2 (diff)
parent40a75a509187b6759099a3644b7ae8db9fc14045 (diff)
downloadrails-e8980ad278923e07eb1626908f40608db7f7a6ff.tar.gz
rails-e8980ad278923e07eb1626908f40608db7f7a6ff.tar.bz2
rails-e8980ad278923e07eb1626908f40608db7f7a6ff.zip
Sync 'rails/rails/master'
Diffstat (limited to 'actionpack/test/controller/request_test.rb')
-rw-r--r--actionpack/test/controller/request_test.rb182
1 files changed, 1 insertions, 181 deletions
diff --git a/actionpack/test/controller/request_test.rb b/actionpack/test/controller/request_test.rb
index 02bb2ee890..c53f1bc2d9 100644
--- a/actionpack/test/controller/request_test.rb
+++ b/actionpack/test/controller/request_test.rb
@@ -407,114 +407,10 @@ class RequestTest < ActiveSupport::TestCase
end
class UrlEncodedRequestParameterParsingTest < ActiveSupport::TestCase
- def setup
- @query_string = "action=create_customer&full_name=David%20Heinemeier%20Hansson&customerId=1"
- @query_string_with_empty = "action=create_customer&full_name="
- @query_string_with_array = "action=create_customer&selected[]=1&selected[]=2&selected[]=3"
- @query_string_with_amps = "action=create_customer&name=Don%27t+%26+Does"
- @query_string_with_multiple_of_same_name =
- "action=update_order&full_name=Lau%20Taarnskov&products=4&products=2&products=3"
- @query_string_with_many_equal = "action=create_customer&full_name=abc=def=ghi"
- @query_string_without_equal = "action"
- @query_string_with_many_ampersands =
- "&action=create_customer&&&full_name=David%20Heinemeier%20Hansson"
- @query_string_with_empty_key = "action=create_customer&full_name=David%20Heinemeier%20Hansson&=Save"
- end
-
- def test_query_string
- assert_equal(
- { "action" => "create_customer", "full_name" => "David Heinemeier Hansson", "customerId" => "1"},
- ActionController::RequestParser.parse_query_parameters(@query_string)
- )
- end
-
- def test_deep_query_string
- expected = {'x' => {'y' => {'z' => '10'}}}
- assert_equal(expected, ActionController::RequestParser.parse_query_parameters('x[y][z]=10'))
- end
-
- def test_deep_query_string_with_array
- assert_equal({'x' => {'y' => {'z' => ['10']}}}, ActionController::RequestParser.parse_query_parameters('x[y][z][]=10'))
- assert_equal({'x' => {'y' => {'z' => ['10', '5']}}}, ActionController::RequestParser.parse_query_parameters('x[y][z][]=10&x[y][z][]=5'))
- end
-
- def test_deep_query_string_with_array_of_hash
- assert_equal({'x' => {'y' => [{'z' => '10'}]}}, ActionController::RequestParser.parse_query_parameters('x[y][][z]=10'))
- assert_equal({'x' => {'y' => [{'z' => '10', 'w' => '10'}]}}, ActionController::RequestParser.parse_query_parameters('x[y][][z]=10&x[y][][w]=10'))
- assert_equal({'x' => {'y' => [{'z' => '10', 'v' => {'w' => '10'}}]}}, ActionController::RequestParser.parse_query_parameters('x[y][][z]=10&x[y][][v][w]=10'))
- end
-
- def test_deep_query_string_with_array_of_hashes_with_one_pair
- assert_equal({'x' => {'y' => [{'z' => '10'}, {'z' => '20'}]}}, ActionController::RequestParser.parse_query_parameters('x[y][][z]=10&x[y][][z]=20'))
- assert_equal("10", ActionController::RequestParser.parse_query_parameters('x[y][][z]=10&x[y][][z]=20')["x"]["y"].first["z"])
- assert_equal("10", ActionController::RequestParser.parse_query_parameters('x[y][][z]=10&x[y][][z]=20').with_indifferent_access[:x][:y].first[:z])
- end
-
- def test_deep_query_string_with_array_of_hashes_with_multiple_pairs
- assert_equal(
- {'x' => {'y' => [{'z' => '10', 'w' => 'a'}, {'z' => '20', 'w' => 'b'}]}},
- ActionController::RequestParser.parse_query_parameters('x[y][][z]=10&x[y][][w]=a&x[y][][z]=20&x[y][][w]=b')
- )
- end
-
- def test_query_string_with_nil
- assert_equal(
- { "action" => "create_customer", "full_name" => ''},
- ActionController::RequestParser.parse_query_parameters(@query_string_with_empty)
- )
- end
-
- def test_query_string_with_array
- assert_equal(
- { "action" => "create_customer", "selected" => ["1", "2", "3"]},
- ActionController::RequestParser.parse_query_parameters(@query_string_with_array)
- )
- end
-
- def test_query_string_with_amps
- assert_equal(
- { "action" => "create_customer", "name" => "Don't & Does"},
- ActionController::RequestParser.parse_query_parameters(@query_string_with_amps)
- )
- end
-
- def test_query_string_with_many_equal
- assert_equal(
- { "action" => "create_customer", "full_name" => "abc=def=ghi"},
- ActionController::RequestParser.parse_query_parameters(@query_string_with_many_equal)
- )
- end
-
- def test_query_string_without_equal
- assert_equal(
- { "action" => nil },
- ActionController::RequestParser.parse_query_parameters(@query_string_without_equal)
- )
- end
-
- def test_query_string_with_empty_key
- assert_equal(
- { "action" => "create_customer", "full_name" => "David Heinemeier Hansson" },
- ActionController::RequestParser.parse_query_parameters(@query_string_with_empty_key)
- )
- end
-
- def test_query_string_with_many_ampersands
- assert_equal(
- { "action" => "create_customer", "full_name" => "David Heinemeier Hansson"},
- ActionController::RequestParser.parse_query_parameters(@query_string_with_many_ampersands)
- )
- end
-
def test_unbalanced_query_string_with_array
assert_equal(
{'location' => ["1", "2"], 'age_group' => ["2"]},
- ActionController::RequestParser.parse_query_parameters("location[]=1&location[]=2&age_group[]=2")
- )
- assert_equal(
- {'location' => ["1", "2"], 'age_group' => ["2"]},
- ActionController::RequestParser.parse_request_parameters({'location[]' => ["1", "2"],
- 'age_group[]' => ["2"]})
+ ActionController::RequestParser.parse_request_parameters({'location[]' => ["1", "2"], 'age_group[]' => ["2"]})
)
end
@@ -814,79 +710,3 @@ class MultipartRequestParameterParsingTest < ActiveSupport::TestCase
end
end
end
-
-class XmlParamsParsingTest < ActiveSupport::TestCase
- def test_hash_params
- person = parse_body("<person><name>David</name></person>")[:person]
- assert_kind_of Hash, person
- assert_equal 'David', person['name']
- end
-
- def test_single_file
- person = parse_body("<person><name>David</name><avatar type='file' name='me.jpg' content_type='image/jpg'>#{ActiveSupport::Base64.encode64('ABC')}</avatar></person>")
-
- assert_equal "image/jpg", person['person']['avatar'].content_type
- assert_equal "me.jpg", person['person']['avatar'].original_filename
- assert_equal "ABC", person['person']['avatar'].read
- end
-
- def test_multiple_files
- person = parse_body(<<-end_body)
- <person>
- <name>David</name>
- <avatars>
- <avatar type='file' name='me.jpg' content_type='image/jpg'>#{ActiveSupport::Base64.encode64('ABC')}</avatar>
- <avatar type='file' name='you.gif' content_type='image/gif'>#{ActiveSupport::Base64.encode64('DEF')}</avatar>
- </avatars>
- </person>
- end_body
-
- assert_equal "image/jpg", person['person']['avatars']['avatar'].first.content_type
- assert_equal "me.jpg", person['person']['avatars']['avatar'].first.original_filename
- assert_equal "ABC", person['person']['avatars']['avatar'].first.read
-
- assert_equal "image/gif", person['person']['avatars']['avatar'].last.content_type
- assert_equal "you.gif", person['person']['avatars']['avatar'].last.original_filename
- assert_equal "DEF", person['person']['avatars']['avatar'].last.read
- end
-
- private
- def parse_body(body)
- env = { 'rack.input' => StringIO.new(body),
- 'CONTENT_TYPE' => 'application/xml',
- 'CONTENT_LENGTH' => body.size.to_s }
- ActionController::Request.new(env).request_parameters
- end
-end
-
-class LegacyXmlParamsParsingTest < XmlParamsParsingTest
- private
- def parse_body(body)
- env = { 'rack.input' => StringIO.new(body),
- 'HTTP_X_POST_DATA_FORMAT' => 'xml',
- 'CONTENT_LENGTH' => body.size.to_s }
- ActionController::Request.new(env).request_parameters
- end
-end
-
-class JsonParamsParsingTest < ActiveSupport::TestCase
- def test_hash_params_for_application_json
- person = parse_body({:person => {:name => "David"}}.to_json,'application/json')[:person]
- assert_kind_of Hash, person
- assert_equal 'David', person['name']
- end
-
- def test_hash_params_for_application_jsonrequest
- person = parse_body({:person => {:name => "David"}}.to_json,'application/jsonrequest')[:person]
- assert_kind_of Hash, person
- assert_equal 'David', person['name']
- end
-
- private
- def parse_body(body,content_type)
- env = { 'rack.input' => StringIO.new(body),
- 'CONTENT_TYPE' => content_type,
- 'CONTENT_LENGTH' => body.size.to_s }
- ActionController::Request.new(env).request_parameters
- end
-end