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
|
|
|
|
add_translation { true }
|
2020-02-19 17:07:52 +00:00
|
|
|
translation_traits { [] }
|
2019-09-24 13:04:42 +00:00
|
|
|
end
|
|
|
|
|
2019-06-04 03:40:48 +00:00
|
|
|
category { create(:knowledge_base_category) }
|
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-02-19 17:07:52 +00:00
|
|
|
answer.translations << build('knowledge_base/answer/translation', *context.translation_traits, answer: answer)
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
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
|