feeds_controller_policy_spec.rb 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. describe Controllers::KnowledgeBase::FeedsControllerPolicy do
  4. subject { described_class.new(user, record) }
  5. include_context 'basic Knowledge Base'
  6. let(:record_class) { KnowledgeBase::FeedsController }
  7. let(:params) { {} }
  8. let(:record) do
  9. rec = record_class.new
  10. rec.params = params
  11. rec
  12. end
  13. context 'with KB user' do
  14. let(:user) { create(:admin) }
  15. it { is_expected.to permit_actions(:root, :category) }
  16. end
  17. context 'with non-KB user' do
  18. let(:user) { create(:customer) }
  19. it { is_expected.to forbid_actions(:root, :category) }
  20. end
  21. context 'with token with KB user' do
  22. let(:user) { create(:admin) }
  23. let(:token) { create(:token, action: 'KnowledgeBaseFeed', user: user) }
  24. let(:params) { { token: token.token } }
  25. it { is_expected.to permit_actions(:root, :category) }
  26. end
  27. context 'with token with non-KB user' do
  28. let(:user) { create(:customer) }
  29. let(:token) { create(:token, action: 'KnowledgeBaseFeed', user: user) }
  30. let(:params) { { token: token.token } }
  31. it { is_expected.to forbid_actions(:root, :category) }
  32. end
  33. context 'with nonexistant token' do
  34. let(:user) { nil }
  35. let(:params) { { token: 'foobar' } }
  36. it { is_expected.to forbid_actions(:root, :category) }
  37. end
  38. context 'without both token and user' do
  39. let(:user) { nil }
  40. it { is_expected.to forbid_actions(:root, :category) }
  41. end
  42. end