From acaaea695bf0fd82adbdc84e48fc370ca4a7e908 Mon Sep 17 00:00:00 2001 From: claudiob Date: Sun, 1 Sep 2013 22:47:30 -0700 Subject: [PATCH] Allow requests with extra_params and no parameters Without this commit, the following request: post '/orders' do example_request 'should take an optional parameter hash', order_type: 'big' do ... end end would **not receive** the POST body/param `order_type: 'big'` specified. The reason is that the function `params` was returning nil if example.metadata[:parameters] was undefined, and the only one to define example.metadata[:parameters] was to have previously called "parameter". In other words, requests were not allowed to have so-called "extra parameters" unless they had at least one "parameter" specified. This commit removes this restrictions, allowing requests to specify all their parameters "inline". --- lib/rspec_api_documentation/dsl/endpoint.rb | 3 +-- spec/dsl_spec.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/rspec_api_documentation/dsl/endpoint.rb b/lib/rspec_api_documentation/dsl/endpoint.rb index 6373b633..222392c7 100644 --- a/lib/rspec_api_documentation/dsl/endpoint.rb +++ b/lib/rspec_api_documentation/dsl/endpoint.rb @@ -52,8 +52,7 @@ def query_string end def params - return unless example.metadata[:parameters] - parameters = example.metadata[:parameters].inject({}) do |hash, param| + parameters = example.metadata.fetch(:parameters, {}).inject({}) do |hash, param| set_param(hash, param) end parameters.merge!(extra_params) diff --git a/spec/dsl_spec.rb b/spec/dsl_spec.rb index 5902665e..207e9d6f 100644 --- a/spec/dsl_spec.rb +++ b/spec/dsl_spec.rb @@ -357,6 +357,18 @@ end end + context "request with only extra params" do + post "/orders" do + context "extra options for do_request" do + before do + client.should_receive(:post).with("/orders", {"order_type" => "big"}, nil) + end + + example_request "should take an optional parameter hash", :order_type => "big" + end + end + end + context "last_response helpers" do put "/orders" do it "status" do