From f9521bc2b54dff1c616ef271024426776e9434e2 Mon Sep 17 00:00:00 2001 From: Daniel M Brasil Date: Mon, 19 Jun 2023 03:53:05 -0300 Subject: [PATCH] Fix incorrect pagination headers in `/api/v2/admin/accounts` (#25477) --- app/controllers/api/v2/admin/accounts_controller.rb | 8 ++++++++ spec/controllers/api/v2/admin/accounts_controller_spec.rb | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/app/controllers/api/v2/admin/accounts_controller.rb b/app/controllers/api/v2/admin/accounts_controller.rb index a89e6835ee..ed39deced2 100644 --- a/app/controllers/api/v2/admin/accounts_controller.rb +++ b/app/controllers/api/v2/admin/accounts_controller.rb @@ -17,6 +17,14 @@ class Api::V2::Admin::AccountsController < Api::V1::Admin::AccountsController private + def next_path + api_v2_admin_accounts_url(pagination_params(max_id: pagination_max_id)) if records_continue? + end + + def prev_path + api_v2_admin_accounts_url(pagination_params(min_id: pagination_since_id)) unless @accounts.empty? + end + def filtered_accounts AccountFilter.new(filter_params).results end diff --git a/spec/controllers/api/v2/admin/accounts_controller_spec.rb b/spec/controllers/api/v2/admin/accounts_controller_spec.rb index 3212ddb844..01a50607dc 100644 --- a/spec/controllers/api/v2/admin/accounts_controller_spec.rb +++ b/spec/controllers/api/v2/admin/accounts_controller_spec.rb @@ -69,5 +69,13 @@ RSpec.describe Api::V2::Admin::AccountsController, type: :controller do end end end + + context 'with limit param' do + let(:params) { { limit: 1 } } + + it 'sets the correct pagination headers' do + expect(response.headers['Link'].find_link(%w(rel next)).href).to eq api_v2_admin_accounts_url(limit: 1, max_id: admin_account.id) + end + end end end