Allow pagination `Link` headers on API accounts/statuses when pinned true (#29442)

pull/29434/head
Matt Jankowski 2024-02-29 09:21:56 -05:00 committed by GitHub
parent edd6aa70e1
commit eb1b8f69de
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 47 additions and 3 deletions

View File

@ -4,7 +4,7 @@ class Api::V1::Accounts::StatusesController < Api::BaseController
before_action -> { authorize_if_got_token! :read, :'read:statuses' }
before_action :set_account
after_action :insert_pagination_headers, unless: -> { truthy_param?(:pinned) }
after_action :insert_pagination_headers
def index
cache_if_unauthenticated!

View File

@ -18,7 +18,8 @@ describe Api::V1::Accounts::StatusesController do
get :index, params: { account_id: user.account.id, limit: 1 }
expect(response).to have_http_status(200)
expect(response.headers['Link'].links.size).to eq(2)
expect(links_from_header.size)
.to eq(2)
end
context 'with only media' do
@ -55,10 +56,45 @@ describe Api::V1::Accounts::StatusesController do
Fabricate(:status_pin, account: user.account, status: Fabricate(:status, account: user.account))
end
it 'returns http success' do
it 'returns http success and includes a header link' do
get :index, params: { account_id: user.account.id, pinned: true }
expect(response).to have_http_status(200)
expect(links_from_header.size)
.to eq(1)
expect(links_from_header)
.to contain_exactly(
have_attributes(
href: /pinned=true/,
attr_pairs: contain_exactly(['rel', 'prev'])
)
)
end
end
context 'with enough pinned statuses to paginate' do
before do
stub_const 'Api::BaseController::DEFAULT_STATUSES_LIMIT', 1
2.times { Fabricate(:status_pin, account: user.account) }
end
it 'returns http success and header pagination links to prev and next' do
get :index, params: { account_id: user.account.id, pinned: true }
expect(response).to have_http_status(200)
expect(links_from_header.size)
.to eq(2)
expect(links_from_header)
.to contain_exactly(
have_attributes(
href: /pinned=true/,
attr_pairs: contain_exactly(['rel', 'next'])
),
have_attributes(
href: /pinned=true/,
attr_pairs: contain_exactly(['rel', 'prev'])
)
)
end
end
@ -98,4 +134,12 @@ describe Api::V1::Accounts::StatusesController do
end
end
end
private
def links_from_header
response
.headers['Link']
.links
end
end