Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extra_params use Hash#deep_merge! instead of merge #182

Merged
merged 3 commits into from
Dec 9, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
5 changes: 3 additions & 2 deletions lib/rspec_api_documentation/dsl/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ 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
Expand Down 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