answer.rb 998 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. FactoryBot.define do
  2. factory 'knowledge_base/answer', aliases: %i[knowledge_base_answer] do
  3. transient do
  4. add_translation { true }
  5. translation_traits { [] }
  6. end
  7. category { create(:knowledge_base_category) }
  8. before(:create) do |answer, context|
  9. next if answer.translations.present?
  10. answer.translations << build('knowledge_base/answer/translation', *context.translation_traits, answer: answer)
  11. end
  12. trait :with_video do
  13. transient do
  14. translation_traits { [:with_video] }
  15. end
  16. end
  17. trait :with_attachment do
  18. transient do
  19. attachment { File.open('spec/fixtures/upload/hello_world.txt') }
  20. end
  21. after(:create) do |answer, context|
  22. Store.add(
  23. object: answer.class.name,
  24. o_id: answer.id,
  25. data: context.attachment.read,
  26. filename: File.basename(context.attachment.path),
  27. preferences: {}
  28. )
  29. end
  30. end
  31. end
  32. end