suspensions_spec.rb 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Account::Suspensions do
  4. subject { Fabricate(:account) }
  5. describe '.suspended' do
  6. let!(:suspended_account) { Fabricate :account, suspended: true }
  7. before { Fabricate :account, suspended: false }
  8. it 'returns accounts that are suspended' do
  9. expect(Account.suspended)
  10. .to contain_exactly(suspended_account)
  11. end
  12. end
  13. describe '#suspended_locally?' do
  14. context 'when the account is not suspended' do
  15. it { is_expected.to_not be_suspended_locally }
  16. end
  17. context 'when the account is suspended locally' do
  18. before { subject.update!(suspended_at: 1.day.ago, suspension_origin: :local) }
  19. it { is_expected.to be_suspended_locally }
  20. end
  21. context 'when the account is suspended remotely' do
  22. before { subject.update!(suspended_at: 1.day.ago, suspension_origin: :remote) }
  23. it { is_expected.to_not be_suspended_locally }
  24. end
  25. end
  26. describe '#suspend!' do
  27. it 'marks the account as suspended and creates a deletion request' do
  28. expect { subject.suspend! }
  29. .to change(subject, :suspended?).from(false).to(true)
  30. .and change(subject, :suspended_locally?).from(false).to(true)
  31. .and(change { AccountDeletionRequest.exists?(account: subject) }.from(false).to(true))
  32. end
  33. context 'when the account is of a local user' do
  34. subject { local_user_account }
  35. let!(:local_user_account) { Fabricate(:user, email: 'foo+bar@domain.org').account }
  36. it 'creates a canonical domain block' do
  37. expect { subject.suspend! }
  38. .to change { CanonicalEmailBlock.block?(subject.user_email) }.from(false).to(true)
  39. end
  40. context 'when a canonical domain block already exists for that email' do
  41. before { Fabricate(:canonical_email_block, email: subject.user_email) }
  42. it 'does not raise an error' do
  43. expect { subject.suspend! }
  44. .to_not raise_error
  45. end
  46. end
  47. end
  48. end
  49. end