migrate_template_options_spec.rb 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe MigrateTemplateOptions, type: :db_migration do
  4. let!(:template) { create(:template) }
  5. context 'with new options' do
  6. it 'keeps new options unchanged' do
  7. expect { migrate }.not_to change(template, :options)
  8. end
  9. end
  10. context 'with old options' do
  11. let!(:template) { create(:template, options: old_options) }
  12. let(:customer) { create(:customer) }
  13. let(:old_options) do
  14. {
  15. title: 'Bar',
  16. customer_id: customer.id.to_s,
  17. customer_id_completion: "#{customer.firstname} #{customer.lastname} <#{customer.email}>",
  18. body: 'abc'
  19. }
  20. end
  21. let(:new_options) do
  22. {
  23. 'ticket.title' => { 'value' => 'Bar' },
  24. 'ticket.customer_id' => {
  25. 'value' => customer.id.to_s,
  26. 'value_completion' => "#{customer.firstname} #{customer.lastname} <#{customer.email}>",
  27. },
  28. 'article.body' => { 'value' => 'abc' }
  29. }
  30. end
  31. it 'migrates them' do
  32. expect { migrate }.to change { template.reload.options }.from(old_options).to(new_options)
  33. end
  34. end
  35. end