1
0

account_warning_policy_spec.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe AccountWarningPolicy do
  4. subject { described_class }
  5. let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account }
  6. let(:account) { Fabricate(:account) }
  7. permissions :show? do
  8. context 'with an admin' do
  9. it { is_expected.to permit(admin, AccountWarning.new) }
  10. end
  11. context 'with a non-admin' do
  12. context 'when account is not target' do
  13. it { is_expected.to_not permit(account, AccountWarning.new) }
  14. end
  15. context 'when account is target' do
  16. it { is_expected.to permit(account, AccountWarning.new(target_account_id: account.id)) }
  17. end
  18. end
  19. end
  20. permissions :appeal? do
  21. context 'when account is not target' do
  22. it { is_expected.to_not permit(account, AccountWarning.new) }
  23. end
  24. context 'when account is target' do
  25. context 'when record is appealable' do
  26. it { is_expected.to permit(account, AccountWarning.new(target_account_id: account.id, created_at: Appeal::MAX_STRIKE_AGE.ago + 1.hour)) }
  27. end
  28. context 'when record is not appealable' do
  29. it { is_expected.to_not permit(account, AccountWarning.new(target_account_id: account.id, created_at: Appeal::MAX_STRIKE_AGE.ago - 1.hour)) }
  30. end
  31. end
  32. end
  33. end