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

rename config post_body_formatter to be request_body_formatter #244

Merged
merged 1 commit into from
Dec 11, 2015
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ RspecApiDocumentation.configure do |config|

# Change how the post body is formatted by default, you can still override by `raw_post`
# Can be :json, :xml, or a proc that will be passed the params
config.post_body_formatter = Proc.new { |params| params }
config.request_body_formatter = Proc.new { |params| params }

# Change the embedded style for HTML output. This file will not be processed by
# RspecApiDocumentation and should be plain CSS.
Expand Down
7 changes: 5 additions & 2 deletions lib/rspec_api_documentation/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,21 @@ def self.add_setting(name, opts = {})
add_setting :response_headers_to_include, :default => nil
add_setting :html_embedded_css_file, :default => nil

# renamed to request_body_formatter. here for backwards compatibility
add_setting :post_body_formatter, :default => nil

# Change how the post body is formatted by default, you can still override by `raw_post`
# Can be :json, :xml, or a proc that will be passed the params
#
# RspecApiDocumentation.configure do |config|
# config.post_body_formatter = Proc.new do |params|
# config.request_body_formatter = Proc.new do |params|
# # convert to whatever you want
# params.to_s
# end
# end
#
# See RspecApiDocumentation::DSL::Endpoint#do_request
add_setting :post_body_formatter, :default => Proc.new { |_| Proc.new { |params| params } }
add_setting :request_body_formatter, :default => Proc.new { |_| RspecApiDocumentation.configuration.post_body_formatter || Proc.new { |params| params } }

def client_method=(new_client_method)
RspecApiDocumentation::DSL::Resource.module_eval <<-RUBY
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec_api_documentation/dsl/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def do_request(extra_params = {})
if respond_to?(:raw_post)
params_or_body = raw_post
else
formatter = RspecApiDocumentation.configuration.post_body_formatter
formatter = RspecApiDocumentation.configuration.request_body_formatter
case formatter
when :json
params_or_body = params.empty? ? nil : params.to_json
Expand Down
2 changes: 1 addition & 1 deletion spec/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
its(:html_embedded_css_file) { should be_nil }

specify "post body formatter" do
expect(configuration.post_body_formatter.call({ :page => 1})).to eq({ :page => 1 })
expect(configuration.request_body_formatter.call({ :page => 1})).to eq({ :page => 1 })
end
end

Expand Down
16 changes: 13 additions & 3 deletions spec/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@
get "/orders" do
specify "formatting by json without parameters" do
RspecApiDocumentation.configure do |config|
config.post_body_formatter = :json
config.request_body_formatter = :json
end

expect(client).to receive(method).with(path, nil, nil)
Expand All @@ -530,6 +530,16 @@
let(:page) { 1 }

specify "formatting by json" do
RspecApiDocumentation.configure do |config|
config.request_body_formatter = :json
end

expect(client).to receive(method).with(path, { :page => 1 }.to_json , nil)

do_request
end

specify "formatting by json via legacy config" do
RspecApiDocumentation.configure do |config|
config.post_body_formatter = :json
end
Expand All @@ -541,7 +551,7 @@

specify "formatting by xml" do
RspecApiDocumentation.configure do |config|
config.post_body_formatter = :xml
config.request_body_formatter = :xml
end

expect(client).to receive(method).with(path, { :page => 1 }.to_xml , nil)
Expand All @@ -551,7 +561,7 @@

specify "formatting by proc" do
RspecApiDocumentation.configure do |config|
config.post_body_formatter = Proc.new do |params|
config.request_body_formatter = Proc.new do |params|
{ :from => "a proc" }.to_json
end
end
Expand Down