report_note_policy_spec.rb 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. require 'pundit/rspec'
  4. RSpec.describe ReportNotePolicy 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 'permits' do
  11. expect(subject).to permit(admin, ReportNote)
  12. end
  13. end
  14. context 'with !staff?' do
  15. it 'denies' do
  16. expect(subject).to_not permit(john, ReportNote)
  17. end
  18. end
  19. end
  20. permissions :destroy? do
  21. context 'when admin?' do
  22. it 'permit' do
  23. report_note = Fabricate(:report_note, account: john)
  24. expect(subject).to permit(admin, report_note)
  25. end
  26. end
  27. context 'when owner?' do
  28. it 'permit' do
  29. report_note = Fabricate(:report_note, account: john)
  30. expect(subject).to permit(john, report_note)
  31. end
  32. end
  33. context 'with !owner?' do
  34. it 'denies' do
  35. report_note = Fabricate(:report_note)
  36. expect(subject).to_not permit(john, report_note)
  37. end
  38. end
  39. end
  40. end