Remove 2x double subject call in `models/form/account_batch` spec (#28209)
parent
71e5a16eba
commit
89a8e6e622
|
@ -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)
|
|
||||||
|
def change_account_suspensions
|
||||||
|
change { relevant_account_suspension_statuses }
|
||||||
|
.from([false, false])
|
||||||
|
.to([true, true])
|
||||||
end
|
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
|
||||||
|
|
Loading…
Reference in New Issue