Skip to content
This repository
Browse code

Cleanup ul_encoded_params_parsing_test

  • Loading branch information...
commit 3db80b5496caf21a24b97e04162dac5155cf5564 1 parent 19f842b
Genadi Samokovarov authored July 05, 2013
52  actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb
@@ -17,10 +17,9 @@ def teardown
17 17
   end
18 18
 
19 19
   test "parses unbalanced query string with array" do
20  
-    assert_parses(
21  
-       {'location' => ["1", "2"], 'age_group' => ["2"]},
22  
-      "location[]=1&location[]=2&age_group[]=2"
23  
-    )
  20
+    query    = "location[]=1&location[]=2&age_group[]=2"
  21
+    expected = { 'location' => ["1", "2"], 'age_group' => ["2"] }
  22
+    assert_parses expected, query
24 23
   end
25 24
 
26 25
   test "parses nested hash" do
@@ -30,9 +29,17 @@ def teardown
30 29
       "note[viewers][viewer][][type]=Group",
31 30
       "note[viewers][viewer][][id]=2"
32 31
     ].join("&")
33  
-
34  
-    expected = { "note" => { "viewers"=>{"viewer"=>[{ "id"=>"1", "type"=>"User"}, {"type"=>"Group", "id"=>"2"} ]} } }
35  
-    assert_parses(expected, query)
  32
+    expected = {
  33
+      "note" => {
  34
+        "viewers" => {
  35
+          "viewer" => [
  36
+            { "id" => "1", "type" => "User" },
  37
+            { "type" => "Group", "id" => "2" }
  38
+          ]
  39
+        }
  40
+      }
  41
+    }
  42
+    assert_parses expected, query
36 43
   end
37 44
 
38 45
   test "parses more complex nesting" do
@@ -48,7 +55,6 @@ def teardown
48 55
       "products[second]=Pc",
49 56
       "=Save"
50 57
     ].join("&")
51  
-
52 58
     expected =  {
53 59
       "customers" => {
54 60
         "boston" => {
@@ -70,13 +76,12 @@ def teardown
70 76
         "second" => "Pc"
71 77
       }
72 78
     }
73  
-
74 79
     assert_parses expected, query
75 80
   end
76 81
 
77 82
   test "parses params with array" do
78  
-    query = "selected[]=1&selected[]=2&selected[]=3"
79  
-    expected = { "selected" => [ "1", "2", "3" ] }
  83
+    query    = "selected[]=1&selected[]=2&selected[]=3"
  84
+    expected = { "selected" => ["1", "2", "3"] }
80 85
     assert_parses expected, query
81 86
   end
82 87
 
@@ -88,13 +93,13 @@ def teardown
88 93
 
89 94
   test "parses params with array prefix and hashes" do
90 95
     query    = "a[][b][c]=d"
91  
-    expected = {"a" => [{"b" => {"c" => "d"}}]}
  96
+    expected = { "a" => [{ "b" => { "c" => "d" } }] }
92 97
     assert_parses expected, query
93 98
   end
94 99
 
95 100
   test "parses params with complex nesting" do
96 101
     query    = "a[][b][c][][d][]=e"
97  
-    expected = {"a" => [{"b" => {"c" => [{"d" => ["e"]}]}}]}
  102
+    expected = { "a" => [{ "b" => { "c" => [{ "d" => ["e"] }] } }] }
98 103
     assert_parses expected, query
99 104
   end
100 105
 
@@ -104,7 +109,6 @@ def teardown
104 109
       "something_else=blah",
105 110
       "logo=#{File.expand_path(__FILE__)}"
106 111
     ].join("&")
107  
-
108 112
     expected = {
109 113
       "customers" => {
110 114
         "boston" => {
@@ -116,22 +120,20 @@ def teardown
116 120
       "something_else" => "blah",
117 121
       "logo" => File.expand_path(__FILE__),
118 122
     }
119  
-
120 123
     assert_parses expected, query
121 124
   end
122 125
 
123 126
   test "parses params with Safari 2 trailing null character" do
124  
-    query = "selected[]=1&selected[]=2&selected[]=3\0"
125  
-    expected = { "selected" => [ "1", "2", "3" ] }
  127
+    query    = "selected[]=1&selected[]=2&selected[]=3\0"
  128
+    expected = { "selected" => ["1", "2", "3"] }
126 129
     assert_parses expected, query
127 130
   end
128 131
 
129 132
   test "ambiguous params returns a bad request" do
130 133
     with_routing do |set|
131 134
       set.draw do
132  
-        post ':action', :to => ::UrlEncodedParamsParsingTest::TestController
  135
+        post ':action', to: ::UrlEncodedParamsParsingTest::TestController
133 136
       end
134  
-
135 137
       post "/parse", "foo[]=bar&foo[4]=bar"
136 138
       assert_response :bad_request
137 139
     end
@@ -141,7 +143,7 @@ def teardown
141 143
     def with_test_routing
142 144
       with_routing do |set|
143 145
         set.draw do
144  
-          post ':action', :to => ::UrlEncodedParamsParsingTest::TestController
  146
+          post ':action', to: ::UrlEncodedParamsParsingTest::TestController
145 147
         end
146 148
         yield
147 149
       end
@@ -151,8 +153,8 @@ def assert_parses(expected, actual)
151 153
       with_test_routing do
152 154
         post "/parse", actual
153 155
         assert_response :ok
154  
-        assert_equal(expected, TestController.last_request_parameters)
155  
-        assert_utf8(TestController.last_request_parameters)
  156
+        assert_equal expected, TestController.last_request_parameters
  157
+        assert_utf8 TestController.last_request_parameters
156 158
       end
157 159
     end
158 160
 
@@ -167,11 +169,11 @@ def assert_utf8(object)
167 169
       object.each_value do |v|
168 170
         case v
169 171
         when Hash
170  
-          assert_utf8(v)
  172
+          assert_utf8 v
171 173
         when Array
172  
-          v.each {|el| assert_utf8(el) }
  174
+          v.each { |el| assert_utf8 el }
173 175
         else
174  
-          assert_utf8(v)
  176
+          assert_utf8 v
175 177
         end
176 178
       end
177 179
     end

0 notes on commit 3db80b5

Please sign in to comment.
Something went wrong with that request. Please try again.