Skip to content

Commit b8600c8

Browse files
committed
Replace custom query string to hash parser with Rack::Utils.parse_nested_query
Closes #140
1 parent ac91b0b commit b8600c8

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

lib/rspec_api_documentation/client_base.rb

+1-6
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,7 @@ def document_example(method, path)
7474
end
7575

7676
def query_hash
77-
strings = query_string.split("&")
78-
arrays = strings.map do |segment|
79-
k,v = segment.split("=")
80-
[k, v && CGI.unescape(v)]
81-
end
82-
Hash[arrays]
77+
Rack::Utils.parse_nested_query(query_string)
8378
end
8479

8580
def headers(method, path, params, request_headers)

spec/rack_test_client_spec.rb

+8-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class StubApp < Sinatra::Base
8888
context "when examples should be documented", :document => true do
8989
it "should still argument the metadata" do |example|
9090
metadata = example.metadata[:requests].first
91-
expect(metadata[:request_query_parameters]).to eq({'query' => nil, 'other' => 'exists'})
91+
expect(metadata[:request_query_parameters]).to eq({'query' => "", 'other' => 'exists'})
9292
end
9393
end
9494
end
@@ -136,6 +136,13 @@ class StubApp < Sinatra::Base
136136
expect(example.metadata[:requests].first[:request_body]).to be_nil
137137
end
138138
end
139+
140+
specify "array parameters" do |example|
141+
test_client.post "/greet?query[]=test&query[]=query", post_data, headers
142+
143+
metadata = example.metadata[:requests].last
144+
expect(metadata[:request_query_parameters]).to eq({ "query" => ["test", "query"] })
145+
end
139146
end
140147
end
141148
end

0 commit comments

Comments
 (0)