Merge commit '9e04007020' into upstream-20240725

This commit is contained in:
KMY 2024-07-25 13:06:26 +09:00
commit a99f174d98
322 changed files with 8093 additions and 1586 deletions

View file

@ -25,14 +25,12 @@ RSpec.describe ActivityPub::CollectionsController do
context 'without signature' do
let(:remote_account) { nil }
it 'returns http success and correct media type' do
expect(response).to have_http_status(200)
expect(response.media_type).to eq 'application/activity+json'
end
it_behaves_like 'cacheable response'
it 'returns orderedItems with correct items' do
it 'returns http success and correct media type and correct items' do
expect(response).to have_http_status(200)
expect(response.media_type).to eq 'application/activity+json'
expect(body_as_json[:orderedItems])
.to be_an(Array)
.and have_attributes(size: 3)
@ -66,14 +64,12 @@ RSpec.describe ActivityPub::CollectionsController do
let(:remote_account) { Fabricate(:account, domain: 'example.com') }
context 'when getting a featured resource' do
it 'returns http success and correct media type' do
expect(response).to have_http_status(200)
expect(response.media_type).to eq 'application/activity+json'
end
it_behaves_like 'cacheable response'
it 'returns orderedItems with expected items' do
it 'returns http success and correct media type and expected items' do
expect(response).to have_http_status(200)
expect(response.media_type).to eq 'application/activity+json'
expect(body_as_json[:orderedItems])
.to be_an(Array)
.and have_attributes(size: 3)
@ -92,16 +88,14 @@ RSpec.describe ActivityPub::CollectionsController do
account.block!(remote_account)
end
it 'returns http success and correct media type and cache headers' do
it 'returns http success and correct media type and cache headers and empty items' do
expect(response).to have_http_status(200)
expect(response.media_type).to eq 'application/activity+json'
expect(response.headers['Cache-Control']).to include 'private'
end
it 'returns empty orderedItems' do
expect(body_as_json[:orderedItems])
.to be_an(Array)
.and have_attributes(size: 0)
.and be_empty
end
end
@ -110,16 +104,14 @@ RSpec.describe ActivityPub::CollectionsController do
account.block_domain!(remote_account.domain)
end
it 'returns http success and correct media type and cache headers' do
it 'returns http success and correct media type and cache headers and empty items' do
expect(response).to have_http_status(200)
expect(response.media_type).to eq 'application/activity+json'
expect(response.headers['Cache-Control']).to include 'private'
end
it 'returns empty orderedItems' do
expect(body_as_json[:orderedItems])
.to be_an(Array)
.and have_attributes(size: 0)
.and be_empty
end
end
end

View file

@ -37,25 +37,18 @@ RSpec.describe ActivityPub::FollowersSynchronizationsController do
let(:body) { body_as_json }
let(:remote_account) { Fabricate(:account, domain: 'example.com', uri: 'https://example.com/instance') }
it 'returns http success' do
it 'returns http success and cache control and activity json types and correct items' do
expect(response).to have_http_status(200)
end
it 'returns application/activity+json' do
expect(response.media_type).to eq 'application/activity+json'
end
it 'returns orderedItems with followers from example.com' do
expect(body[:orderedItems]).to be_an Array
expect(body[:orderedItems]).to contain_exactly(
follower_example_com_instance_actor.uri,
follower_example_com_user_a.uri,
follower_example_com_user_b.uri
)
end
it 'returns private Cache-Control header' do
expect(response.headers['Cache-Control']).to eq 'max-age=0, private'
expect(response.media_type).to eq 'application/activity+json'
expect(body[:orderedItems])
.to be_an(Array)
.and contain_exactly(
follower_example_com_instance_actor.uri,
follower_example_com_user_a.uri,
follower_example_com_user_b.uri
)
end
context 'when account is permanently suspended' do

View file

@ -25,22 +25,13 @@ RSpec.describe ActivityPub::OutboxesController do
context 'with page not requested' do
let(:page) { nil }
it 'returns http success' do
expect(response).to have_http_status(200)
end
it 'returns application/activity+json' do
expect(response.media_type).to eq 'application/activity+json'
end
it 'returns totalItems' do
expect(body[:totalItems]).to eq 4
end
it_behaves_like 'cacheable response'
it 'does not have a Vary header' do
it 'returns http success and correct media type and headers and items count' do
expect(response).to have_http_status(200)
expect(response.media_type).to eq 'application/activity+json'
expect(response.headers['Vary']).to be_nil
expect(body[:totalItems]).to eq 4
end
context 'when account is permanently suspended' do
@ -68,26 +59,18 @@ RSpec.describe ActivityPub::OutboxesController do
context 'with page requested' do
let(:page) { 'true' }
it 'returns http success' do
it_behaves_like 'cacheable response'
it 'returns http success and correct media type and vary header and items' do
expect(response).to have_http_status(200)
end
it 'returns application/activity+json' do
expect(response.media_type).to eq 'application/activity+json'
end
expect(response.headers['Vary']).to include 'Signature'
it 'returns orderedItems with public or unlisted statuses' do
expect(body[:orderedItems]).to be_an Array
expect(body[:orderedItems].size).to eq 2
expect(body[:orderedItems].all? { |item| targets_public_collection?(item) }).to be true
end
it_behaves_like 'cacheable response'
it 'returns Vary header with Signature' do
expect(response.headers['Vary']).to include 'Signature'
end
context 'when account is permanently suspended' do
before do
account.suspend!
@ -120,23 +103,14 @@ RSpec.describe ActivityPub::OutboxesController do
get :show, params: { account_username: account.username, page: page }
end
it 'returns http success' do
it 'returns http success and correct media type and headers and items' do
expect(response).to have_http_status(200)
end
it 'returns application/activity+json' do
expect(response.media_type).to eq 'application/activity+json'
end
it 'returns orderedItems with public or unlisted statuses' do
json = body_as_json
expect(json[:orderedItems]).to be_an Array
expect(json[:orderedItems].size).to eq 2
expect(json[:orderedItems].all? { |item| targets_public_collection?(item) }).to be true
end
it 'returns private Cache-Control header' do
expect(response.headers['Cache-Control']).to eq 'max-age=60, private'
expect(body_as_json[:orderedItems]).to be_an Array
expect(body_as_json[:orderedItems].size).to eq 2
expect(body_as_json[:orderedItems].all? { |item| targets_public_collection?(item) }).to be true
end
end
@ -146,23 +120,14 @@ RSpec.describe ActivityPub::OutboxesController do
get :show, params: { account_username: account.username, page: page }
end
it 'returns http success' do
it 'returns http success and correct media type and headers and items' do
expect(response).to have_http_status(200)
end
it 'returns application/activity+json' do
expect(response.media_type).to eq 'application/activity+json'
end
it 'returns orderedItems with private statuses' do
json = body_as_json
expect(json[:orderedItems]).to be_an Array
expect(json[:orderedItems].size).to eq 3
expect(json[:orderedItems].all? { |item| targets_public_collection?(item) || targets_followers_collection?(item, account) }).to be true
end
it 'returns private Cache-Control header' do
expect(response.headers['Cache-Control']).to eq 'max-age=60, private'
expect(body_as_json[:orderedItems]).to be_an Array
expect(body_as_json[:orderedItems].size).to eq 3
expect(body_as_json[:orderedItems].all? { |item| targets_public_collection?(item) || targets_followers_collection?(item, account) }).to be true
end
end
@ -172,22 +137,14 @@ RSpec.describe ActivityPub::OutboxesController do
get :show, params: { account_username: account.username, page: page }
end
it 'returns http success' do
it 'returns http success and correct media type and headers and items' do
expect(response).to have_http_status(200)
end
it 'returns application/activity+json' do
expect(response.media_type).to eq 'application/activity+json'
end
it 'returns empty orderedItems' do
json = body_as_json
expect(json[:orderedItems]).to be_an Array
expect(json[:orderedItems].size).to eq 0
end
it 'returns private Cache-Control header' do
expect(response.headers['Cache-Control']).to eq 'max-age=60, private'
expect(body_as_json[:orderedItems])
.to be_an(Array)
.and be_empty
end
end
@ -197,22 +154,14 @@ RSpec.describe ActivityPub::OutboxesController do
get :show, params: { account_username: account.username, page: page }
end
it 'returns http success' do
it 'returns http success and correct media type and headers and items' do
expect(response).to have_http_status(200)
end
it 'returns application/activity+json' do
expect(response.media_type).to eq 'application/activity+json'
end
it 'returns empty orderedItems' do
json = body_as_json
expect(json[:orderedItems]).to be_an Array
expect(json[:orderedItems].size).to eq 0
end
it 'returns private Cache-Control header' do
expect(response.headers['Cache-Control']).to eq 'max-age=60, private'
expect(body_as_json[:orderedItems])
.to be_an(Array)
.and be_empty
end
end
end

View file

@ -66,19 +66,15 @@ RSpec.describe ActivityPub::RepliesController do
context 'when status is public' do
let(:parent_visibility) { :public }
let(:json) { body_as_json }
let(:page_json) { json[:first] }
it 'returns http success' do
expect(response).to have_http_status(200)
end
it 'returns application/activity+json' do
expect(response.media_type).to eq 'application/activity+json'
end
let(:page_json) { body_as_json[:first] }
it_behaves_like 'cacheable response'
it 'returns http success and correct media type' do
expect(response).to have_http_status(200)
expect(response.media_type).to eq 'application/activity+json'
end
context 'without only_other_accounts' do
it "returns items with thread author's replies" do
expect(page_json).to be_a Hash

View file

@ -37,10 +37,32 @@ RSpec.describe Admin::InstancesController do
end
describe 'GET #show' do
before do
allow(Admin::ActionLogFilter).to receive(:new).and_call_original
end
it 'shows an instance page' do
get :show, params: { id: account_popular_main.domain }
expect(response).to have_http_status(200)
instance = assigns(:instance)
expect(instance).to_not be_new_record
expect(Admin::ActionLogFilter).to have_received(:new).with(target_domain: account_popular_main.domain)
action_logs = assigns(:action_logs).to_a
expect(action_logs.size).to eq 0
end
context 'with an unknown domain' do
it 'returns http success' do
get :show, params: { id: 'unknown.example' }
expect(response).to have_http_status(200)
instance = assigns(:instance)
expect(instance).to be_new_record
end
end
end

View file

@ -64,7 +64,7 @@ describe Admin::ReportsController do
describe 'POST #reopen' do
it 'reopens the report' do
report = Fabricate(:report)
report = Fabricate(:report, action_taken_at: 3.days.ago)
put :reopen, params: { id: report }
expect(response).to redirect_to(admin_report_path(report))
@ -89,7 +89,7 @@ describe Admin::ReportsController do
describe 'POST #unassign' do
it 'reopens the report' do
report = Fabricate(:report)
report = Fabricate(:report, assigned_account_id: Account.last.id)
put :unassign, params: { id: report }
expect(response).to redirect_to(admin_report_path(report))