Skip to content

Commit 09ccb97

Browse files
committed
Add spec to verify deep_merge functionality
1 parent 608da0c commit 09ccb97

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/rspec_api_documentation/dsl/endpoint.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ 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
@@ -128,6 +128,7 @@ def rspec_api_documentation_client
128128
def extra_params
129129
return {} if @extra_params.nil?
130130
@extra_params.inject({}) do |h, (k, v)|
131+
v = v.is_a?(Hash) ? v.stringify_keys : v
131132
h[k.to_s] = v
132133
h
133134
end

spec/dsl_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,9 @@
362362
context "auto request" do
363363
post "/orders" do
364364
parameter :order_type, "Type of order"
365+
parameter :amount, "Amount of order", scope: :order
366+
parameter :name, "Name of order", scope: :order
367+
365368

366369
context "no extra params" do
367370
before do
@@ -382,6 +385,17 @@
382385

383386
example_request "should take an optional parameter hash", :order_type => "big"
384387
end
388+
389+
context "extra options for do_request with scoped hash" do
390+
before do
391+
expect(client).to receive(:post).with("/orders", {"order_type" => "big", "order" => {"amount" => "19.99", "name" => "Friday Order"}}, nil)
392+
end
393+
394+
let(:amount) { '19.99' }
395+
let(:name) { 'Monday Order' }
396+
397+
example_request "should deep merge the optional parameter hash", {:order_type => 'big', :order => {:name => 'Friday Order'}}
398+
end
385399
end
386400
end
387401

0 commit comments

Comments
 (0)