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

#1662 - Add a spec for sending single element to an array #1675

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
52 changes: 52 additions & 0 deletions spec/grape/endpoint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1493,4 +1493,56 @@ def memoized
)
end
end

context 'array params with XML content type' do
let(:single_element_request) do
'<?xml version="1.0" encoding="UTF-8" ?>
<admin>
<products>
<price>100</price>
</products>
</admin>'
end

let(:multiple_element_request) do
'<?xml version="1.0" encoding="UTF-8" ?>
<admin>
<products>
<price>100</price>
</products>
<products>
<price>200</price>
</products>
</admin>'
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