issue_1660_fix_tree_select_configurations_spec.rb 5.6 KB

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