translation.rb 912 B

123456789101112131415161718192021222324252627282930
  1. FactoryBot.define do
  2. factory 'knowledge_base/category/translation', aliases: %i[knowledge_base_category_translation] do
  3. transient do
  4. knowledge_base { nil }
  5. parent_category { nil }
  6. end
  7. category { nil }
  8. kb_locale { nil }
  9. sequence(:title) { |n| "#{Faker::Appliance.brand} ##{n}" }
  10. before(:create) do |translation, context|
  11. if translation.category.nil?
  12. attrs = if context.parent_category
  13. { parent: context.parent_category }
  14. elsif context.knowledge_base
  15. { knowledge_base: context.knowledge_base }
  16. else
  17. {}
  18. end
  19. attrs[:translations] = [translation]
  20. build(:knowledge_base_category, attrs)
  21. end
  22. translation.kb_locale = translation.category.knowledge_base.kb_locales.first if translation.kb_locale.nil?
  23. end
  24. end
  25. end