Skip to content

Commit

Permalink
Allow requests with extra_params and no parameters
Browse files Browse the repository at this point in the history
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".
  • Loading branch information
claudiob committed Sep 2, 2013
1 parent 9a5c79e commit acaaea6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/rspec_api_documentation/dsl/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions spec/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit acaaea6

Please sign in to comment.