File tree 2 files changed +19
-4
lines changed
2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -53,6 +53,7 @@ def wait!
53
53
# - +response+ -> A NET::HTTP response object
54
54
#
55
55
attr_reader :status_code , :body , :headers
56
+
56
57
def initialize ( response )
57
58
@status_code = response . code
58
59
@body = response . body
@@ -265,7 +266,7 @@ def _(name = nil)
265
266
# (e.g. client.name.name.get())
266
267
#
267
268
# * *Args* :
268
- # - The args are autmoatically passed in
269
+ # - The args are automatically passed in
269
270
# * *Returns* :
270
271
# - Client object or Response object
271
272
#
@@ -296,8 +297,8 @@ def build_http_request(http_method)
296
297
297
298
def update_content_type ( http_method )
298
299
if @request_body && content_type_json?
299
- # If body is a hash, encode it; else leave it alone
300
- @request . body = if @request_body . class == Hash
300
+ # If body is a hash or array , encode it; else leave it alone
301
+ @request . body = if [ Hash , Array ] . include? ( @request_body . class )
301
302
@request_body . to_json
302
303
else
303
304
@request_body
Original file line number Diff line number Diff line change @@ -189,7 +189,7 @@ def test_build_request_post_multipart
189
189
assert_equal ( 'hogebody' , client . request . body )
190
190
end
191
191
192
- def test_json_body_encode
192
+ def test_json_body_encode_hash
193
193
headers = {
194
194
'Content-Type' => 'application/json'
195
195
}
@@ -203,6 +203,20 @@ def test_json_body_encode
203
203
assert_equal ( '{"this_is":"json"}' , response . request_body )
204
204
end
205
205
206
+ def test_json_body_encode_array
207
+ headers = {
208
+ 'Content-Type' => 'application/json'
209
+ }
210
+ client = MockRequestWithRequestBody . new (
211
+ host : 'https://localhost' ,
212
+ request_headers : headers
213
+ )
214
+ name = 'post'
215
+ args = [ { 'request_body' => [ { 'this_is' => 'json' } ] } ]
216
+ response = client . build_request ( name , args )
217
+ assert_equal ( '[{"this_is":"json"}]' , response . request_body )
218
+ end
219
+
206
220
def test_json_body_do_not_reencode
207
221
headers = {
208
222
'Content-Type' => 'application/json'
You can’t perform that action at this time.
0 commit comments