Skip to content
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

Allow requests with extra_params and no parameters #87

Merged
Merged
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
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|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to break if you already have set the parameters to a String (for example doing params.to_json) even when not using any extra_params

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you give an example of setting params to a string? I'm not sure what you mean by that. If you need to send a string you should be using raw_post

let(:raw_post) { params.to_json }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow I feel stupid here (facepalm) -- I was setting let(:raw_data) { params.to_json } instead of let(:raw_post) { ....}. I was getting this error doing the following:

post '/users' do
  let(:raw_data) { params.to_json }

  example 'creating a user' do
    do_request raw_data
  end
end

This causes the error where your passing do_request a string and you get an error saying inject method is not defined (which is accurate).

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