Skip to content

Add ability to pass array parameters to requests #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ resource "Account" do
response_body.should == accounts.reverse
status.should == 200
end

example "Get a list of all accounts with certain types" do
do_request(:type_in => ["pending", "closed"])

response_body.should == accounts.inactive
status.should == 200
end
end

get "/accounts/:id" do
Expand Down
12 changes: 10 additions & 2 deletions lib/rspec_api_documentation/dsl/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,16 @@ def do_request(extra_params = {})

def query_string
query = params.to_a.map do |param|
param.map! { |a| CGI.escape(a.to_s) }
param.join("=")
if param[1].present? && param[1].is_a?(Array)
param_val = []
param[1].each do |val|
param_val << ["#{param[0].gsub('[]','')}[]", val].map { |a| CGI.escape(a.to_s) }.join("=")
end
param_val
else
param.map! { |a| CGI.escape(a.to_s) }
param.join("=")
end
end
query.join("&")
end
Expand Down
8 changes: 8 additions & 0 deletions spec/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,14 @@

example_request "should take an optional parameter hash", :order_type => "big"
end

context "Array options for do_request" do
before do
client.should_receive(:post).with("/orders", {"pizza_type" => ["big", "tasty"] }, nil)
end

example_request "should take an optional parameter hash", :pizza_type => ["big", "tasty"]
end
end
end

Expand Down