translation.rb 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. FactoryBot.define do
  2. factory 'knowledge_base/answer/translation', aliases: %i[knowledge_base_answer_translation] do
  3. created_by_id { 1 }
  4. updated_by_id { 1 }
  5. answer { nil }
  6. kb_locale { nil }
  7. sequence(:title) { |n| "#{Faker::Appliance.equipment} ##{n}" }
  8. content { build(:knowledge_base_answer_translation_content) }
  9. before(:create) do |translation, _context|
  10. if translation.answer.nil?
  11. build(:knowledge_base_answer, translations: [translation])
  12. end
  13. if translation.kb_locale.nil?
  14. translation.kb_locale = translation.answer.category.knowledge_base.kb_locales.first
  15. end
  16. end
  17. after(:build) do |translation, _context|
  18. if translation.answer.nil?
  19. build(:knowledge_base_answer, translations: [translation])
  20. end
  21. if translation.kb_locale.nil?
  22. translation.kb_locale = translation.answer.category.knowledge_base.kb_locales.first
  23. end
  24. end
  25. trait :with_video do
  26. content { build(:knowledge_base_answer_translation_content, :with_video) }
  27. end
  28. trait :with_image do
  29. content { build(:knowledge_base_answer_translation_content, :with_image) }
  30. end
  31. end
  32. end