123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- require 'rails_helper'
- RSpec.describe Issue1660FixTreeSelectConfigurations, type: :db_migration do
- it 'corrects broken data_option options' do
- # as provided in issue #1775
- expected = [
- {
- 'name' => 'Blaak',
- 'value' => 'Blaak',
- 'children' => [
- {
- 'name' => 'BL.-1',
- 'value' => 'Blaak::BL.-1',
- 'children' => [
- {
- 'name' => 'BL.-1.3',
- 'value' => 'Blaak::BL.-1::BL.-1.3',
- },
- {
- 'name' => 'BL.-1.19',
- 'value' => 'Blaak::BL.-1::BL.-1.19',
- }
- ]
- },
- {
- 'name' => 'BL.0',
- 'value' => 'Blaak::BL.0',
- 'children' => [
- {
- 'name' => 'BL.00.10a',
- 'value' => 'Blaak::BL.0::BL.00.10a',
- },
- {
- 'name' => 'BL.00.7',
- 'value' => 'Blaak::BL.0::BL.00.7',
- },
- {
- 'name' => 'BL.01.18',
- 'value' => 'Blaak::BL.0::BL.01.18',
- },
- {
- 'name' => 'BL.00.12',
- 'value' => 'Blaak::BL.0::BL.00.12',
- },
- {
- 'name' => 'BL.e0.3',
- 'value' => 'Blaak::BL.0::BL.e0.3',
- },
- ]
- },
- {
- 'name' => 'BL.1',
- 'value' => 'Blaak::BL.1',
- 'children' => [
- {
- 'name' => 'BL.01.i',
- 'value' => 'Blaak::BL.1::BL.01.i',
- },
- ]
- },
- {
- 'name' => 'BL.2',
- 'value' => 'Blaak::BL.2',
- 'children' => [
- {
- 'name' => 'BL.02.2',
- 'value' => 'Blaak::BL.2::BL.02.2',
- },
- {
- 'name' => 'BL.02.4',
- 'value' => 'Blaak::BL.2::BL.02.4',
- },
- {
- 'name' => 'BL.02.5',
- 'value' => 'Blaak::BL.2::BL.02.5',
- },
- {
- 'name' => 'BL.02.6',
- 'value' => 'Blaak::BL.2::BL.02.6',
- },
- {
- 'name' => 'BL.02.7',
- 'value' => 'Blaak::BL.2::BL.02.7',
- },
- ]
- },
- ],
- }
- ]
- broken = [
- {
- 'name' => 'Blaak',
- 'value' => 'Blaak',
- 'children' => [
- {
- 'name' => 'BL.-1',
- 'value' => 'Blaak::BL.-1',
- 'children' => [
- {
- 'name' => 'BL.-1.3',
- 'value' => 'Blaak::BL.2::BL.-1.3',
- },
- {
- 'name' => 'BL.-1.19',
- 'value' => 'Blaak::BL.2::BL.-1.19',
- }
- ]
- },
- {
- 'name' => 'BL.0',
- 'value' => 'Blaak::BL.0',
- 'children' => [
- {
- 'name' => 'BL.00.10a',
- 'value' => 'Blaak::BL.2::BL.00.10a',
- },
- {
- 'name' => 'BL.00.7',
- 'value' => 'Blaak::BL.2::BL.00.7',
- },
- {
- 'name' => 'BL.01.18',
- 'value' => 'Blaak::BL.2::BL.01.18',
- },
- {
- 'name' => 'BL.00.12',
- 'value' => 'Blaak::BL.2::BL.00.12',
- },
- {
- 'name' => 'BL.e0.3',
- 'value' => 'Blaak::BL.2::BL.e0.3',
- },
- ]
- },
- {
- 'name' => 'BL.1',
- 'value' => 'Blaak::BL.1',
- 'children' => [
- {
- 'name' => 'BL.01.i',
- 'value' => 'Blaak::BL.2::BL.01.i',
- },
- ]
- },
- {
- 'name' => 'BL.2',
- 'value' => 'Blaak::BL.2',
- 'children' => [
- {
- 'name' => 'BL.02.2',
- 'value' => 'Blaak::BL.2::BL.02.2',
- },
- {
- 'name' => 'BL.02.4',
- 'value' => 'Blaak::BL.2::BL.02.4',
- },
- {
- 'name' => 'BL.02.5',
- 'value' => 'Blaak::BL.2::BL.02.5',
- },
- {
- 'name' => 'BL.02.6',
- 'value' => 'Blaak::BL.2::BL.02.6',
- },
- {
- 'name' => 'BL.02.7',
- 'value' => 'Blaak::BL.2::BL.02.7',
- },
- ]
- },
- ],
- }
- ]
- attribute = create(:object_manager_attribute_tree_select, data_option: { options: broken, null: true, default: '' })
- expect do
- migrate
- end.to change {
- attribute.reload.data_option[:options]
- }
- expect(attribute.data_option[:options]).to eq(expected)
- end
- it 'performs no action for new systems', system_init_done: false do
- migrate do |instance|
- expect(instance).not_to receive(:attributes)
- end
- end
- it 'skips blank data_option options' do
- attribute = create(:object_manager_attribute_tree_select, data_option: { options: [], null: true, default: '' })
- expect do
- migrate
- end.not_to change {
- attribute.reload.data_option[:options]
- }
- end
- it 'does not change correct data_option options' do
- attribute = create(:object_manager_attribute_tree_select)
- expect do
- migrate
- end.not_to change {
- attribute.reload.data_option[:options]
- }
- end
- end
|