account_moderation_note_policy_spec.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. require 'pundit/rspec'
  4. RSpec.describe AccountModerationNotePolicy do
  5. subject { described_class }
  6. let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account }
  7. let(:john) { Fabricate(:account) }
  8. permissions :create? do
  9. context 'when staff' do
  10. it 'grants to create' do
  11. expect(subject).to permit(admin, described_class)
  12. end
  13. end
  14. context 'when not staff' do
  15. it 'denies to create' do
  16. expect(subject).to_not permit(john, described_class)
  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 'when admin' do
  27. it 'grants to destroy' do
  28. expect(subject).to permit(admin, account_moderation_note)
  29. end
  30. end
  31. context 'when owner' do
  32. it 'grants to destroy' do
  33. expect(subject).to permit(john, account_moderation_note)
  34. end
  35. end
  36. context 'when 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