From 8a285413f71eac89d87ab64c985cd9f33aabdaaa Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 16 Nov 2023 05:03:51 -0500 Subject: [PATCH] Reduce expectations for `RSpec/MultipleExpectations` cop in `MoveWorker` spec (#27880) --- spec/workers/move_worker_spec.rb | 36 +++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/spec/workers/move_worker_spec.rb b/spec/workers/move_worker_spec.rb index efad92c047..774296fda4 100644 --- a/spec/workers/move_worker_spec.rb +++ b/spec/workers/move_worker_spec.rb @@ -35,17 +35,16 @@ describe MoveWorker do context 'when user notes are short enough' do it 'copies user note with prelude' do 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(AccountNote.find_by(account: account_note.account, target_account: target_account).comment).to include(account_note.comment) + expect(relevant_account_note.comment) + .to include(source_account.acct, account_note.comment) end 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') 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(AccountNote.find_by(account: account_note.account, target_account: target_account).comment).to include(account_note.comment) - 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(source_account.acct, account_note.comment, new_account_note.comment) end end @@ -54,16 +53,24 @@ describe MoveWorker do it 'copies user note without prelude' do 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 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') 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 + + private + + def relevant_account_note + AccountNote.find_by(account: account_note.account, target_account: target_account) + end end shared_examples 'block and mute handling' do @@ -71,10 +78,19 @@ describe MoveWorker do subject.perform(source_account.id, target_account.id) 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(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