category_policy_spec.rb 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. require 'policies/knowledge_base_policy_examples'
  4. describe KnowledgeBase::CategoryPolicy do
  5. subject(:policy) { described_class.new(user, record) }
  6. let(:record) { create(:knowledge_base_category) }
  7. let(:user) { create(:user) }
  8. describe '#show?' do
  9. include_examples 'with KB policy check', editor: true, reader: true, none: false, method: :show?
  10. end
  11. describe '#show_public?' do
  12. context 'when category has public content' do
  13. before { allow(record).to receive(:public_content?).and_return(true) }
  14. include_examples 'with KB policy check', editor: true, reader: true, none: true, method: :show_public?
  15. end
  16. context 'when category has no public content' do
  17. before { allow(record).to receive(:public_content?).and_return(false) }
  18. include_examples 'with KB policy check', editor: true, reader: false, none: false, method: :show_public?
  19. end
  20. end
  21. describe '#permissions?' do
  22. include_examples 'with KB policy check', editor: true, reader: false, none: false, method: :permissions?
  23. end
  24. describe '#update?' do
  25. include_examples 'with KB policy check', editor: true, reader: false, none: false, method: :update?
  26. end
  27. describe '#create?' do
  28. include_examples 'with KB policy check', editor: true, reader: false, none: false, method: :create?, access_method: :parent_access
  29. end
  30. describe '#destroy?' do
  31. include_examples 'with KB policy check', editor: true, reader: false, none: false, method: :destroy?, access_method: :parent_access
  32. end
  33. end