Skip to content

Fix for #to_json on empty hash creating bad params payload #184

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

Merged
merged 1 commit into from
Dec 9, 2014
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
4 changes: 2 additions & 2 deletions lib/rspec_api_documentation/dsl/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ def do_request(extra_params = {})
if method == :get && !query_string.blank?
path_or_query += "?#{query_string}"
else
if respond_to?(:raw_post)
if respond_to?(:raw_post)
params_or_body = raw_post
else
formatter = RspecApiDocumentation.configuration.post_body_formatter
case formatter
when :json
params_or_body = params.to_json
params_or_body = params.empty? ? nil : params.to_json
when :xml
params_or_body = params.to_xml
when Proc
Expand Down
12 changes: 12 additions & 0 deletions spec/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,18 @@
RspecApiDocumentation.instance_variable_set(:@configuration, RspecApiDocumentation::Configuration.new)
end

get "/orders" do
specify "formatting by json without parameters" do
RspecApiDocumentation.configure do |config|
config.post_body_formatter = :json
end

expect(client).to receive(method).with(path, nil, nil)

do_request
end
end

post "/orders" do
parameter :page, "Page to view"

Expand Down