account_batch_spec.rb 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Form::AccountBatch do
  4. let(:account_batch) { described_class.new }
  5. describe '#save' do
  6. subject { account_batch.save }
  7. let(:account) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account }
  8. let(:account_ids) { [] }
  9. let(:query) { Account.none }
  10. before do
  11. account_batch.assign_attributes(
  12. action: action,
  13. current_account: account,
  14. account_ids: account_ids,
  15. query: query,
  16. select_all_matching: select_all_matching
  17. )
  18. end
  19. context 'when action is "suspend"' do
  20. let(:action) { 'suspend' }
  21. let(:target_account) { Fabricate(:account) }
  22. let(:target_account2) { Fabricate(:account) }
  23. before do
  24. Fabricate(:report, target_account: target_account)
  25. Fabricate(:report, target_account: target_account2)
  26. end
  27. context 'when accounts are passed as account_ids' do
  28. let(:select_all_matching) { '0' }
  29. let(:account_ids) { [target_account.id, target_account2.id] }
  30. it 'suspends the expected users' do
  31. expect { subject }.to change { [target_account.reload.suspended?, target_account2.reload.suspended?] }.from([false, false]).to([true, true])
  32. end
  33. it 'closes open reports targeting the suspended users' do
  34. expect { subject }.to change { Report.unresolved.where(target_account: [target_account, target_account2]).count }.from(2).to(0)
  35. end
  36. end
  37. context 'when accounts are passed as a query' do
  38. let(:select_all_matching) { '1' }
  39. let(:query) { Account.where(id: [target_account.id, target_account2.id]) }
  40. it 'suspends the expected users' do
  41. expect { subject }.to change { [target_account.reload.suspended?, target_account2.reload.suspended?] }.from([false, false]).to([true, true])
  42. end
  43. it 'closes open reports targeting the suspended users' do
  44. expect { subject }.to change { Report.unresolved.where(target_account: [target_account, target_account2]).count }.from(2).to(0)
  45. end
  46. end
  47. end
  48. end
  49. end