Skip to content

Commit

Permalink
Merge pull request #182 from jsmestad/patch-1
Browse files Browse the repository at this point in the history
extra_params use Hash#deep_merge! instead of merge
  • Loading branch information
oestrich committed Dec 9, 2014
2 parents 4bb6af5 + 09ccb97 commit 2f1fe19
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/rspec_api_documentation.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'active_support'
require 'active_support/inflector'
require 'active_support/core_ext/hash/conversions'
require 'active_support/core_ext/hash/deep_merge'
require 'cgi'
require 'json'

Expand Down
3 changes: 2 additions & 1 deletion lib/rspec_api_documentation/dsl/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def params
parameters = example.metadata.fetch(:parameters, {}).inject({}) do |hash, param|
set_param(hash, param)
end
parameters.merge!(extra_params)
parameters.deep_merge!(extra_params)
parameters
end

Expand Down Expand Up @@ -128,6 +128,7 @@ def rspec_api_documentation_client
def extra_params
return {} if @extra_params.nil?
@extra_params.inject({}) do |h, (k, v)|
v = v.is_a?(Hash) ? v.stringify_keys : v
h[k.to_s] = v
h
end
Expand Down
14 changes: 14 additions & 0 deletions spec/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,9 @@
context "auto request" do
post "/orders" do
parameter :order_type, "Type of order"
parameter :amount, "Amount of order", scope: :order
parameter :name, "Name of order", scope: :order


context "no extra params" do
before do
Expand All @@ -382,6 +385,17 @@

example_request "should take an optional parameter hash", :order_type => "big"
end

context "extra options for do_request with scoped hash" do
before do
expect(client).to receive(:post).with("/orders", {"order_type" => "big", "order" => {"amount" => "19.99", "name" => "Friday Order"}}, nil)
end

let(:amount) { '19.99' }
let(:name) { 'Monday Order' }

example_request "should deep merge the optional parameter hash", {:order_type => 'big', :order => {:name => 'Friday Order'}}
end
end
end

Expand Down

0 comments on commit 2f1fe19

Please sign in to comment.