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.

51 lines
1.2 KiB

  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. require 'pundit/rspec'
  4. describe AppealPolicy do
  5. let(:policy) { described_class }
  6. let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account }
  7. let(:john) { Fabricate(:account) }
  8. let(:appeal) { Fabricate(:appeal) }
  9. permissions :index? do
  10. context 'with an admin' do
  11. it 'permits' do
  12. expect(policy).to permit(admin, Tag)
  13. end
  14. end
  15. context 'with a non-admin' do
  16. it 'denies' do
  17. expect(policy).to_not permit(john, Tag)
  18. end
  19. end
  20. end
  21. permissions :reject? do
  22. context 'with an admin' do
  23. context 'with a pending appeal' do
  24. before { allow(appeal).to receive(:pending?).and_return(true) }
  25. it 'permits' do
  26. expect(policy).to permit(admin, appeal)
  27. end
  28. end
  29. context 'with a not pending appeal' do
  30. before { allow(appeal).to receive(:pending?).and_return(false) }
  31. it 'denies' do
  32. expect(policy).to_not permit(admin, appeal)
  33. end
  34. end
  35. end
  36. context 'with a non admin' do
  37. it 'denies' do
  38. expect(policy).to_not permit(john, appeal)
  39. end
  40. end
  41. end
  42. end