Skip to content

Commit

Permalink
Reduce expectations for RSpec/MultipleExpectations cop in `MoveWork…
Browse files Browse the repository at this point in the history
…er` spec (mastodon#27880)
  • Loading branch information
mjankowski authored Nov 16, 2023
1 parent 3f0c156 commit 8a28541
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions spec/workers/move_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,16 @@
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

Expand All @@ -54,27 +53,44 @@

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
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(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

Expand Down

0 comments on commit 8a28541

Please sign in to comment.