issue_1660_fix_tree_select_configurations_spec.rb 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Issue1660FixTreeSelectConfigurations, type: :db_migration do
  4. it 'corrects broken data_option options' do
  5. # as provided in issue #1775
  6. expected = [
  7. {
  8. 'name' => 'Blaak',
  9. 'value' => 'Blaak',
  10. 'children' => [
  11. {
  12. 'name' => 'BL.-1',
  13. 'value' => 'Blaak::BL.-1',
  14. 'children' => [
  15. {
  16. 'name' => 'BL.-1.3',
  17. 'value' => 'Blaak::BL.-1::BL.-1.3',
  18. },
  19. {
  20. 'name' => 'BL.-1.19',
  21. 'value' => 'Blaak::BL.-1::BL.-1.19',
  22. }
  23. ]
  24. },
  25. {
  26. 'name' => 'BL.0',
  27. 'value' => 'Blaak::BL.0',
  28. 'children' => [
  29. {
  30. 'name' => 'BL.00.10a',
  31. 'value' => 'Blaak::BL.0::BL.00.10a',
  32. },
  33. {
  34. 'name' => 'BL.00.7',
  35. 'value' => 'Blaak::BL.0::BL.00.7',
  36. },
  37. {
  38. 'name' => 'BL.01.18',
  39. 'value' => 'Blaak::BL.0::BL.01.18',
  40. },
  41. {
  42. 'name' => 'BL.00.12',
  43. 'value' => 'Blaak::BL.0::BL.00.12',
  44. },
  45. {
  46. 'name' => 'BL.e0.3',
  47. 'value' => 'Blaak::BL.0::BL.e0.3',
  48. },
  49. ]
  50. },
  51. {
  52. 'name' => 'BL.1',
  53. 'value' => 'Blaak::BL.1',
  54. 'children' => [
  55. {
  56. 'name' => 'BL.01.i',
  57. 'value' => 'Blaak::BL.1::BL.01.i',
  58. },
  59. ]
  60. },
  61. {
  62. 'name' => 'BL.2',
  63. 'value' => 'Blaak::BL.2',
  64. 'children' => [
  65. {
  66. 'name' => 'BL.02.2',
  67. 'value' => 'Blaak::BL.2::BL.02.2',
  68. },
  69. {
  70. 'name' => 'BL.02.4',
  71. 'value' => 'Blaak::BL.2::BL.02.4',
  72. },
  73. {
  74. 'name' => 'BL.02.5',
  75. 'value' => 'Blaak::BL.2::BL.02.5',
  76. },
  77. {
  78. 'name' => 'BL.02.6',
  79. 'value' => 'Blaak::BL.2::BL.02.6',
  80. },
  81. {
  82. 'name' => 'BL.02.7',
  83. 'value' => 'Blaak::BL.2::BL.02.7',
  84. },
  85. ]
  86. },
  87. ],
  88. }
  89. ]
  90. broken = [
  91. {
  92. 'name' => 'Blaak',
  93. 'value' => 'Blaak',
  94. 'children' => [
  95. {
  96. 'name' => 'BL.-1',
  97. 'value' => 'Blaak::BL.-1',
  98. 'children' => [
  99. {
  100. 'name' => 'BL.-1.3',
  101. 'value' => 'Blaak::BL.2::BL.-1.3',
  102. },
  103. {
  104. 'name' => 'BL.-1.19',
  105. 'value' => 'Blaak::BL.2::BL.-1.19',
  106. }
  107. ]
  108. },
  109. {
  110. 'name' => 'BL.0',
  111. 'value' => 'Blaak::BL.0',
  112. 'children' => [
  113. {
  114. 'name' => 'BL.00.10a',
  115. 'value' => 'Blaak::BL.2::BL.00.10a',
  116. },
  117. {
  118. 'name' => 'BL.00.7',
  119. 'value' => 'Blaak::BL.2::BL.00.7',
  120. },
  121. {
  122. 'name' => 'BL.01.18',
  123. 'value' => 'Blaak::BL.2::BL.01.18',
  124. },
  125. {
  126. 'name' => 'BL.00.12',
  127. 'value' => 'Blaak::BL.2::BL.00.12',
  128. },
  129. {
  130. 'name' => 'BL.e0.3',
  131. 'value' => 'Blaak::BL.2::BL.e0.3',
  132. },
  133. ]
  134. },
  135. {
  136. 'name' => 'BL.1',
  137. 'value' => 'Blaak::BL.1',
  138. 'children' => [
  139. {
  140. 'name' => 'BL.01.i',
  141. 'value' => 'Blaak::BL.2::BL.01.i',
  142. },
  143. ]
  144. },
  145. {
  146. 'name' => 'BL.2',
  147. 'value' => 'Blaak::BL.2',
  148. 'children' => [
  149. {
  150. 'name' => 'BL.02.2',
  151. 'value' => 'Blaak::BL.2::BL.02.2',
  152. },
  153. {
  154. 'name' => 'BL.02.4',
  155. 'value' => 'Blaak::BL.2::BL.02.4',
  156. },
  157. {
  158. 'name' => 'BL.02.5',
  159. 'value' => 'Blaak::BL.2::BL.02.5',
  160. },
  161. {
  162. 'name' => 'BL.02.6',
  163. 'value' => 'Blaak::BL.2::BL.02.6',
  164. },
  165. {
  166. 'name' => 'BL.02.7',
  167. 'value' => 'Blaak::BL.2::BL.02.7',
  168. },
  169. ]
  170. },
  171. ],
  172. }
  173. ]
  174. attribute = create(:object_manager_attribute_tree_select, data_option: { options: broken, null: true, default: '' })
  175. expect do
  176. migrate
  177. end.to change {
  178. attribute.reload.data_option[:options]
  179. }
  180. expect(attribute.data_option[:options]).to eq(expected)
  181. end
  182. it 'performs no action for new systems', system_init_done: false do
  183. migrate do |instance|
  184. expect(instance).not_to receive(:attributes)
  185. end
  186. end
  187. it 'skips blank data_option options' do
  188. attribute = create(:object_manager_attribute_tree_select, data_option: { options: [], null: true, default: '' })
  189. expect do
  190. migrate
  191. end.not_to change {
  192. attribute.reload.data_option[:options]
  193. }
  194. end
  195. it 'does not change correct data_option options' do
  196. attribute = create(:object_manager_attribute_tree_select)
  197. expect do
  198. migrate
  199. end.not_to change {
  200. attribute.reload.data_option[:options]
  201. }
  202. end
  203. end