2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2019-06-04 03:40:48 +00:00
|
|
|
FactoryBot.define do
|
|
|
|
factory 'knowledge_base/category', aliases: %i[knowledge_base_category] do
|
2019-09-24 13:04:42 +00:00
|
|
|
transient do
|
|
|
|
add_translation { true }
|
|
|
|
end
|
|
|
|
|
2019-06-04 03:40:48 +00:00
|
|
|
knowledge_base { parent&.knowledge_base || create(:knowledge_base) }
|
|
|
|
category_icon { 'f04b' }
|
2019-09-18 17:25:04 +00:00
|
|
|
|
|
|
|
before(:create) do |category|
|
|
|
|
next if category.translations.present?
|
|
|
|
|
|
|
|
category.translations << create('knowledge_base/category/translation', category: category)
|
|
|
|
end
|
2020-08-05 13:48:41 +00:00
|
|
|
|
|
|
|
trait :empty # empty placeholder for better readability
|
|
|
|
|
|
|
|
%i[published internal draft archived].each do |state|
|
|
|
|
trait "containing_#{state}" do
|
|
|
|
after(:create) do |obj|
|
|
|
|
create(:knowledge_base_answer, state, parent: obj)
|
|
|
|
|
|
|
|
obj.reload
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-06-04 03:40:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
factory 'kb_category_with_tree', parent: 'knowledge_base/category' do
|
|
|
|
after(:create) do |obj|
|
|
|
|
create(:knowledge_base_category, parent: obj)
|
|
|
|
|
|
|
|
level2 = create(:knowledge_base_category, parent: obj)
|
2020-11-24 16:20:57 +00:00
|
|
|
create_list(:knowledge_base_category, 2, parent: level2)
|
2019-06-04 03:40:48 +00:00
|
|
|
|
|
|
|
level3 = level2.children.reload.first
|
2020-11-24 16:20:57 +00:00
|
|
|
create_list(:knowledge_base_category, 2, parent: level3)
|
2019-06-04 03:40:48 +00:00
|
|
|
|
|
|
|
obj.reload
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|