mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-18 04:19:27 +00:00
Allow pagination Link
headers on API accounts/statuses when pinned true (#29442)
This commit is contained in:
parent
edd6aa70e1
commit
eb1b8f69de
|
@ -4,7 +4,7 @@ class Api::V1::Accounts::StatusesController < Api::BaseController
|
||||||
before_action -> { authorize_if_got_token! :read, :'read:statuses' }
|
before_action -> { authorize_if_got_token! :read, :'read:statuses' }
|
||||||
before_action :set_account
|
before_action :set_account
|
||||||
|
|
||||||
after_action :insert_pagination_headers, unless: -> { truthy_param?(:pinned) }
|
after_action :insert_pagination_headers
|
||||||
|
|
||||||
def index
|
def index
|
||||||
cache_if_unauthenticated!
|
cache_if_unauthenticated!
|
||||||
|
|
|
@ -18,7 +18,8 @@ describe Api::V1::Accounts::StatusesController do
|
||||||
get :index, params: { account_id: user.account.id, limit: 1 }
|
get :index, params: { account_id: user.account.id, limit: 1 }
|
||||||
|
|
||||||
expect(response).to have_http_status(200)
|
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
|
end
|
||||||
|
|
||||||
context 'with only media' do
|
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))
|
Fabricate(:status_pin, account: user.account, status: Fabricate(:status, account: user.account))
|
||||||
end
|
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 }
|
get :index, params: { account_id: user.account.id, pinned: true }
|
||||||
|
|
||||||
expect(response).to have_http_status(200)
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -98,4 +134,12 @@ describe Api::V1::Accounts::StatusesController do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def links_from_header
|
||||||
|
response
|
||||||
|
.headers['Link']
|
||||||
|
.links
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue