Reduce expectations for `RSpec/MultipleExpectations` cop in `MoveWorker` spec (#27880)

pull/27889/head
Matt Jankowski 2023-11-16 05:03:51 -05:00 committed by GitHub
parent 3f0c1566c3
commit 8a285413f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 10 deletions

View File

@ -35,17 +35,16 @@ describe MoveWorker do
context 'when user notes are short enough' do context 'when user notes are short enough' do
it 'copies user note with prelude' do it 'copies user note with prelude' do
subject.perform(source_account.id, target_account.id) subject.perform(source_account.id, target_account.id)
expect(AccountNote.find_by(account: account_note.account, target_account: target_account).comment).to include(source_account.acct) expect(relevant_account_note.comment)
expect(AccountNote.find_by(account: account_note.account, target_account: target_account).comment).to include(account_note.comment) .to include(source_account.acct, account_note.comment)
end end
it 'merges user notes when needed' do it 'merges user notes when needed' do
new_account_note = AccountNote.create!(account: account_note.account, target_account: target_account, comment: 'new note prior to move') new_account_note = AccountNote.create!(account: account_note.account, target_account: target_account, comment: 'new note prior to move')
subject.perform(source_account.id, target_account.id) subject.perform(source_account.id, target_account.id)
expect(AccountNote.find_by(account: account_note.account, target_account: target_account).comment).to include(source_account.acct) expect(relevant_account_note.comment)
expect(AccountNote.find_by(account: account_note.account, target_account: target_account).comment).to include(account_note.comment) .to include(source_account.acct, account_note.comment, new_account_note.comment)
expect(AccountNote.find_by(account: account_note.account, target_account: target_account).comment).to include(new_account_note.comment)
end end
end end
@ -54,16 +53,24 @@ describe MoveWorker do
it 'copies user note without prelude' do it 'copies user note without prelude' do
subject.perform(source_account.id, target_account.id) subject.perform(source_account.id, target_account.id)
expect(AccountNote.find_by(account: account_note.account, target_account: target_account).comment).to include(account_note.comment) expect(relevant_account_note.comment)
.to include(account_note.comment)
end end
it 'keeps user notes unchanged' do it 'keeps user notes unchanged' do
new_account_note = AccountNote.create!(account: account_note.account, target_account: target_account, comment: 'new note prior to move') new_account_note = AccountNote.create!(account: account_note.account, target_account: target_account, comment: 'new note prior to move')
subject.perform(source_account.id, target_account.id) subject.perform(source_account.id, target_account.id)
expect(AccountNote.find_by(account: account_note.account, target_account: target_account).comment).to include(new_account_note.comment) expect(relevant_account_note.comment)
.to include(new_account_note.comment)
end end
end end
private
def relevant_account_note
AccountNote.find_by(account: account_note.account, target_account: target_account)
end
end end
shared_examples 'block and mute handling' do shared_examples 'block and mute handling' do
@ -71,10 +78,19 @@ describe MoveWorker do
subject.perform(source_account.id, target_account.id) subject.perform(source_account.id, target_account.id)
expect(block_service).to have_received(:call).with(blocking_account, target_account) expect(block_service).to have_received(:call).with(blocking_account, target_account)
expect(AccountNote.find_by(account: blocking_account, target_account: target_account).comment).to include(source_account.acct)
expect(muting_account.muting?(target_account)).to be true expect(muting_account.muting?(target_account)).to be true
expect(AccountNote.find_by(account: muting_account, target_account: target_account).comment).to include(source_account.acct)
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
end end