1
0

appeal_policy_spec.rb 1.2 KB

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