Skip to content

Commit 2f1fe19

Browse files
committed
Merge pull request #182 from jsmestad/patch-1
extra_params use Hash#deep_merge! instead of merge
2 parents 4bb6af5 + 09ccb97 commit 2f1fe19

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

lib/rspec_api_documentation.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require 'active_support'
22
require 'active_support/inflector'
33
require 'active_support/core_ext/hash/conversions'
4+
require 'active_support/core_ext/hash/deep_merge'
45
require 'cgi'
56
require 'json'
67

lib/rspec_api_documentation/dsl/endpoint.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def params
6666
parameters = example.metadata.fetch(:parameters, {}).inject({}) do |hash, param|
6767
set_param(hash, param)
6868
end
69-
parameters.merge!(extra_params)
69+
parameters.deep_merge!(extra_params)
7070
parameters
7171
end
7272

@@ -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)