@@ -272,6 +272,55 @@ def expected_payload(method, overrides = {})
272272
273273 %i( post post_form put patch ) . each do |http_method |
274274 context ".#{ http_method } " do
275+ context 'when body is an Array' do
276+ let ( :payload ) { [ { permission_name : 'read:data' , resource_server_identifier : 'https://api.example.com' } ] }
277+
278+ if http_method == :post_form
279+ it 'sends the array as-is without wrapping in a Hash' do
280+ expect ( RestClient ::Request ) . to receive ( :execute ) do |args |
281+ expect ( args [ :payload ] ) . to be_an ( Array )
282+ expect ( args [ :payload ] ) . to eq ( payload )
283+ end . and_return ( StubResponse . new ( '[]' , true , 200 ) )
284+
285+ @instance . send ( http_method , '/test' , payload )
286+ end
287+ else
288+ it 'sends the array as-is without wrapping in a Hash' do
289+ expect ( RestClient ::Request ) . to receive ( :execute ) do |args |
290+ parsed = JSON . parse ( args [ :payload ] , symbolize_names : true )
291+ expect ( parsed ) . to be_an ( Array )
292+ expect ( parsed ) . to eq ( payload )
293+ end . and_return ( StubResponse . new ( '[]' , true , 200 ) )
294+
295+ @instance . send ( http_method , '/test' , payload )
296+ end
297+ end
298+ end
299+
300+ context 'when body is a Hash' do
301+ let ( :payload ) { { permission_name : 'read:data' , resource_server_identifier : 'https://api.example.com' } }
302+
303+ if http_method == :post_form
304+ it 'sends the Hash without modification' do
305+ expect ( RestClient ::Request ) . to receive ( :execute ) do |args |
306+ expect ( args [ :payload ] ) . to be_a ( Hash )
307+ expect ( args [ :payload ] ) . to include ( payload )
308+ end . and_return ( StubResponse . new ( '{}' , true , 200 ) )
309+
310+ @instance . send ( http_method , '/test' , payload )
311+ end
312+ else
313+ it 'sends the Hash as JSON without modification' do
314+ expect ( RestClient ::Request ) . to receive ( :execute ) do |args |
315+ parsed = JSON . parse ( args [ :payload ] , symbolize_names : true )
316+ expect ( parsed ) . to be_a ( Hash )
317+ expect ( parsed ) . to eq ( payload )
318+ end . and_return ( StubResponse . new ( '{}' , true , 200 ) )
319+
320+ @instance . send ( http_method , '/test' , payload )
321+ end
322+ end
323+ end
275324 it { expect ( @instance ) . to respond_to ( http_method . to_sym ) }
276325 it "should call send http #{ http_method } method to path defined through HTTP" do
277326 expect ( RestClient ::Request ) . to receive ( :execute ) . with ( expected_payload ( http_method ) )
@@ -465,6 +514,7 @@ def expected_payload(method, overrides = {})
465514 end
466515 end
467516 end
517+
468518 end
469519end
470520
0 commit comments