Skip to content

Commit 4588a37

Browse files
committed
+ Array params for do_request;
+ spec for Array param in do_request
1 parent 4c76c40 commit 4588a37

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/rspec_api_documentation/dsl/endpoint.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,16 @@ def do_request(extra_params = {})
4646

4747
def query_string
4848
query = params.to_a.map do |param|
49-
param.map! { |a| CGI.escape(a.to_s) }
50-
param.join("=")
49+
if param[1].present? && param[1].is_a?(Array)
50+
param_val = []
51+
param[1].each do |val|
52+
param_val << ["#{param[0].gsub('[]','')}[]", val].map { |a| CGI.escape(a.to_s) }.join("=")
53+
end
54+
param_val
55+
else
56+
param.map! { |a| CGI.escape(a.to_s) }
57+
param.join("=")
58+
end
5159
end
5260
query.join("&")
5361
end

spec/dsl_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,14 @@
403403

404404
example_request "should take an optional parameter hash", :order_type => "big"
405405
end
406+
407+
context "Array options for do_request" do
408+
before do
409+
client.should_receive(:post).with("/orders", {"pizza_type" => ["big", "tasty"] }, nil)
410+
end
411+
412+
example_request "should take an optional parameter hash", :pizza_type => ["big", "tasty"]
413+
end
406414
end
407415
end
408416

0 commit comments

Comments
 (0)