category.rb 1.1 KB

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