Methods
- setup
- test_parse_params
- test_parse_params_from_multipart_upload
- test_parse_params_with_file
- test_query_string
- test_query_string_with_nil
- xtest_query_string_multiple_of_same_name
Public Instance methods
[ show source ]
# File test/controller/cgi_test.rb, line 18
18: def setup
19: @query_string = "action=create_customer&full_name=David%20Heinemeier%20Hansson&customerId=1"
20: @query_string_with_nil = "action=create_customer&full_name="
21: @query_string_with_multiple_of_same_name =
22: "action=update_order&full_name=Lau%20Taarnskov&products=4&products=2&products=3"
23: end
[ show source ]
# File test/controller/cgi_test.rb, line 39
39: def test_parse_params
40: input = {
41: "customers[boston][first][name]" => [ "David" ],
42: "customers[boston][first][url]" => [ "http://David" ],
43: "customers[boston][second][name]" => [ "Allan" ],
44: "customers[boston][second][url]" => [ "http://Allan" ],
45: "something_else" => [ "blah" ],
46: "something_nil" => [ nil ],
47: "something_empty" => [ "" ],
48: "products[first]" => [ "Apple Computer" ],
49: "products[second]" => [ "Pc" ]
50: }
51:
52: expected_output = {
53: "customers" => {
54: "boston" => {
55: "first" => {
56: "name" => "David",
57: "url" => "http://David"
58: },
59: "second" => {
60: "name" => "Allan",
61: "url" => "http://Allan"
62: }
63: }
64: },
65: "something_else" => "blah",
66: "something_empty" => "",
67: "something_nil" => "",
68: "products" => {
69: "first" => "Apple Computer",
70: "second" => "Pc"
71: }
72: }
73:
74: assert_equal expected_output, CGIMethods.parse_request_parameters(input)
75: end
[ show source ]
# File test/controller/cgi_test.rb, line 77
77: def test_parse_params_from_multipart_upload
78: mock_file = MockUploadedFile.new
79:
80: input = {
81: "something" => [ StringIO.new("") ],
82: "products[string]" => [ StringIO.new("Apple Computer") ],
83: "products[file]" => [ mock_file ]
84: }
85:
86: expected_output = {
87: "something" => "",
88: "products" => {
89: "string" => "Apple Computer",
90: "file" => mock_file
91: }
92: }
93:
94: assert_equal expected_output, CGIMethods.parse_request_parameters(input)
95: end
[ show source ]
# File test/controller/cgi_test.rb, line 97
97: def test_parse_params_with_file
98: input = {
99: "customers[boston][first][name]" => [ "David" ],
100: "something_else" => [ "blah" ],
101: "logo" => [ File.new(File.dirname(__FILE__) + "/cgi_test.rb").path ]
102: }
103:
104: expected_output = {
105: "customers" => {
106: "boston" => {
107: "first" => {
108: "name" => "David"
109: }
110: }
111: },
112: "something_else" => "blah",
113: "logo" => File.new(File.dirname(__FILE__) + "/cgi_test.rb").path,
114: }
115:
116: assert_equal expected_output, CGIMethods.parse_request_parameters(input)
117: end
[ show source ]
# File test/controller/cgi_test.rb, line 25
25: def test_query_string
26: assert_equal(
27: { "action" => "create_customer", "full_name" => "David Heinemeier Hansson", "customerId" => "1"},
28: CGIMethods.parse_query_parameters(@query_string)
29: )
30: end
[ show source ]
# File test/controller/cgi_test.rb, line 32
32: def test_query_string_with_nil
33: assert_equal(
34: { "action" => "create_customer", "full_name" => nil},
35: CGIMethods.parse_query_parameters(@query_string_with_nil)
36: )
37: end
[ show source ]
# File test/controller/cgi_test.rb, line 119
119: def xtest_query_string_multiple_of_same_name
120: assert_equal(
121: { "action" => "update_order", "full_name" => "Lau Taarnskov", "products" => [4,2,3]},
122: CGIMethods.parse_query_parameters(@query_string_with_multiple_of_same_name)
123: )
124: end