translation.rb 989 B

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