From 268f7870d2735c59265dedd422d0efe73d852d3d Mon Sep 17 00:00:00 2001 From: Michal Cichra Date: Thu, 28 Mar 2013 10:43:10 +0100 Subject: [PATCH] allow parameters without values --- lib/rspec_api_documentation/client_base.rb | 2 +- spec/rack_test_client_spec.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/rspec_api_documentation/client_base.rb b/lib/rspec_api_documentation/client_base.rb index 01695884..99ff3d95 100644 --- a/lib/rspec_api_documentation/client_base.rb +++ b/lib/rspec_api_documentation/client_base.rb @@ -70,7 +70,7 @@ def query_hash strings = query_string.split("&") arrays = strings.map do |segment| k,v = segment.split("=") - [k, CGI.unescape(v)] + [k, v && CGI.unescape(v)] end Hash[arrays] end diff --git a/spec/rack_test_client_spec.rb b/spec/rack_test_client_spec.rb index 6ef5cad6..335a774f 100644 --- a/spec/rack_test_client_spec.rb +++ b/spec/rack_test_client_spec.rb @@ -80,6 +80,19 @@ class StubApp < Sinatra::Base end end + context "when doing request without parameter value" do + before do + test_client.post "/greet?query=&other=exists" + end + + context "when examples should be documented", :document => true do + it "should still argument the metadata" do + metadata = example.metadata[:requests].first + metadata[:request_query_parameters].should == {'query' => nil, 'other' => 'exists'} + end + end + end + context "after a request is made" do before do test_client.post "/greet?query=test+query", post_data, headers