[Fix #2176] Allow setting page size in API

This commit is contained in:
Frederic Merizen 2018-06-29 17:34:35 +02:00
parent 4f9bf73fe5
commit b003fe9221
2 changed files with 8 additions and 1 deletions

View file

@ -47,6 +47,6 @@ class API::V1::DossiersController < APIController
end
def per_page # inherited value from will_paginate
[params[:resultats_par_page] || DEFAULT_PAGE_SIZE, 1000].min
[params[:resultats_par_page]&.to_i || DEFAULT_PAGE_SIZE, 1000].min
end
end

View file

@ -61,6 +61,13 @@ describe API::V1::DossiersController do
it { expect(subject[:nombre_de_page]).to eq(1) }
end
describe 'with custom resultats_par_page' do
let(:retour) { get :index, params: { token: admin.api_token, procedure_id: procedure_id, resultats_par_page: 18 } }
subject { body[:pagination] }
it { is_expected.to have_key(:resultats_par_page) }
it { expect(subject[:resultats_par_page]).to eq(18) }
end
describe 'dossiers' do
subject { body[:dossiers] }
it { expect(subject).to be_an(Array) }