Skip to content

Commit 4bb6af5

Browse files
committed
Merge pull request #184 from jsmestad/bugfix/empty-hash-is-bad
Fix for `#to_json` on empty hash creating bad params payload
2 parents f27adf6 + 6f125a2 commit 4bb6af5

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/rspec_api_documentation/dsl/endpoint.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ def do_request(extra_params = {})
3838
if method == :get && !query_string.blank?
3939
path_or_query += "?#{query_string}"
4040
else
41-
if respond_to?(:raw_post)
41+
if respond_to?(:raw_post)
4242
params_or_body = raw_post
4343
else
4444
formatter = RspecApiDocumentation.configuration.post_body_formatter
4545
case formatter
4646
when :json
47-
params_or_body = params.to_json
47+
params_or_body = params.empty? ? nil : params.to_json
4848
when :xml
4949
params_or_body = params.to_xml
5050
when Proc

spec/dsl_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,18 @@
477477
RspecApiDocumentation.instance_variable_set(:@configuration, RspecApiDocumentation::Configuration.new)
478478
end
479479

480+
get "/orders" do
481+
specify "formatting by json without parameters" do
482+
RspecApiDocumentation.configure do |config|
483+
config.post_body_formatter = :json
484+
end
485+
486+
expect(client).to receive(method).with(path, nil, nil)
487+
488+
do_request
489+
end
490+
end
491+
480492
post "/orders" do
481493
parameter :page, "Page to view"
482494

0 commit comments

Comments
 (0)