issue_4316_template_options_migration_spec.rb 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Issue4316TemplateOptionsMigration, type: :db_migration do
  4. let(:expected) do
  5. {
  6. 'article.body' => { value: 'twet 23123' },
  7. 'ticket.formSenderType' => { value: 'phone-in' },
  8. 'ticket.title' => { value: 'aaa' },
  9. 'ticket.customer_id' => { value: '2', value_completion: 'Nicole Braun <nicole.braun@example.com>' },
  10. 'ticket.cc' => { value: 'somebody2@example.com' },
  11. 'ticket.group_id' => { value: '1' },
  12. 'ticket.owner_id' => { value: '11' },
  13. 'ticket.state_id' => { value: '2' },
  14. 'ticket.priority_id' => { value: '2' },
  15. 'ticket.a1' => { value: 'a' },
  16. 'ticket.a2' => { value: %w[a b] },
  17. 'ticket.b1' => { value: 'a::c' },
  18. 'ticket.b2' => { value: ['b'], value_completion: '' },
  19. 'ticket.category' => { value: 'a::aa' },
  20. 'ticket.tags' => { value: 'aa, bb' },
  21. }
  22. end
  23. let(:template) do
  24. # Wrong format after initial migration from 5.2 to 5.3.
  25. Template.create!(
  26. name: 'new',
  27. options:
  28. {
  29. 'article.body' => 'twet 23123',
  30. 'ticket.formSenderType' => 'phone-in',
  31. 'ticket.title' => 'aaa',
  32. 'ticket.customer_id' => '2',
  33. 'ticket.customer_id_completion' => 'Nicole Braun <nicole.braun@example.com>',
  34. 'ticket.cc' => 'somebody2@example.com',
  35. 'ticket.group_id' => '1',
  36. 'ticket.owner_id' => '11',
  37. 'ticket.state_id' => '2',
  38. 'ticket.priority_id' => '2',
  39. 'ticket.a1' => 'a',
  40. 'ticket.a2' => %w[a b],
  41. 'ticket.b1' => 'a::c',
  42. 'ticket.b2' => ['b'],
  43. 'ticket.b2_completion' => '',
  44. 'ticket.category' => 'a::aa',
  45. 'ticket.tags' => 'aa, bb'
  46. },
  47. updated_by_id: 1,
  48. created_by_id: 1,
  49. )
  50. end
  51. before do
  52. template
  53. end
  54. context 'when migrating' do
  55. it 'update options to expected hash value (#4316)' do
  56. migrate
  57. expect(template.reload.options).to eq(expected.deep_stringify_keys)
  58. end
  59. end
  60. end