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/answer', aliases: %i[knowledge_base_answer] do
|
2019-09-24 13:04:42 +00:00
|
|
|
transient do
|
2021-08-16 08:20:07 +00:00
|
|
|
add_translation { true }
|
|
|
|
translation_traits { [] }
|
2020-09-23 14:10:50 +00:00
|
|
|
translation_attributes { {} }
|
2021-08-16 08:20:07 +00:00
|
|
|
knowledge_base { nil }
|
2019-09-24 13:04:42 +00:00
|
|
|
end
|
|
|
|
|
2020-08-05 13:48:41 +00:00
|
|
|
category { create(:knowledge_base_category, { knowledge_base: knowledge_base }.compact) }
|
2019-09-18 17:25:04 +00:00
|
|
|
|
2020-02-19 17:07:52 +00:00
|
|
|
before(:create) do |answer, context|
|
2019-09-18 17:25:04 +00:00
|
|
|
next if answer.translations.present?
|
|
|
|
|
2020-09-23 14:10:50 +00:00
|
|
|
answer.translations << build('knowledge_base/answer/translation', *context.translation_traits, answer: answer, **context.translation_attributes)
|
2020-02-19 17:07:52 +00:00
|
|
|
end
|
|
|
|
|
2020-08-05 13:48:41 +00:00
|
|
|
trait :draft # empty placeholder for better readability
|
|
|
|
|
|
|
|
trait :internal do
|
|
|
|
internal_at { 1.week.ago }
|
|
|
|
end
|
|
|
|
|
|
|
|
trait :published do
|
|
|
|
published_at { 1.week.ago }
|
|
|
|
end
|
|
|
|
|
|
|
|
trait :archived do
|
|
|
|
archived_at { 1.week.ago }
|
|
|
|
end
|
|
|
|
|
2020-02-19 17:07:52 +00:00
|
|
|
trait :with_video do
|
|
|
|
transient do
|
|
|
|
translation_traits { [:with_video] }
|
|
|
|
end
|
2019-09-18 17:25:04 +00:00
|
|
|
end
|
2020-04-20 09:47:45 +00:00
|
|
|
|
2020-05-28 08:02:07 +00:00
|
|
|
trait :with_image do
|
|
|
|
transient do
|
|
|
|
translation_traits { [:with_image] }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-08-16 08:20:07 +00:00
|
|
|
trait :with_tag do
|
|
|
|
transient do
|
|
|
|
tag_names { %w[example_kb_tag] }
|
|
|
|
end
|
|
|
|
|
|
|
|
after(:create) do |answer, context|
|
|
|
|
context.tag_names.each { |tag| answer.tag_add tag }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-20 09:47:45 +00:00
|
|
|
trait :with_attachment do
|
|
|
|
transient do
|
|
|
|
attachment { File.open('spec/fixtures/upload/hello_world.txt') }
|
|
|
|
end
|
|
|
|
|
|
|
|
after(:create) do |answer, context|
|
|
|
|
Store.add(
|
|
|
|
object: answer.class.name,
|
|
|
|
o_id: answer.id,
|
|
|
|
data: context.attachment.read,
|
|
|
|
filename: File.basename(context.attachment.path),
|
|
|
|
preferences: {}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2019-06-04 03:40:48 +00:00
|
|
|
end
|
|
|
|
end
|