Skip to content

Commit

Permalink
Replace custom query string to hash parser with Rack::Utils.parse_nes…
Browse files Browse the repository at this point in the history
…ted_query

Closes #140
  • Loading branch information
oestrich committed Jul 15, 2014
1 parent ac91b0b commit b8600c8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
7 changes: 1 addition & 6 deletions lib/rspec_api_documentation/client_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,7 @@ def document_example(method, path)
end

def query_hash
strings = query_string.split("&")
arrays = strings.map do |segment|
k,v = segment.split("=")
[k, v && CGI.unescape(v)]
end
Hash[arrays]
Rack::Utils.parse_nested_query(query_string)
end

def headers(method, path, params, request_headers)
Expand Down
9 changes: 8 additions & 1 deletion spec/rack_test_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class StubApp < Sinatra::Base
context "when examples should be documented", :document => true do
it "should still argument the metadata" do |example|
metadata = example.metadata[:requests].first
expect(metadata[:request_query_parameters]).to eq({'query' => nil, 'other' => 'exists'})
expect(metadata[:request_query_parameters]).to eq({'query' => "", 'other' => 'exists'})
end
end
end
Expand Down Expand Up @@ -136,6 +136,13 @@ class StubApp < Sinatra::Base
expect(example.metadata[:requests].first[:request_body]).to be_nil
end
end

specify "array parameters" do |example|
test_client.post "/greet?query[]=test&query[]=query", post_data, headers

metadata = example.metadata[:requests].last
expect(metadata[:request_query_parameters]).to eq({ "query" => ["test", "query"] })
end
end
end
end

0 comments on commit b8600c8

Please sign in to comment.