mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-22 06:06:45 +00:00
Reduce move worker factory creation
This commit is contained in:
parent
e15befebbd
commit
1bdc17e6de
|
@ -73,95 +73,110 @@ RSpec.describe MoveWorker do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
shared_examples 'block and mute handling' do
|
|
||||||
it 'makes blocks and mutes carry over and adds a note' do
|
|
||||||
subject.perform(source_account.id, target_account.id)
|
|
||||||
|
|
||||||
expect(block_service).to have_received(:call).with(blocking_account, target_account)
|
|
||||||
expect(muting_account.muting?(target_account)).to be true
|
|
||||||
|
|
||||||
expect(
|
|
||||||
[note_account_comment, mute_account_comment]
|
|
||||||
).to all include(source_account.acct)
|
|
||||||
end
|
|
||||||
|
|
||||||
def note_account_comment
|
|
||||||
AccountNote.find_by(account: blocking_account, target_account: target_account).comment
|
|
||||||
end
|
|
||||||
|
|
||||||
def mute_account_comment
|
|
||||||
AccountNote.find_by(account: muting_account, target_account: target_account).comment
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
shared_examples 'followers count handling' do
|
|
||||||
it 'updates the source and target account followers counts' do
|
|
||||||
subject.perform(source_account.id, target_account.id)
|
|
||||||
|
|
||||||
expect(source_account.reload.followers_count).to eq(source_account.passive_relationships.count)
|
|
||||||
expect(target_account.reload.followers_count).to eq(target_account.passive_relationships.count)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
shared_examples 'lists handling' do
|
|
||||||
it 'puts the new account on the list and makes valid lists', :inline_jobs do
|
|
||||||
subject.perform(source_account.id, target_account.id)
|
|
||||||
|
|
||||||
expect(list.accounts.include?(target_account)).to be true
|
|
||||||
expect(ListAccount.all).to all be_valid
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
shared_examples 'common tests' do
|
shared_examples 'common tests' do
|
||||||
include_examples 'user note handling'
|
include_examples 'user note handling'
|
||||||
include_examples 'block and mute handling'
|
|
||||||
include_examples 'followers count handling'
|
it 'handles data movement', :inline_jobs do
|
||||||
include_examples 'lists handling'
|
subject.perform(source_account.id, target_account.id)
|
||||||
|
|
||||||
|
expect_successful_list_movement
|
||||||
|
expect_successful_followers_movement
|
||||||
|
expect_successful_block_movement
|
||||||
|
expect_successful_mute_movement
|
||||||
|
end
|
||||||
|
|
||||||
context 'when a local user already follows both source and target' do
|
context 'when a local user already follows both source and target' do
|
||||||
before do
|
before { local_follower.request_follow!(target_account) }
|
||||||
local_follower.request_follow!(target_account)
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples 'user note handling'
|
include_examples 'user note handling'
|
||||||
include_examples 'block and mute handling'
|
|
||||||
include_examples 'followers count handling'
|
it 'handles data movement', :inline_jobs do
|
||||||
include_examples 'lists handling'
|
subject.perform(source_account.id, target_account.id)
|
||||||
|
|
||||||
|
expect_successful_list_movement
|
||||||
|
expect_successful_followers_movement
|
||||||
|
expect_successful_block_movement
|
||||||
|
expect_successful_mute_movement
|
||||||
|
end
|
||||||
|
|
||||||
context 'when the local user already has the target in a list' do
|
context 'when the local user already has the target in a list' do
|
||||||
before do
|
before { list.accounts << target_account }
|
||||||
list.accounts << target_account
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples 'lists handling'
|
it 'handles list movement', :inline_jobs do
|
||||||
|
subject.perform(source_account.id, target_account.id)
|
||||||
|
|
||||||
|
expect_successful_list_movement
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when a local follower already has a pending request to the target' do
|
context 'when a local follower already has a pending request to the target' do
|
||||||
before do
|
before { local_follower.follow!(target_account) }
|
||||||
local_follower.follow!(target_account)
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples 'user note handling'
|
include_examples 'user note handling'
|
||||||
include_examples 'block and mute handling'
|
|
||||||
include_examples 'followers count handling'
|
it 'handles data movement', :inline_jobs do
|
||||||
include_examples 'lists handling'
|
subject.perform(source_account.id, target_account.id)
|
||||||
|
|
||||||
|
expect_successful_list_movement
|
||||||
|
expect_successful_followers_movement
|
||||||
|
expect_successful_block_movement
|
||||||
|
expect_successful_mute_movement
|
||||||
|
end
|
||||||
|
|
||||||
context 'when the local user already has the target in a list' do
|
context 'when the local user already has the target in a list' do
|
||||||
before do
|
before { list.accounts << target_account }
|
||||||
list.accounts << target_account
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples 'lists handling'
|
it 'handles list movement', :inline_jobs do
|
||||||
|
subject.perform(source_account.id, target_account.id)
|
||||||
|
|
||||||
|
expect_successful_list_movement
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def expect_successful_list_movement
|
||||||
|
expect(list.accounts)
|
||||||
|
.to include(target_account)
|
||||||
|
expect(ListAccount.all)
|
||||||
|
.to all be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
def expect_successful_followers_movement
|
||||||
|
expect(source_account.reload.followers_count)
|
||||||
|
.to eq(source_account.passive_relationships.count)
|
||||||
|
expect(target_account.reload.followers_count)
|
||||||
|
.to eq(target_account.passive_relationships.count)
|
||||||
|
end
|
||||||
|
|
||||||
|
def expect_successful_block_movement
|
||||||
|
expect(block_service)
|
||||||
|
.to have_received(:call).with(blocking_account, target_account)
|
||||||
|
|
||||||
|
expect(account_note_from(blocking_account).comment)
|
||||||
|
.to include(source_account.acct)
|
||||||
|
end
|
||||||
|
|
||||||
|
def expect_successful_mute_movement
|
||||||
|
expect(muting_account)
|
||||||
|
.to be_muting(target_account)
|
||||||
|
expect(account_note_from(muting_account).comment)
|
||||||
|
.to include(source_account.acct)
|
||||||
|
end
|
||||||
|
|
||||||
|
def account_note_from(account)
|
||||||
|
AccountNote
|
||||||
|
.find_by(account: account, target_account: target_account)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#perform' do
|
describe '#perform' do
|
||||||
context 'when both accounts are distant' do
|
context 'when both accounts are distant' do
|
||||||
it 'calls UnfollowFollowWorker' do
|
it 'calls UnfollowFollowWorker' do
|
||||||
subject.perform(source_account.id, target_account.id)
|
subject.perform(source_account.id, target_account.id)
|
||||||
expect(UnfollowFollowWorker).to have_enqueued_sidekiq_job(local_follower.id, source_account.id, target_account.id, false)
|
|
||||||
|
expect(UnfollowFollowWorker)
|
||||||
|
.to have_enqueued_sidekiq_job(local_follower.id, source_account.id, target_account.id, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
include_examples 'common tests'
|
include_examples 'common tests'
|
||||||
|
@ -172,7 +187,9 @@ RSpec.describe MoveWorker do
|
||||||
|
|
||||||
it 'calls UnfollowFollowWorker' do
|
it 'calls UnfollowFollowWorker' do
|
||||||
subject.perform(source_account.id, target_account.id)
|
subject.perform(source_account.id, target_account.id)
|
||||||
expect(UnfollowFollowWorker).to have_enqueued_sidekiq_job(local_follower.id, source_account.id, target_account.id, true)
|
|
||||||
|
expect(UnfollowFollowWorker)
|
||||||
|
.to have_enqueued_sidekiq_job(local_follower.id, source_account.id, target_account.id, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
include_examples 'common tests'
|
include_examples 'common tests'
|
||||||
|
@ -184,15 +201,20 @@ RSpec.describe MoveWorker do
|
||||||
|
|
||||||
it 'calls makes local followers follow the target account' do
|
it 'calls makes local followers follow the target account' do
|
||||||
subject.perform(source_account.id, target_account.id)
|
subject.perform(source_account.id, target_account.id)
|
||||||
expect(local_follower.following?(target_account)).to be true
|
|
||||||
|
expect(local_follower).to be_following(target_account)
|
||||||
end
|
end
|
||||||
|
|
||||||
include_examples 'common tests'
|
include_examples 'common tests'
|
||||||
|
|
||||||
it 'does not allow the moved account to follow themselves' do
|
context 'when source follows target' do
|
||||||
source_account.follow!(target_account)
|
before { source_account.follow!(target_account) }
|
||||||
subject.perform(source_account.id, target_account.id)
|
|
||||||
expect(target_account.following?(target_account)).to be false
|
it 'does not allow the moved account to follow themselves' do
|
||||||
|
subject.perform(source_account.id, target_account.id)
|
||||||
|
|
||||||
|
expect(target_account).to_not be_following(target_account)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue