Merge commit '5f87ae101c5e0e940e148d493eaac1ce31fe24c1' into glitch-soc/merge-upstream

This commit is contained in:
Claire
2025-04-04 20:00:24 +02:00
60 changed files with 667 additions and 512 deletions

View File

@@ -1,52 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Settings::PicturesController do
render_views
let!(:user) { Fabricate(:user) }
before do
sign_in user, scope: :user
end
describe 'DELETE #destroy' do
context 'with invalid picture id' do
it 'returns http bad request' do
delete :destroy, params: { id: 'invalid' }
expect(response).to have_http_status(400)
end
end
context 'with valid picture id' do
context 'when account updates correctly' do
let(:service) { instance_double(UpdateAccountService, call: true) }
before do
allow(UpdateAccountService).to receive(:new).and_return(service)
end
it 'updates the account' do
delete :destroy, params: { id: 'avatar' }
expect(response).to redirect_to(settings_profile_path)
expect(response).to have_http_status(303)
expect(service).to have_received(:call).with(user.account, { 'avatar' => nil, 'avatar_remote_url' => '' })
end
end
context 'when account cannot update' do
let(:service) { instance_double(UpdateAccountService, call: false) }
before do
allow(UpdateAccountService).to receive(:new).and_return(service)
end
it 'redirects to profile' do
delete :destroy, params: { id: 'avatar' }
expect(response).to redirect_to(settings_profile_path)
end
end
end
end
end

View File

@@ -28,6 +28,19 @@ RSpec.describe Admin::Trends::StatusesHelper do
end
end
context 'with a remote status that has excessive attributes' do
let(:attr_limit) { Nokogiri::Gumbo::DEFAULT_MAX_ATTRIBUTES * 2 }
let(:html) { "<html><body #{(1..attr_limit).map { |x| "attr-#{x}" }.join(' ')}><p>text</p></body></html>" }
let(:status) { Fabricate.build(:status, uri: 'https://host.example', text: html) }
it 'renders a correct preview text' do
result = helper.one_line_preview(status)
expect(result).to eq ''
end
end
context 'with a status that has empty text' do
let(:status) { Fabricate.build(:status, text: '') }

View File

@@ -187,6 +187,23 @@ RSpec.describe ActivityPub::TagManager do
end
end
describe '#uris_to_local_accounts' do
it 'returns the expected local accounts' do
account = Fabricate(:account)
expect(subject.uris_to_local_accounts([subject.uri_for(account), instance_actor_url])).to contain_exactly(account, Account.representative)
end
it 'does not return remote accounts' do
account = Fabricate(:account, uri: 'https://example.com/123', domain: 'example.com')
expect(subject.uris_to_local_accounts([subject.uri_for(account)])).to be_empty
end
it 'does not return an account for a local post' do
status = Fabricate(:status)
expect(subject.uris_to_local_accounts([subject.uri_for(status)])).to be_empty
end
end
describe '#uri_to_resource' do
it 'returns the local account' do
account = Fabricate(:account)

View File

@@ -38,7 +38,7 @@ RSpec.describe Fasp::Request do
it 'raises an error' do
expect do
subject.send(method, '/test_path')
end.to raise_error(SignatureVerification::SignatureVerificationError)
end.to raise_error(Mastodon::SignatureVerificationError)
end
end
end

View File

@@ -0,0 +1,55 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'Settings Pictures' do
let!(:user) { Fabricate(:user) }
before { sign_in user }
describe 'DELETE /settings/profile/pictures/:id' do
context 'with invalid picture id' do
it 'returns http bad request' do
delete settings_profile_picture_path(id: 'invalid')
expect(response)
.to have_http_status(400)
end
end
context 'with valid picture id' do
before { stub_service }
context 'when account updates correctly' do
let(:service) { instance_double(UpdateAccountService, call: true) }
it 'updates the account' do
delete settings_profile_picture_path(id: 'avatar')
expect(response)
.to redirect_to(settings_profile_path)
.and have_http_status(303)
expect(service)
.to have_received(:call).with(user.account, { 'avatar' => nil, 'avatar_remote_url' => '' })
end
end
context 'when account cannot update' do
let(:service) { instance_double(UpdateAccountService, call: false) }
it 'redirects to profile' do
delete settings_profile_picture_path(id: 'avatar')
expect(response)
.to redirect_to(settings_profile_path)
end
end
def stub_service
allow(UpdateAccountService)
.to receive(:new)
.and_return(service)
end
end
end
end