Merge pull request #622 from kmycode/upstream-20240229

Upstream 20240229
This commit is contained in:
KMY(雪あすか) 2024-02-29 12:54:54 +09:00 committed by GitHub
commit 5646b4e1e6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
60 changed files with 563 additions and 780 deletions

View file

@ -44,14 +44,13 @@ describe Admin::InvitesController do
end
describe 'POST #deactivate_all' do
before { Fabricate(:invite, expires_at: nil) }
it 'expires all invites, then redirects to admin_invites_path' do
invites = Fabricate.times(1, :invite, expires_at: nil)
post :deactivate_all
invites.each do |invite|
expect(invite.reload).to be_expired
end
expect { post :deactivate_all }
.to change { Invite.exists?(expires_at: nil) }
.from(true)
.to(false)
expect(response).to redirect_to admin_invites_path
end

View file

@ -14,17 +14,6 @@ describe CustomCssController do
expect(response).to have_http_status(200)
end
it 'returns public cache control header' do
expect(response.headers['Cache-Control']).to include('public')
end
it 'does not set cookies' do
expect(response.cookies).to be_empty
expect(response.headers['Set-Cookies']).to be_nil
end
it 'does not set sessions' do
expect(session).to be_empty
end
it_behaves_like 'cacheable response'
end
end

View file

@ -12,23 +12,18 @@ RSpec.describe InstanceActorsController do
get :show, params: { format: format }
end
it 'returns http success with correct media type, headers, and session values' do
it 'returns http success with correct media type and body' do
expect(response)
.to have_http_status(200)
.and have_attributes(
media_type: eq('application/activity+json'),
cookies: be_empty
media_type: eq('application/activity+json')
)
expect(response.headers)
.to include('Cache-Control' => include('public'))
.and not_include('Set-Cookies')
expect(session).to be_empty
expect(body_as_json)
.to include(:id, :type, :preferredUsername, :inbox, :publicKey, :inbox, :outbox, :url)
end
it_behaves_like 'cacheable response'
end
before do

View file

@ -14,17 +14,6 @@ describe ManifestsController do
expect(response).to have_http_status(200)
end
it 'returns public cache control header' do
expect(response.headers['Cache-Control']).to include('public')
end
it 'does not set cookies' do
expect(response.cookies).to be_empty
expect(response.headers['Set-Cookies']).to be_nil
end
it 'does not set sessions' do
expect(session).to be_empty
end
it_behaves_like 'cacheable response'
end
end

View file

@ -20,13 +20,7 @@ RSpec.describe TagsController do
expect(response).to have_http_status(200)
end
it 'returns Vary header' do
expect(response.headers['Vary']).to eq 'Accept, Accept-Language, Cookie'
end
it 'returns public Cache-Control header' do
expect(response.headers['Cache-Control']).to include 'public'
end
it_behaves_like 'cacheable response', expects_vary: 'Accept, Accept-Language, Cookie'
end
context 'when requested as JSON' do
@ -36,13 +30,7 @@ RSpec.describe TagsController do
expect(response).to have_http_status(200)
end
it 'returns Vary header' do
expect(response.headers['Vary']).to eq 'Accept, Accept-Language, Cookie'
end
it 'returns public Cache-Control header' do
expect(response.headers['Cache-Control']).to include 'public'
end
it_behaves_like 'cacheable response', expects_vary: 'Accept, Accept-Language, Cookie'
end
end

View file

@ -1,7 +1,7 @@
# frozen_string_literal: true
shared_examples 'cacheable response' do |expects_vary: false|
it 'sets correct cache and vary headers and does not set cookies or session' do
it 'sets correct cache and vary headers and does not set cookies or session', :aggregate_failures do
expect(response.cookies).to be_empty
expect(response.headers['Set-Cookies']).to be_nil

View file

@ -22,6 +22,12 @@ module ProfileStories
click_on I18n.t('auth.login')
end
def as_a_logged_in_admin
# This is a bit awkward, but this avoids code duplication.
as_a_logged_in_user
bob.update!(role: UserRole.find_by!(name: 'Admin'))
end
def with_alice_as_local_user
@alice_bio = '@alice and @bob are fictional characters commonly used as' \
'placeholder names in #cryptology, as well as #science and' \

View file

@ -109,6 +109,9 @@ RSpec.configure do |config|
# Also needs to be set per-example here because of the database cleaner.
Setting.registrations_mode = 'open'
# Load seeds so we have the default roles otherwise cleared by `DatabaseCleaner`
Rails.application.load_seed
example.run
end

View file

@ -0,0 +1,31 @@
# frozen_string_literal: true
require 'rails_helper'
describe 'report interface', :paperclip_processing do
include ProfileStories
let(:email) { 'admin@example.com' }
let(:password) { 'password' }
let(:confirmed_at) { Time.zone.now }
let(:finished_onboarding) { true }
let(:reported_account) { Fabricate(:account) }
let(:reported_status) { Fabricate(:status, account: reported_account) }
let(:media_attachment) { Fabricate(:media_attachment, account: reported_account, status: reported_status, file: attachment_fixture('attachment.jpg')) }
let!(:report) { Fabricate(:report, target_account: reported_account, status_ids: [media_attachment.status.id]) }
before do
as_a_logged_in_admin
visit admin_report_path(report)
end
it 'displays the report interface, including the javascript bits' do
# The report category selector React component is properly rendered
expect(page).to have_css('.report-reason-selector')
# The media React component is properly rendered
page.scroll_to(page.find('.batch-table__row'))
expect(page).to have_css('.spoiler-button__overlay__label')
end
end