webhook_policy_spec.rb 964 B

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