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

This commit is contained in:
KMY 2024-02-22 07:48:56 +09:00
commit a23f77a5b8
90 changed files with 2926 additions and 2298 deletions

View file

@ -2,7 +2,7 @@
require 'rails_helper'
describe TagFeed, type: :service do
describe TagFeed do
describe '#get' do
let(:account) { Fabricate(:account) }
let(:tag_cats) { Fabricate(:tag, name: 'cats') }

View file

@ -0,0 +1,24 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe AfterUnallowDomainService do
describe '#call' do
context 'with accounts for a domain' do
let!(:account) { Fabricate(:account, domain: 'host.example') }
let!(:test_account) { Fabricate(:account, domain: 'test.example') }
let(:service_double) { instance_double(DeleteAccountService, call: true) }
before { allow(DeleteAccountService).to receive(:new).and_return(service_double) }
it 'calls the delete service for accounts from the relevant domain' do
subject.call 'test.example'
expect(service_double)
.to_not have_received(:call).with(account, reserve_username: false)
expect(service_double)
.to have_received(:call).with(test_account, reserve_username: false)
end
end
end
end

View file

@ -0,0 +1,40 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe AppealService do
describe '#call' do
let!(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
context 'with an existing strike' do
let(:strike) { Fabricate(:account_warning) }
let(:text) { 'Appeal text' }
it 'creates an appeal and notifies staff' do
emails = capture_emails { subject.call(strike, text) }
expect(Appeal.last)
.to have_attributes(
strike: strike,
text: text,
account: strike.target_account
)
expect(emails.size)
.to eq(1)
expect(emails.first)
.to have_attributes(
to: contain_exactly(admin.email),
subject: eq(
I18n.t(
'admin_mailer.new_appeal.subject',
username: strike.target_account.acct,
instance: Rails.configuration.x.local_domain
)
)
)
end
end
end
end

View file

@ -0,0 +1,31 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe CreateFeaturedTagService do
describe '#call' do
let(:tag) { 'test' }
context 'with a local account' do
let(:account) { Fabricate(:account, domain: nil) }
it 'creates a new featured tag and distributes' do
expect { subject.call(account, tag) }
.to change(FeaturedTag, :count).by(1)
expect(ActivityPub::AccountRawDistributionWorker)
.to have_enqueued_sidekiq_job(anything, account.id)
end
end
context 'with a remote account' do
let(:account) { Fabricate(:account, domain: 'host.example') }
it 'creates a new featured tag and does not distributes' do
expect { subject.call(account, tag) }
.to change(FeaturedTag, :count).by(1)
expect(ActivityPub::AccountRawDistributionWorker)
.to_not have_enqueued_sidekiq_job
end
end
end
end

View file

@ -0,0 +1,16 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe ProcessHashtagsService do
describe '#call' do
let(:status) { Fabricate(:status, visibility: :public, text: 'With tags #one #two') }
it 'applies the tags from the status text' do
expect { subject.call(status) }
.to change(Tag, :count).by(2)
expect(status.reload.tags.map(&:name))
.to contain_exactly('one', 'two')
end
end
end

View file

@ -0,0 +1,60 @@
# frozen_string_literal: true
require 'rails_helper'
describe Scheduler::AutoCloseRegistrationsScheduler do
subject { described_class.new }
describe '#perform' do
let(:moderator_activity_date) { Time.now.utc }
before do
Fabricate(:user, role: UserRole.find_by(name: 'Owner'), current_sign_in_at: 10.years.ago)
Fabricate(:user, role: UserRole.find_by(name: 'Moderator'), current_sign_in_at: moderator_activity_date)
end
context 'when registrations are open' do
before do
Setting.registrations_mode = 'open'
end
context 'when a moderator has logged in recently' do
let(:moderator_activity_date) { Time.now.utc }
it 'does not change registrations mode' do
expect { subject.perform }.to_not change(Setting, :registrations_mode)
end
end
context 'when a moderator has not recently signed in' do
let(:moderator_activity_date) { 1.year.ago }
it 'changes registrations mode from open to approved' do
expect { subject.perform }.to change(Setting, :registrations_mode).from('open').to('approved')
end
end
end
context 'when registrations are closed' do
before do
Setting.registrations_mode = 'none'
end
context 'when a moderator has logged in recently' do
let(:moderator_activity_date) { Time.now.utc }
it 'does not change registrations mode' do
expect { subject.perform }.to_not change(Setting, :registrations_mode)
end
end
context 'when a moderator has not recently signed in' do
let(:moderator_activity_date) { 1.year.ago }
it 'does not change registrations mode' do
expect { subject.perform }.to_not change(Setting, :registrations_mode)
end
end
end
end
end