webhook_policy_spec.rb 981 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. require 'pundit/rspec'
  4. describe WebhookPolicy do
  5. let(:policy) { described_class }
  6. let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account }
  7. let(:john) { Fabricate(:account) }
  8. permissions :index?, :create? do
  9. context 'with an admin' do
  10. it 'permits' do
  11. expect(policy).to permit(admin, Webhook)
  12. end
  13. end
  14. context 'with a non-admin' do
  15. it 'denies' do
  16. expect(policy).to_not permit(john, Webhook)
  17. end
  18. end
  19. end
  20. permissions :show?, :update?, :enable?, :disable?, :rotate_secret?, :destroy? do
  21. let(:webhook) { Fabricate(:webhook, events: ['account.created', 'report.created']) }
  22. context 'with an admin' do
  23. it 'permits' do
  24. expect(policy).to permit(admin, webhook)
  25. end
  26. end
  27. context 'with a non-admin' do
  28. it 'denies' do
  29. expect(policy).to_not permit(john, webhook)
  30. end
  31. end
  32. end
  33. end