issue_4266_fix_field_spec.rb 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Issue4266FixField, type: :db_migration do
  4. context 'when config is migrated' do
  5. before do
  6. Setting.find_by(name: 'customer_ticket_create_group_ids').destroy
  7. Setting.create_if_not_exists(
  8. title: 'Group selection for Ticket creation',
  9. name: 'customer_ticket_create_group_ids',
  10. area: 'CustomerWeb::Base',
  11. description: 'Defines groups for which a customer can create tickets via web interface. "-" means all groups are available.',
  12. options: {
  13. form: [
  14. {
  15. display: '',
  16. null: true,
  17. name: 'group_ids',
  18. tag: 'select',
  19. multiple: true,
  20. nulloption: true,
  21. relation: 'Group',
  22. },
  23. ],
  24. },
  25. state: '',
  26. preferences: {
  27. authentication: true,
  28. permission: ['admin.channel_web'],
  29. },
  30. frontend: true
  31. )
  32. migrate
  33. end
  34. it 'does change the config properly', :aggregate_failures do
  35. setting = Setting.find_by(name: 'customer_ticket_create_group_ids')
  36. expect(setting.options['form'][0]['tag']).to eq('multiselect')
  37. expect(setting.options['form'][0]['nulloption']).to be_nil
  38. end
  39. end
  40. context 'when value is correct' do
  41. let(:setting_value) { [Group.first.id] }
  42. before do
  43. Setting.set('customer_ticket_create_group_ids', setting_value)
  44. migrate
  45. end
  46. it 'does not change the value' do
  47. expect(Setting.get('customer_ticket_create_group_ids')).to eq(setting_value)
  48. end
  49. end
  50. context 'when value is an empty string' do
  51. let(:setting_value) { '' }
  52. before do
  53. Setting.set('customer_ticket_create_group_ids', setting_value)
  54. migrate
  55. end
  56. it 'does change to value to nil' do
  57. expect(Setting.get('customer_ticket_create_group_ids')).to be_nil
  58. end
  59. end
  60. context 'when value is an empty array string' do
  61. let(:setting_value) { [''] }
  62. before do
  63. Setting.set('customer_ticket_create_group_ids', setting_value)
  64. migrate
  65. end
  66. it 'does change to value to nil' do
  67. expect(Setting.get('customer_ticket_create_group_ids')).to be_nil
  68. end
  69. end
  70. end