From c77aaec4c31198f042b270eaa8859a00df767d7f Mon Sep 17 00:00:00 2001 From: Ramkumar Date: Thu, 10 Aug 2017 21:17:35 +0530 Subject: [PATCH] #1662 - Add a spec for sending single element to an array --- spec/grape/endpoint_spec.rb | 52 +++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/spec/grape/endpoint_spec.rb b/spec/grape/endpoint_spec.rb index ff06105388..8967c68836 100644 --- a/spec/grape/endpoint_spec.rb +++ b/spec/grape/endpoint_spec.rb @@ -1493,4 +1493,56 @@ def memoized ) end end + + context 'array params with XML content type' do + let(:single_element_request) do + ' + + + 100 + + ' + end + + let(:multiple_element_request) do + ' + + + 100 + + + 200 + + ' + end + before do + subject.format :xml + subject.content_type :xml, 'application/xml; charset=utf-8' + subject.params do + requires :admin, type: Hash do + requires :products, type: Array do + requires :price, type: String + end + end + end + subject.post do + params[:data] + end + end + context 'with one element' do + it 'returns a successful response' do + post '/', single_element_request, 'CONTENT_TYPE' => 'application/xml' + expect(last_request.params['admin']['products'][0]['price']['__content__']).to eq('100') + # expect(last_response.status).to eq(201) + end + end + + context 'with multiple elements' do + it 'returns a successful response' do + post '/', multiple_element_request, 'CONTENT_TYPE' => 'application/xml' + expect(last_request.params['admin']['products'][0]['price']['__content__']).to eq('100') + expect(last_request.params['admin']['products'][1]['price']['__content__']).to eq('200') + end + end + end end