answer_spec.rb 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. require 'models/concerns/checks_kb_client_notification_examples'
  4. require 'models/concerns/has_tags_examples'
  5. require 'models/contexts/factory_context'
  6. RSpec.describe KnowledgeBase::Answer, type: :model, current_user_id: 1 do
  7. subject!(:kb_answer) { create(:knowledge_base_answer) }
  8. it_behaves_like 'HasTags'
  9. include_context 'factory'
  10. it_behaves_like 'ChecksKbClientNotification'
  11. it { is_expected.not_to validate_presence_of(:category_id) }
  12. it { is_expected.to belong_to(:category) }
  13. it { expect(kb_answer.attachments).to be_blank }
  14. context 'with attachment' do
  15. subject(:kb_answer) { create(:knowledge_base_answer, :with_attachment) }
  16. it { expect(kb_answer.attachments).to be_present }
  17. end
  18. describe '#assets', current_user_id: -> { user.id } do
  19. let(:assets) { another_category_answer && internal_answer.assets }
  20. let(:user) { create(:agent) }
  21. let(:another_category) { create(:knowledge_base_category, knowledge_base: knowledge_base) }
  22. let(:another_category_answer) { create(:knowledge_base_answer, :internal, category: another_category) }
  23. include_context 'basic Knowledge Base'
  24. context 'without permissions' do
  25. it { expect(assets).to include_assets_of internal_answer }
  26. it { expect(assets).to include_assets_of category }
  27. end
  28. context 'with readable another category' do
  29. before do
  30. KnowledgeBase::PermissionsUpdate
  31. .new(another_category)
  32. .update! user.roles.first => 'reader'
  33. end
  34. it { expect(assets).to include_assets_of internal_answer }
  35. it { expect(assets).to include_assets_of category }
  36. end
  37. context 'with hidden another category' do
  38. before do
  39. KnowledgeBase::PermissionsUpdate
  40. .new(another_category)
  41. .update! user.roles.first => 'none'
  42. end
  43. it { expect(assets).to include_assets_of internal_answer }
  44. it { expect(assets).to include_assets_of category }
  45. context 'with published answer' do
  46. let(:another_category_published_answer) { create(:knowledge_base_answer, :published, category: another_category) }
  47. before { another_category_published_answer }
  48. it { expect(assets).to include_assets_of internal_answer }
  49. it { expect(assets).to include_assets_of category }
  50. end
  51. end
  52. end
  53. end