Merge remote-tracking branch 'parent/main' into kb_development

This commit is contained in:
KMY 2023-12-09 10:04:10 +09:00
commit f20cb3fd59
60 changed files with 1036 additions and 695 deletions

View file

@ -378,12 +378,10 @@ RSpec.describe ActivityPub::ProcessAccountService, type: :service do
end
end
it 'creates at least some accounts' do
expect { subject }.to change { Account.remote.count }.by_at_least(2)
end
it 'creates no more account than the limit allows' do
expect { subject }.to change { Account.remote.count }.by_at_most(5)
it 'creates accounts without exceeding rate limit' do
expect { subject }
.to create_some_remote_accounts
.and create_fewer_than_rate_limit_accounts
end
end
@ -445,12 +443,20 @@ RSpec.describe ActivityPub::ProcessAccountService, type: :service do
end
end
it 'creates at least some accounts' do
expect { subject.call('user1', 'foo.test', payload) }.to change { Account.remote.count }.by_at_least(2)
end
it 'creates no more account than the limit allows' do
expect { subject.call('user1', 'foo.test', payload) }.to change { Account.remote.count }.by_at_most(5)
it 'creates accounts without exceeding rate limit' do
expect { subject.call('user1', 'foo.test', payload) }
.to create_some_remote_accounts
.and create_fewer_than_rate_limit_accounts
end
end
private
def create_some_remote_accounts
change(Account.remote, :count).by_at_least(2)
end
def create_fewer_than_rate_limit_accounts
change(Account.remote, :count).by_at_most(5)
end
end

View file

@ -47,8 +47,15 @@ RSpec.describe DeleteAccountService, type: :service do
let!(:account_note) { Fabricate(:account_note, account: account) }
it 'deletes associated owned records' do
expect { subject }.to change {
it 'deletes associated owned and target records and target notifications' do
expect { subject }
.to delete_associated_owned_records
.and delete_associated_target_records
.and delete_associated_target_notifications
end
def delete_associated_owned_records
change do
[
account.statuses,
account.media_attachments,
@ -61,7 +68,7 @@ RSpec.describe DeleteAccountService, type: :service do
account.polls,
account.account_notes,
].map(&:count)
}.from([3, 1, 1, 1, 1, 1, 2, 2, 1, 1]).to([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
end.from([3, 1, 1, 1, 1, 1, 2, 2, 1, 1]).to([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
end
it 'deletes associated owned record groups' do
@ -82,20 +89,20 @@ RSpec.describe DeleteAccountService, type: :service do
expect { bookmark_category_status.reload }.to raise_error(ActiveRecord::RecordNotFound)
end
it 'deletes associated target records' do
expect { subject }.to change {
def delete_associated_target_records
change do
[
AccountPin.where(target_account: account),
].map(&:count)
}.from([1]).to([0])
end.from([1]).to([0])
end
it 'deletes associated target notifications' do
expect { subject }.to change {
def delete_associated_target_notifications
change do
%w(
poll favourite emoji_reaction status mention follow
).map { |type| Notification.where(type: type).count }
}.from([1, 1, 1, 1, 1, 1]).to([0, 0, 0, 0, 0, 0])
end.from([1, 1, 1, 1, 1, 1]).to([0, 0, 0, 0, 0, 0])
end
end

View file

@ -18,14 +18,15 @@ RSpec.describe SuspendAccountService, type: :service do
account.suspend!
end
it "unmerges from local followers' feeds" do
subject
it 'unmerges from feeds of local followers and preserves suspended flag' do
expect { subject }
.to_not change_suspended_flag
expect(FeedManager.instance).to have_received(:unmerge_from_home).with(account, local_follower)
expect(FeedManager.instance).to have_received(:unmerge_from_list).with(account, list)
end
it 'does not change the “suspended” flag' do
expect { subject }.to_not change(account, :suspended?)
def change_suspended_flag
change(account, :suspended?)
end
end

View file

@ -45,14 +45,19 @@ RSpec.describe UnsuspendAccountService, type: :service do
remote_follower.follow!(account)
end
it "merges back into local followers' feeds" do
it 'merges back into feeds of local followers and sends update' do
subject
expect_feeds_merged
expect_updates_sent
end
def expect_feeds_merged
expect(FeedManager.instance).to have_received(:merge_into_home).with(account, local_follower)
expect(FeedManager.instance).to have_received(:merge_into_list).with(account, list)
end
it 'sends an update actor to followers and reporters' do
subject
def expect_updates_sent
expect(a_request(:post, remote_follower.inbox_url).with { |req| match_update_actor_request(req, account) }).to have_been_made.once
expect(a_request(:post, remote_reporter.inbox_url).with { |req| match_update_actor_request(req, account) }).to have_been_made.once
end
@ -73,19 +78,20 @@ RSpec.describe UnsuspendAccountService, type: :service do
allow(resolve_account_service).to receive(:call).with(account).and_return(account)
end
it 're-fetches the account' do
subject
it 're-fetches the account, merges feeds, and preserves suspended' do
expect { subject }
.to_not change_suspended_flag
expect_feeds_merged
expect(resolve_account_service).to have_received(:call).with(account)
end
it "merges back into local followers' feeds" do
subject
def expect_feeds_merged
expect(FeedManager.instance).to have_received(:merge_into_home).with(account, local_follower)
expect(FeedManager.instance).to have_received(:merge_into_list).with(account, list)
end
it 'does not change the “suspended” flag' do
expect { subject }.to_not change(account, :suspended?)
def change_suspended_flag
change(account, :suspended?)
end
end
@ -97,19 +103,20 @@ RSpec.describe UnsuspendAccountService, type: :service do
end
end
it 're-fetches the account' do
subject
it 're-fetches the account, does not merge feeds, marks suspended' do
expect { subject }
.to change_suspended_to_true
expect(resolve_account_service).to have_received(:call).with(account)
expect_feeds_not_merged
end
it "does not merge back into local followers' feeds" do
subject
def expect_feeds_not_merged
expect(FeedManager.instance).to_not have_received(:merge_into_home).with(account, local_follower)
expect(FeedManager.instance).to_not have_received(:merge_into_list).with(account, list)
end
it 'marks account as suspended' do
expect { subject }.to change(account, :suspended?).from(false).to(true)
def change_suspended_to_true
change(account, :suspended?).from(false).to(true)
end
end
@ -118,13 +125,14 @@ RSpec.describe UnsuspendAccountService, type: :service do
allow(resolve_account_service).to receive(:call).with(account).and_return(nil)
end
it 're-fetches the account' do
it 're-fetches the account and does not merge feeds' do
subject
expect(resolve_account_service).to have_received(:call).with(account)
expect_feeds_not_merged
end
it "does not merge back into local followers' feeds" do
subject
def expect_feeds_not_merged
expect(FeedManager.instance).to_not have_received(:merge_into_home).with(account, local_follower)
expect(FeedManager.instance).to_not have_received(:merge_into_list).with(account, list)
end