account_moderation_note_policy_spec.rb 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe AccountModerationNotePolicy do
  4. subject { described_class }
  5. let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account }
  6. let(:john) { Fabricate(:account) }
  7. permissions :create? do
  8. context 'when staff' do
  9. it 'grants to create' do
  10. expect(subject).to permit(admin, AccountModerationNote)
  11. end
  12. end
  13. context 'when not staff' do
  14. it 'denies to create' do
  15. expect(subject).to_not permit(john, AccountModerationNote)
  16. end
  17. end
  18. end
  19. permissions :destroy? do
  20. let(:account_moderation_note) do
  21. Fabricate(:account_moderation_note,
  22. account: john,
  23. target_account: Fabricate(:account))
  24. end
  25. context 'when admin' do
  26. it 'grants to destroy' do
  27. expect(subject).to permit(admin, account_moderation_note)
  28. end
  29. end
  30. context 'when owner' do
  31. it 'grants to destroy' do
  32. expect(subject).to permit(john, account_moderation_note)
  33. end
  34. end
  35. context 'when neither admin nor owner' do
  36. let(:kevin) { Fabricate(:account) }
  37. it 'denies to destroy' do
  38. expect(subject).to_not permit(kevin, account_moderation_note)
  39. end
  40. end
  41. end
  42. end