category.rb 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. FactoryBot.define do
  3. factory 'knowledge_base/category', aliases: %i[knowledge_base_category] do
  4. transient do
  5. add_translation { true }
  6. end
  7. knowledge_base { parent&.knowledge_base || create(:knowledge_base) }
  8. category_icon { 'f04b' }
  9. before(:create) do |category|
  10. next if category.translations.present?
  11. category.translations << create(:'knowledge_base/category/translation', category: category)
  12. end
  13. trait :empty # empty placeholder for better readability
  14. %i[published internal draft archived].each do |state|
  15. trait "containing_#{state}" do
  16. after(:create) do |obj|
  17. create(:knowledge_base_answer, state, parent: obj)
  18. obj.reload
  19. end
  20. end
  21. end
  22. end
  23. factory 'kb_category_with_tree', parent: 'knowledge_base/category' do
  24. after(:create) do |obj|
  25. create(:knowledge_base_category, parent: obj)
  26. level2 = create(:knowledge_base_category, parent: obj)
  27. create_list(:knowledge_base_category, 2, parent: level2)
  28. level3 = level2.children.reload.sorted.first
  29. create_list(:knowledge_base_category, 2, parent: level3)
  30. obj.reload
  31. end
  32. end
  33. end