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

This commit is contained in:
KMY 2023-12-06 12:49:55 +09:00
commit 0199608b87
61 changed files with 781 additions and 162 deletions

View file

@ -161,12 +161,13 @@ RSpec.describe Admin::AccountsController do
it 'logs action' do
expect(subject).to have_http_status 302
log_item = Admin::ActionLog.last
expect(log_item).to_not be_nil
expect(log_item.action).to eq :approve
expect(log_item.account_id).to eq current_user.account_id
expect(log_item.target_id).to eq account.user.id
expect(latest_admin_action_log)
.to be_present
.and have_attributes(
action: eq(:approve),
account_id: eq(current_user.account_id),
target_id: eq(account.user.id)
)
end
end
@ -201,12 +202,13 @@ RSpec.describe Admin::AccountsController do
it 'logs action' do
expect(subject).to have_http_status 302
log_item = Admin::ActionLog.last
expect(log_item).to_not be_nil
expect(log_item.action).to eq :reject
expect(log_item.account_id).to eq current_user.account_id
expect(log_item.target_id).to eq account.user.id
expect(latest_admin_action_log)
.to be_present
.and have_attributes(
action: eq(:reject),
account_id: eq(current_user.account_id),
target_id: eq(account.user.id)
)
end
end
@ -427,4 +429,10 @@ RSpec.describe Admin::AccountsController do
end
end
end
private
def latest_admin_action_log
Admin::ActionLog.last
end
end

View file

@ -9,11 +9,9 @@ describe Admin::ActionLogsController do
let!(:account) { Fabricate(:account) }
before do
_orphaned_logs = %w(
Account User UserRole Report DomainBlock DomainAllow
EmailDomainBlock UnavailableDomain Status AccountWarning
Announcement IpBlock Instance CustomEmoji CanonicalEmailBlock Appeal
).map { |type| Admin::ActionLog.new(account: account, action: 'destroy', target_type: type, target_id: 1312).save! }
orphaned_log_types.map do |type|
Fabricate(:action_log, account: account, action: 'destroy', target_type: type, target_id: 1312)
end
end
describe 'GET #index' do
@ -24,4 +22,27 @@ describe Admin::ActionLogsController do
expect(response).to have_http_status(200)
end
end
private
def orphaned_log_types
%w(
Account
AccountWarning
Announcement
Appeal
CanonicalEmailBlock
CustomEmoji
DomainAllow
DomainBlock
EmailDomainBlock
Instance
IpBlock
Report
Status
UnavailableDomain
User
UserRole
)
end
end

View file

@ -192,16 +192,11 @@ RSpec.describe Admin::DomainBlocksController do
let(:original_severity) { 'suspend' }
let(:new_severity) { 'silence' }
it 'changes the block severity' do
expect { subject }.to change { domain_block.reload.severity }.from('suspend').to('silence')
end
it 'undoes individual suspensions' do
expect { subject }.to change { remote_account.reload.suspended? }.from(true).to(false)
end
it 'performs individual silences' do
expect { subject }.to change { remote_account.reload.silenced? }.from(false).to(true)
it 'changes the block severity, suspensions, and silences' do
expect { subject }
.to change_severity('suspend', 'silence')
.and change_suspended(true, false)
.and change_silenced(false, true)
end
end
@ -209,17 +204,26 @@ RSpec.describe Admin::DomainBlocksController do
let(:original_severity) { 'silence' }
let(:new_severity) { 'suspend' }
it 'changes the block severity' do
expect { subject }.to change { domain_block.reload.severity }.from('silence').to('suspend')
it 'changes the block severity, silences, and suspensions' do
expect { subject }
.to change_severity('silence', 'suspend')
.and change_silenced(true, false)
.and change_suspended(false, true)
end
end
it 'undoes individual silences' do
expect { subject }.to change { remote_account.reload.silenced? }.from(true).to(false)
end
private
it 'performs individual suspends' do
expect { subject }.to change { remote_account.reload.suspended? }.from(false).to(true)
end
def change_severity(from, to)
change { domain_block.reload.severity }.from(from).to(to)
end
def change_silenced(from, to)
change { remote_account.reload.silenced? }.from(from).to(to)
end
def change_suspended(from, to)
change { remote_account.reload.suspended? }.from(from).to(to)
end
end

View file

@ -24,7 +24,7 @@ RSpec.describe Admin::ExportDomainAllowsController do
get :export, params: { format: :csv }
expect(response).to have_http_status(200)
expect(response.body).to eq(File.read(File.join(file_fixture_path, 'domain_allows.csv')))
expect(response.body).to eq(domain_allows_csv_file)
end
end
@ -40,7 +40,7 @@ RSpec.describe Admin::ExportDomainAllowsController do
# Domains should now be added
get :export, params: { format: :csv }
expect(response).to have_http_status(200)
expect(response.body).to eq(File.read(File.join(file_fixture_path, 'domain_allows.csv')))
expect(response.body).to eq(domain_allows_csv_file)
end
it 'displays error on no file selected' do
@ -49,4 +49,10 @@ RSpec.describe Admin::ExportDomainAllowsController do
expect(flash[:error]).to eq(I18n.t('admin.export_domain_allows.no_file'))
end
end
private
def domain_allows_csv_file
File.read(File.join(file_fixture_path, 'domain_allows.csv'))
end
end

View file

@ -26,7 +26,13 @@ RSpec.describe Admin::ExportDomainBlocksController do
get :export, params: { format: :csv }
expect(response).to have_http_status(200)
expect(response.body).to eq(File.read(File.join(file_fixture_path, 'domain_blocks.csv')))
expect(response.body).to eq(domain_blocks_csv_file)
end
private
def domain_blocks_csv_file
File.read(File.join(file_fixture_path, 'domain_blocks.csv'))
end
end

View file

@ -4,5 +4,22 @@ require 'rails_helper'
require 'mastodon/cli/domains'
describe Mastodon::CLI::Domains do
let(:cli) { described_class.new }
it_behaves_like 'CLI Command'
describe '#purge' do
context 'with accounts from the domain' do
let(:options) { {} }
let(:domain) { 'host.example' }
let!(:account) { Fabricate(:account, domain: domain) }
it 'removes the account' do
expect { cli.invoke(:purge, [domain], options) }.to output(
a_string_including('Removed 1 accounts')
).to_stdout
expect { account.reload }.to raise_error(ActiveRecord::RecordNotFound)
end
end
end
end

View file

@ -4,5 +4,98 @@ require 'rails_helper'
require 'mastodon/cli/email_domain_blocks'
describe Mastodon::CLI::EmailDomainBlocks do
let(:cli) { described_class.new }
it_behaves_like 'CLI Command'
describe '#list' do
context 'with email domain block records' do
let!(:parent_block) { Fabricate(:email_domain_block) }
let!(:child_block) { Fabricate(:email_domain_block, parent: parent_block) }
let(:options) { {} }
it 'lists the blocks' do
expect { cli.invoke(:list, [], options) }.to output(
a_string_including(parent_block.domain)
.and(a_string_including(child_block.domain))
).to_stdout
end
end
end
describe '#add' do
context 'without any options' do
let(:options) { {} }
it 'warns about usage and exits' do
expect { cli.invoke(:add, [], options) }.to output(
a_string_including('No domain(s) given')
).to_stdout.and raise_error(SystemExit)
end
end
context 'when blocks exist' do
let(:options) { {} }
let(:domain) { 'host.example' }
before { Fabricate(:email_domain_block, domain: domain) }
it 'does not add a new block' do
expect { cli.invoke(:add, [domain], options) }.to output(
a_string_including('is already blocked')
).to_stdout
.and(not_change(EmailDomainBlock, :count))
end
end
context 'when no blocks exist' do
let(:options) { {} }
let(:domain) { 'host.example' }
it 'adds a new block' do
expect { cli.invoke(:add, [domain], options) }.to output(
a_string_including('Added 1')
).to_stdout
.and(change(EmailDomainBlock, :count).by(1))
end
end
end
describe '#remove' do
context 'without any options' do
let(:options) { {} }
it 'warns about usage and exits' do
expect { cli.invoke(:remove, [], options) }.to output(
a_string_including('No domain(s) given')
).to_stdout.and raise_error(SystemExit)
end
end
context 'when blocks exist' do
let(:options) { {} }
let(:domain) { 'host.example' }
before { Fabricate(:email_domain_block, domain: domain) }
it 'removes the block' do
expect { cli.invoke(:remove, [domain], options) }.to output(
a_string_including('Removed 1')
).to_stdout
.and(change(EmailDomainBlock, :count).by(-1))
end
end
context 'when no blocks exist' do
let(:options) { {} }
let(:domain) { 'host.example' }
it 'does not remove a block' do
expect { cli.invoke(:remove, [domain], options) }.to output(
a_string_including('is not yet blocked')
).to_stdout
.and(not_change(EmailDomainBlock, :count))
end
end
end
end

View file

@ -4,5 +4,24 @@ require 'rails_helper'
require 'mastodon/cli/upgrade'
describe Mastodon::CLI::Upgrade do
let(:cli) { described_class.new }
it_behaves_like 'CLI Command'
describe '#storage_schema' do
context 'with records that dont need upgrading' do
let(:options) { {} }
before do
Fabricate(:account)
Fabricate(:media_attachment)
end
it 'does not upgrade storage for the attachments' do
expect { cli.invoke(:storage_schema, [], options) }.to output(
a_string_including('Upgraded storage schema of 0 records')
).to_stdout
end
end
end
end

View file

@ -37,12 +37,10 @@ RSpec.describe Form::AccountBatch do
let(:select_all_matching) { '0' }
let(:account_ids) { [target_account.id, target_account2.id] }
it 'suspends the expected users' do
expect { subject }.to change { [target_account.reload.suspended?, target_account2.reload.suspended?] }.from([false, false]).to([true, true])
end
it 'closes open reports targeting the suspended users' do
expect { subject }.to change { Report.unresolved.where(target_account: [target_account, target_account2]).count }.from(2).to(0)
it 'suspends the expected users and closes open reports' do
expect { subject }
.to change_account_suspensions
.and change_open_reports_for_accounts
end
end
@ -50,13 +48,33 @@ RSpec.describe Form::AccountBatch do
let(:select_all_matching) { '1' }
let(:query) { Account.where(id: [target_account.id, target_account2.id]) }
it 'suspends the expected users' do
expect { subject }.to change { [target_account.reload.suspended?, target_account2.reload.suspended?] }.from([false, false]).to([true, true])
it 'suspends the expected users and closes open reports' do
expect { subject }
.to change_account_suspensions
.and change_open_reports_for_accounts
end
end
it 'closes open reports targeting the suspended users' do
expect { subject }.to change { Report.unresolved.where(target_account: [target_account, target_account2]).count }.from(2).to(0)
end
private
def change_account_suspensions
change { relevant_account_suspension_statuses }
.from([false, false])
.to([true, true])
end
def change_open_reports_for_accounts
change(relevant_account_unresolved_reports, :count)
.from(2)
.to(0)
end
def relevant_account_unresolved_reports
Report.unresolved.where(target_account: [target_account, target_account2])
end
def relevant_account_suspension_statuses
[target_account.reload, target_account2.reload].map(&:suspended?)
end
end
end

View file

@ -21,12 +21,19 @@ RSpec.describe 'Account actions' do
it 'logs action' do
subject
log_item = Admin::ActionLog.last
expect(latest_admin_action_log)
.to be_present
.and have_attributes(
action: eq(action_type),
account_id: eq(user.account_id),
target_id: eq(target_type == :user ? target_account.user.id : target_account.id)
)
end
expect(log_item).to be_present
expect(log_item.action).to eq(action_type)
expect(log_item.account_id).to eq(user.account_id)
expect(log_item.target_id).to eq(target_type == :user ? target_account.user.id : target_account.id)
private
def latest_admin_action_log
Admin::ActionLog.last
end
end

View file

@ -151,12 +151,13 @@ RSpec.describe 'Accounts' do
it 'logs action', :aggregate_failures do
subject
log_item = Admin::ActionLog.last
expect(log_item).to be_present
expect(log_item.action).to eq :approve
expect(log_item.account_id).to eq user.account_id
expect(log_item.target_id).to eq account.user.id
expect(latest_admin_action_log)
.to be_present
.and have_attributes(
action: eq(:approve),
account_id: eq(user.account_id),
target_id: eq(account.user.id)
)
end
end
@ -202,12 +203,13 @@ RSpec.describe 'Accounts' do
it 'logs action', :aggregate_failures do
subject
log_item = Admin::ActionLog.last
expect(log_item).to be_present
expect(log_item.action).to eq :reject
expect(log_item.account_id).to eq user.account_id
expect(log_item.target_id).to eq account.user.id
expect(latest_admin_action_log)
.to be_present
.and have_attributes(
action: eq(:reject),
account_id: eq(user.account_id),
target_id: eq(account.user.id)
)
end
end
@ -398,4 +400,10 @@ RSpec.describe 'Accounts' do
end
end
end
private
def latest_admin_action_log
Admin::ActionLog.last
end
end

View file

@ -140,8 +140,11 @@ RSpec.describe 'Lists' do
it_behaves_like 'forbidden for wrong scope', 'read read:lists'
it 'returns the updated list', :aggregate_failures do
subject
it 'returns the updated list and updates values', :aggregate_failures do
expect { subject }
.to change_list_title
.and change_list_replies_policy
.and change_list_exclusive
expect(response).to have_http_status(200)
list.reload
@ -156,16 +159,16 @@ RSpec.describe 'Lists' do
})
end
it 'updates the list title' do
expect { subject }.to change { list.reload.title }.from('my list').to('list')
def change_list_title
change { list.reload.title }.from('my list').to('list')
end
it 'updates the list replies_policy' do
expect { subject }.to change { list.reload.replies_policy }.from('list').to('followed')
def change_list_replies_policy
change { list.reload.replies_policy }.from('list').to('followed')
end
it 'updates the list exclusive' do
expect { subject }.to change { list.reload.exclusive }.from(false).to(true)
def change_list_exclusive
change { list.reload.exclusive }.from(false).to(true)
end
context 'when the list does not exist' do