Reduce request/response round-trips in ap/collections controller spec (#29102)
parent
978fdc71ca
commit
2d6ab44556
|
@ -17,34 +17,27 @@ RSpec.describe ActivityPub::CollectionsController do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'GET #show' do
|
describe 'GET #show' do
|
||||||
context 'when id is "featured"' do
|
subject(:response) { get :show, params: { id: id, account_username: account.username } }
|
||||||
context 'without signature' do
|
|
||||||
subject(:response) { get :show, params: { id: 'featured', account_username: account.username } }
|
|
||||||
|
|
||||||
let(:body) { body_as_json }
|
context 'when id is "featured"' do
|
||||||
|
let(:id) { 'featured' }
|
||||||
|
|
||||||
|
context 'without signature' do
|
||||||
let(:remote_account) { nil }
|
let(:remote_account) { nil }
|
||||||
|
|
||||||
it 'returns http success' do
|
it 'returns http success and correct media type' do
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns application/activity+json' do
|
|
||||||
expect(response.media_type).to eq 'application/activity+json'
|
expect(response.media_type).to eq 'application/activity+json'
|
||||||
end
|
end
|
||||||
|
|
||||||
it_behaves_like 'cacheable response'
|
it_behaves_like 'cacheable response'
|
||||||
|
|
||||||
it 'returns orderedItems with pinned statuses' do
|
it 'returns orderedItems with correct items' do
|
||||||
expect(body[:orderedItems]).to be_an Array
|
expect(body_as_json[:orderedItems])
|
||||||
expect(body[:orderedItems].size).to eq 3
|
.to be_an(Array)
|
||||||
end
|
.and have_attributes(size: 3)
|
||||||
|
.and include(ActivityPub::TagManager.instance.uri_for(private_pinned))
|
||||||
it 'includes URI of private pinned status' do
|
.and not_include(private_pinned.text)
|
||||||
expect(body[:orderedItems]).to include(ActivityPub::TagManager.instance.uri_for(private_pinned))
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'does not include contents of private pinned status' do
|
|
||||||
expect(response.body).to_not include(private_pinned.text)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when account is permanently suspended' do
|
context 'when account is permanently suspended' do
|
||||||
|
@ -73,33 +66,19 @@ RSpec.describe ActivityPub::CollectionsController do
|
||||||
let(:remote_account) { Fabricate(:account, domain: 'example.com') }
|
let(:remote_account) { Fabricate(:account, domain: 'example.com') }
|
||||||
|
|
||||||
context 'when getting a featured resource' do
|
context 'when getting a featured resource' do
|
||||||
before do
|
it 'returns http success and correct media type' do
|
||||||
get :show, params: { id: 'featured', account_username: account.username }
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns http success' do
|
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns application/activity+json' do
|
|
||||||
expect(response.media_type).to eq 'application/activity+json'
|
expect(response.media_type).to eq 'application/activity+json'
|
||||||
end
|
end
|
||||||
|
|
||||||
it_behaves_like 'cacheable response'
|
it_behaves_like 'cacheable response'
|
||||||
|
|
||||||
it 'returns orderedItems with pinned statuses' do
|
it 'returns orderedItems with expected items' do
|
||||||
json = body_as_json
|
expect(body_as_json[:orderedItems])
|
||||||
expect(json[:orderedItems]).to be_an Array
|
.to be_an(Array)
|
||||||
expect(json[:orderedItems].size).to eq 3
|
.and have_attributes(size: 3)
|
||||||
end
|
.and include(ActivityPub::TagManager.instance.uri_for(private_pinned))
|
||||||
|
.and not_include(private_pinned.text)
|
||||||
it 'includes URI of private pinned status' do
|
|
||||||
json = body_as_json
|
|
||||||
expect(json[:orderedItems]).to include(ActivityPub::TagManager.instance.uri_for(private_pinned))
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'does not include contents of private pinned status' do
|
|
||||||
expect(response.body).to_not include(private_pinned.text)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -111,50 +90,36 @@ RSpec.describe ActivityPub::CollectionsController do
|
||||||
context 'when signed request account is blocked' do
|
context 'when signed request account is blocked' do
|
||||||
before do
|
before do
|
||||||
account.block!(remote_account)
|
account.block!(remote_account)
|
||||||
get :show, params: { id: 'featured', account_username: account.username }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns http success' do
|
it 'returns http success and correct media type and cache headers' do
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns application/activity+json' do
|
|
||||||
expect(response.media_type).to eq 'application/activity+json'
|
expect(response.media_type).to eq 'application/activity+json'
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns private Cache-Control header' do
|
|
||||||
expect(response.headers['Cache-Control']).to include 'private'
|
expect(response.headers['Cache-Control']).to include 'private'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns empty orderedItems' do
|
it 'returns empty orderedItems' do
|
||||||
json = body_as_json
|
expect(body_as_json[:orderedItems])
|
||||||
expect(json[:orderedItems]).to be_an Array
|
.to be_an(Array)
|
||||||
expect(json[:orderedItems].size).to eq 0
|
.and have_attributes(size: 0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when signed request account is domain blocked' do
|
context 'when signed request account is domain blocked' do
|
||||||
before do
|
before do
|
||||||
account.block_domain!(remote_account.domain)
|
account.block_domain!(remote_account.domain)
|
||||||
get :show, params: { id: 'featured', account_username: account.username }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns http success' do
|
it 'returns http success and correct media type and cache headers' do
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns application/activity+json' do
|
|
||||||
expect(response.media_type).to eq 'application/activity+json'
|
expect(response.media_type).to eq 'application/activity+json'
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns private Cache-Control header' do
|
|
||||||
expect(response.headers['Cache-Control']).to include 'private'
|
expect(response.headers['Cache-Control']).to include 'private'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns empty orderedItems' do
|
it 'returns empty orderedItems' do
|
||||||
json = body_as_json
|
expect(body_as_json[:orderedItems])
|
||||||
expect(json[:orderedItems]).to be_an Array
|
.to be_an(Array)
|
||||||
expect(json[:orderedItems].size).to eq 0
|
.and have_attributes(size: 0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -162,8 +127,9 @@ RSpec.describe ActivityPub::CollectionsController do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when id is not "featured"' do
|
context 'when id is not "featured"' do
|
||||||
|
let(:id) { 'hoge' }
|
||||||
|
|
||||||
it 'returns http not found' do
|
it 'returns http not found' do
|
||||||
get :show, params: { id: 'hoge', account_username: account.username }
|
|
||||||
expect(response).to have_http_status(404)
|
expect(response).to have_http_status(404)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue