report_note_policy_spec.rb 1.1 KB

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