Remove 2x double subject call in `models/form/account_batch` spec (#28209)

th-new
Matt Jankowski 2023-12-04 10:41:43 -05:00 committed by GitHub
parent 71e5a16eba
commit 89a8e6e622
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 29 additions and 11 deletions

View File

@ -37,12 +37,10 @@ RSpec.describe Form::AccountBatch do
let(:select_all_matching) { '0' } let(:select_all_matching) { '0' }
let(:account_ids) { [target_account.id, target_account2.id] } let(:account_ids) { [target_account.id, target_account2.id] }
it 'suspends the expected users' do it 'suspends the expected users and closes open reports' do
expect { subject }.to change { [target_account.reload.suspended?, target_account2.reload.suspended?] }.from([false, false]).to([true, true]) expect { subject }
end .to change_account_suspensions
.and change_open_reports_for_accounts
it 'closes open reports targeting the suspended users' do
expect { subject }.to change { Report.unresolved.where(target_account: [target_account, target_account2]).count }.from(2).to(0)
end end
end end
@ -50,13 +48,33 @@ RSpec.describe Form::AccountBatch do
let(:select_all_matching) { '1' } let(:select_all_matching) { '1' }
let(:query) { Account.where(id: [target_account.id, target_account2.id]) } let(:query) { Account.where(id: [target_account.id, target_account2.id]) }
it 'suspends the expected users' do it 'suspends the expected users and closes open reports' do
expect { subject }.to change { [target_account.reload.suspended?, target_account2.reload.suspended?] }.from([false, false]).to([true, true]) expect { subject }
.to change_account_suspensions
.and change_open_reports_for_accounts
end
end end
it 'closes open reports targeting the suspended users' do private
expect { subject }.to change { Report.unresolved.where(target_account: [target_account, target_account2]).count }.from(2).to(0)
end def change_account_suspensions
change { relevant_account_suspension_statuses }
.from([false, false])
.to([true, true])
end
def change_open_reports_for_accounts
change(relevant_account_unresolved_reports, :count)
.from(2)
.to(0)
end
def relevant_account_unresolved_reports
Report.unresolved.where(target_account: [target_account, target_account2])
end
def relevant_account_suspension_statuses
[target_account.reload, target_account2.reload].map(&:suspended?)
end end
end end
end end