Merge pull request #2178 from betagouv/frederic/fix_2176-api_pagination

[Fix #2176] Allow setting page size in API
This commit is contained in:
gregoirenovel 2018-07-02 11:02:02 +02:00 committed by GitHub
commit e33c59f9be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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) }