Merge pull request #2178 from betagouv/frederic/fix_2176-api_pagination
[Fix #2176] Allow setting page size in API
This commit is contained in:
commit
e33c59f9be
2 changed files with 8 additions and 1 deletions
|
@ -47,6 +47,6 @@ class API::V1::DossiersController < APIController
|
||||||
end
|
end
|
||||||
|
|
||||||
def per_page # inherited value from will_paginate
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -61,6 +61,13 @@ describe API::V1::DossiersController do
|
||||||
it { expect(subject[:nombre_de_page]).to eq(1) }
|
it { expect(subject[:nombre_de_page]).to eq(1) }
|
||||||
end
|
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
|
describe 'dossiers' do
|
||||||
subject { body[:dossiers] }
|
subject { body[:dossiers] }
|
||||||
it { expect(subject).to be_an(Array) }
|
it { expect(subject).to be_an(Array) }
|
||||||
|
|
Loading…
Reference in a new issue