diff --git a/README.md b/README.md index 368198b8..b8b1a7c5 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/rspec_api_documentation/dsl/endpoint.rb b/lib/rspec_api_documentation/dsl/endpoint.rb index 76ba1402..5547edf3 100644 --- a/lib/rspec_api_documentation/dsl/endpoint.rb +++ b/lib/rspec_api_documentation/dsl/endpoint.rb @@ -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 diff --git a/spec/dsl_spec.rb b/spec/dsl_spec.rb index c7a1420c..b0257928 100644 --- a/spec/dsl_spec.rb +++ b/spec/dsl_spec.rb @@ -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