Merge remote-tracking branch 'parent/main' into upstream-20241015

This commit is contained in:
KMY 2024-10-15 07:24:37 +09:00
commit ebdf1ecf49
24 changed files with 560 additions and 439 deletions

View file

@ -3,14 +3,13 @@
require 'rails_helper'
RSpec.describe DomainBlock do
describe 'validations' do
describe 'Validations' do
it { is_expected.to validate_presence_of(:domain) }
it 'is invalid if the same normalized domain already exists' do
_domain_block = Fabricate(:domain_block, domain: 'にゃん')
domain_block_with_normalized_value = Fabricate.build(:domain_block, domain: 'xn--r9j5b5b')
domain_block_with_normalized_value.valid?
expect(domain_block_with_normalized_value).to model_have_error_on_field(:domain)
context 'when a normalized domain exists' do
before { Fabricate(:domain_block, domain: 'にゃん') }
it { is_expected.to_not allow_value('xn--r9j5b5b').for(:domain) }
end
end
@ -105,4 +104,26 @@ RSpec.describe DomainBlock do
end
end
end
describe '#policies' do
subject { domain_block.policies }
context 'when severity is suspend' do
let(:domain_block) { Fabricate.build :domain_block, severity: :suspend }
it { is_expected.to eq(%i(suspend)) }
end
context 'when severity is noop' do
let(:domain_block) { Fabricate.build :domain_block, severity: :noop, reject_media: true }
it { is_expected.to eq(%i(reject_media)) }
end
context 'when severity is silence' do
let(:domain_block) { Fabricate.build :domain_block, severity: :silence, reject_reports: true }
it { is_expected.to eq(%i(silence reject_reports)) }
end
end
end

View file

@ -7,19 +7,25 @@ RSpec.describe NotificationPolicy do
subject { Fabricate(:notification_policy) }
let(:sender) { Fabricate(:account) }
let(:suspended_sender) { Fabricate(:account) }
before do
Fabricate.times(2, :notification, account: subject.account, activity: Fabricate(:status, account: sender), filtered: true, type: :mention)
Fabricate(:notification_request, account: subject.account, from_account: sender)
Fabricate(:notification, account: subject.account, activity: Fabricate(:status, account: suspended_sender), filtered: true, type: :mention)
Fabricate(:notification_request, account: subject.account, from_account: suspended_sender)
suspended_sender.suspend!
subject.summarize!
end
it 'sets pending_requests_count' do
expect(subject.pending_requests_count).to eq 1
end
it 'sets pending_notifications_count' do
expect(subject.pending_notifications_count).to eq 2
it 'sets pending_requests_count and pending_notifications_count' do
expect(subject).to have_attributes(
pending_requests_count: 1,
pending_notifications_count: 2
)
end
end
end

View file

@ -713,11 +713,53 @@ RSpec.describe Status do
end
end
describe 'validation' do
it 'disallow empty uri for remote status' do
alice.update(domain: 'example.com')
status = Fabricate.build(:status, uri: '', account: alice)
expect(status).to model_have_error_on_field(:uri)
describe 'Validations' do
context 'with a remote account' do
subject { Fabricate.build :status, account: remote_account }
let(:remote_account) { Fabricate :account, domain: 'example.com' }
it { is_expected.to_not allow_value('').for(:uri) }
end
end
describe 'Callbacks' do
describe 'Stripping content when required' do
context 'with a remote account' do
subject { Fabricate.build :status, local: false, account:, text: ' text ', spoiler_text: ' spoiler ' }
let(:account) { Fabricate.build :account, domain: 'host.example' }
it 'preserves content' do
expect { subject.valid? }
.to not_change(subject, :text)
.and not_change(subject, :spoiler_text)
end
end
context 'with a local account' do
let(:account) { Fabricate.build :account, domain: nil }
context 'with populated fields' do
subject { Fabricate.build :status, local: true, account:, text: ' text ', spoiler_text: ' spoiler ' }
it 'strips content' do
expect { subject.valid? }
.to change(subject, :text).to('text')
.and change(subject, :spoiler_text).to('spoiler')
end
end
context 'with empty fields' do
subject { Fabricate.build :status, local: true, account:, text: nil, spoiler_text: nil }
it 'preserves content' do
expect { subject.valid? }
.to not_change(subject, :text)
.and not_change(subject, :spoiler_text)
end
end
end
end
end