You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.1 KiB

  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. require 'pundit/rspec'
  4. RSpec.describe ReportNotePolicy do
  5. let(: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 'staff?' do
  10. it 'permits' do
  11. expect(subject).to permit(admin, ReportNote)
  12. end
  13. end
  14. context '!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 '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 'admin?' do
  28. context 'owner?' do
  29. it 'permit' do
  30. report_note = Fabricate(:report_note, account: john)
  31. expect(subject).to permit(john, report_note)
  32. end
  33. end
  34. context '!owner?' do
  35. it 'denies' do
  36. report_note = Fabricate(:report_note)
  37. expect(subject).to_not permit(john, report_note)
  38. end
  39. end
  40. end
  41. end
  42. end