trabajo-afectivo/spec/factories/knowledge_base/answer.rb

60 lines
1.4 KiB
Ruby
Raw Normal View History

2019-06-04 03:40:48 +00:00
FactoryBot.define do
factory 'knowledge_base/answer', aliases: %i[knowledge_base_answer] do
transient do
add_translation { true }
translation_traits { [] }
knowledge_base { nil }
end
category { create(:knowledge_base_category, { knowledge_base: knowledge_base }.compact) }
before(:create) do |answer, context|
next if answer.translations.present?
answer.translations << build('knowledge_base/answer/translation', *context.translation_traits, answer: answer)
end
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
trait :with_video do
transient do
translation_traits { [:with_video] }
end
end
trait :with_image do
transient do
translation_traits { [:with_image] }
end
end
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