Skip to content

Commit

Permalink
Merge pull request #184 from jsmestad/bugfix/empty-hash-is-bad
Browse files Browse the repository at this point in the history
Fix for `#to_json` on empty hash creating bad params payload
  • Loading branch information
oestrich committed Dec 9, 2014
2 parents f27adf6 + 6f125a2 commit 4bb6af5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
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

0 comments on commit 4bb6af5

Please sign in to comment.