knowledge_base_contexts.rb 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. RSpec.shared_context 'basic Knowledge Base', current_user_id: 1 do # rubocop:disable RSpec/ContextWording
  3. let :knowledge_base do
  4. create(:knowledge_base)
  5. end
  6. let :primary_locale do
  7. knowledge_base.translation_primary.kb_locale
  8. end
  9. let :locale_name do
  10. primary_locale.system_locale.locale
  11. end
  12. let :alternative_locale do
  13. create(:knowledge_base_locale, knowledge_base: knowledge_base, system_locale: Locale.find_by(locale: 'lt'))
  14. end
  15. let :category do
  16. create(:knowledge_base_category, knowledge_base: knowledge_base)
  17. end
  18. let :subcategory do
  19. create(:knowledge_base_category, knowledge_base: knowledge_base, parent: category)
  20. end
  21. let :other_category do
  22. create(:knowledge_base_category, knowledge_base: knowledge_base)
  23. end
  24. let :draft_answer do
  25. create(:knowledge_base_answer, category: category)
  26. end
  27. let :published_answer do
  28. create(:knowledge_base_answer, :published, :with_attachment, category: category)
  29. end
  30. let :published_answer_in_other_category do
  31. create(:knowledge_base_answer, :published, category: other_category)
  32. end
  33. let :published_answer_in_subcategory do
  34. create(:knowledge_base_answer, :published, category: subcategory)
  35. end
  36. let :published_answer_with_video do
  37. create(:knowledge_base_answer, :published, :with_video, category: category)
  38. end
  39. let :published_answer_with_image do
  40. create(:knowledge_base_answer, :published, :with_image, category: category)
  41. end
  42. let :published_answer_with_tag do
  43. create(:knowledge_base_answer, :published, :with_tag, tag_names: [published_answer_tag_name], category: category)
  44. end
  45. let(:published_answer_tag_name) do
  46. 'example_kb_tag'
  47. end
  48. let :internal_answer do
  49. create(:knowledge_base_answer, :internal, category: category)
  50. end
  51. let :archived_answer do
  52. create(:knowledge_base_answer, :archived, category: category)
  53. end
  54. end
  55. RSpec.shared_context 'Knowledge Base menu items', current_user_id: 1 do # rubocop:disable RSpec/ContextWording
  56. # rubocop:disable RSpec/LetSetup
  57. let!(:menu_item_1) { create(:knowledge_base_menu_item, :for_header, kb_locale: primary_locale) }
  58. let!(:menu_item_2) { create(:knowledge_base_menu_item, :for_header, kb_locale: primary_locale) }
  59. let!(:menu_item_3) { create(:knowledge_base_menu_item, :for_footer, kb_locale: primary_locale) }
  60. let!(:menu_item_4) { create(:knowledge_base_menu_item, :for_footer, kb_locale: alternative_locale) }
  61. let!(:menu_item_5) { create(:knowledge_base_menu_item, :for_footer, kb_locale: alternative_locale) }
  62. # rubocop:enable RSpec/LetSetup
  63. end