account_moderation_note_policy_spec.rb 1.2 KB

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