File tree Expand file tree Collapse file tree 5 files changed +21
-8
lines changed
lib/rspec_api_documentation Expand file tree Collapse file tree 5 files changed +21
-8
lines changed Original file line number Diff line number Diff line change @@ -138,7 +138,7 @@ RspecApiDocumentation.configure do |config|
138
138
139
139
# Change how the post body is formatted by default, you can still override by `raw_post`
140
140
# Can be :json, :xml, or a proc that will be passed the params
141
- config.post_body_formatter = Proc .new { |params | params }
141
+ config.request_body_formatter = Proc .new { |params | params }
142
142
143
143
# Change how the response body is formatted by default
144
144
# Is proc that will be called with the response_content_type & response_body
Original file line number Diff line number Diff line change @@ -80,18 +80,21 @@ def self.add_setting(name, opts = {})
80
80
add_setting :response_headers_to_include , :default => nil
81
81
add_setting :html_embedded_css_file , :default => nil
82
82
83
+ # renamed to request_body_formatter. here for backwards compatibility
84
+ add_setting :post_body_formatter , :default => nil
85
+
83
86
# Change how the post body is formatted by default, you can still override by `raw_post`
84
87
# Can be :json, :xml, or a proc that will be passed the params
85
88
#
86
89
# RspecApiDocumentation.configure do |config|
87
- # config.post_body_formatter = Proc.new do |params|
90
+ # config.request_body_formatter = Proc.new do |params|
88
91
# # convert to whatever you want
89
92
# params.to_s
90
93
# end
91
94
# end
92
95
#
93
96
# See RspecApiDocumentation::DSL::Endpoint#do_request
94
- add_setting :post_body_formatter , :default => Proc . new { |_ | Proc . new { |params | params } }
97
+ add_setting :request_body_formatter , :default => Proc . new { |_ | RspecApiDocumentation . configuration . post_body_formatter | | Proc . new { |params | params } }
95
98
96
99
# Change how the response body is formatted
97
100
# Can be a proc that will be passed the response body
Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ def do_request(extra_params = {})
41
41
if respond_to? ( :raw_post )
42
42
params_or_body = raw_post
43
43
else
44
- formatter = RspecApiDocumentation . configuration . post_body_formatter
44
+ formatter = RspecApiDocumentation . configuration . request_body_formatter
45
45
case formatter
46
46
when :json
47
47
params_or_body = params . empty? ? nil : params . to_json
Original file line number Diff line number Diff line change 59
59
its ( :html_embedded_css_file ) { should be_nil }
60
60
61
61
specify "post body formatter" do
62
- expect ( configuration . post_body_formatter . call ( { :page => 1 } ) ) . to eq ( { :page => 1 } )
62
+ expect ( configuration . request_body_formatter . call ( { :page => 1 } ) ) . to eq ( { :page => 1 } )
63
63
end
64
64
end
65
65
Original file line number Diff line number Diff line change 515
515
get "/orders" do
516
516
specify "formatting by json without parameters" do
517
517
RspecApiDocumentation . configure do |config |
518
- config . post_body_formatter = :json
518
+ config . request_body_formatter = :json
519
519
end
520
520
521
521
expect ( client ) . to receive ( method ) . with ( path , nil , nil )
530
530
let ( :page ) { 1 }
531
531
532
532
specify "formatting by json" do
533
+ RspecApiDocumentation . configure do |config |
534
+ config . request_body_formatter = :json
535
+ end
536
+
537
+ expect ( client ) . to receive ( method ) . with ( path , { :page => 1 } . to_json , nil )
538
+
539
+ do_request
540
+ end
541
+
542
+ specify "formatting by json via legacy config" do
533
543
RspecApiDocumentation . configure do |config |
534
544
config . post_body_formatter = :json
535
545
end
541
551
542
552
specify "formatting by xml" do
543
553
RspecApiDocumentation . configure do |config |
544
- config . post_body_formatter = :xml
554
+ config . request_body_formatter = :xml
545
555
end
546
556
547
557
expect ( client ) . to receive ( method ) . with ( path , { :page => 1 } . to_xml , nil )
551
561
552
562
specify "formatting by proc" do
553
563
RspecApiDocumentation . configure do |config |
554
- config . post_body_formatter = Proc . new do |params |
564
+ config . request_body_formatter = Proc . new do |params |
555
565
{ :from => "a proc" } . to_json
556
566
end
557
567
end
You can’t perform that action at this time.
0 commit comments