translation.rb 1.3 KB

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