upsert_spec.rb 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Service::Translation::Upsert, current_user_id: 1 do
  4. describe '#execute' do
  5. let(:locale) { 'de-de' }
  6. let(:translation_upsert_service) { described_class.new(locale:, source:, target:) }
  7. context 'when translation record already exists' do
  8. let(:source) { 'New' }
  9. let(:target) { 'Neu2' }
  10. it 'use existing record' do
  11. translation_for_new = Translation.find_source('de-de', 'New')
  12. expect { translation_upsert_service.execute }.to change { translation_for_new.reload.target }.to(target)
  13. end
  14. end
  15. context 'when translation record does not exist', :aggregate_failures do
  16. let(:source) { SecureRandom.uuid }
  17. let(:target) { 'Other' }
  18. it 'create new record' do
  19. expect { translation_upsert_service.execute }.to change(Translation, :count).by(1)
  20. expect(Translation.last).to have_attributes(locale:, source:, target:, target_initial: target, is_synchronized_from_codebase: false)
  21. end
  22. end
  23. end
  24. end