2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2018-03-23 14:26:09 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe CheckForObjectAttributes, type: :db_migration do
|
|
|
|
|
2018-03-28 09:46:39 +00:00
|
|
|
it 'performs no action for new systems', system_init_done: false do
|
2018-03-23 14:26:09 +00:00
|
|
|
migrate do |instance|
|
|
|
|
expect(instance).not_to receive(:attributes)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-08-24 01:39:17 +00:00
|
|
|
context 'with a valid #data_option hash' do
|
2018-03-23 14:26:09 +00:00
|
|
|
|
|
|
|
it 'does not change converted text attribute' do
|
|
|
|
attribute = create(:object_manager_attribute_text)
|
|
|
|
|
2018-08-24 01:39:17 +00:00
|
|
|
expect { migrate }
|
|
|
|
.not_to change { attribute.reload.data_option }
|
2018-03-23 14:26:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not change select attribute' do
|
|
|
|
attribute = create(:object_manager_attribute_select)
|
|
|
|
|
2018-08-24 01:39:17 +00:00
|
|
|
expect { migrate }
|
|
|
|
.not_to change { attribute.reload.data_option }
|
2018-03-23 14:26:09 +00:00
|
|
|
end
|
2018-03-29 11:46:15 +00:00
|
|
|
|
|
|
|
it 'does not change tree_select attribute' do
|
|
|
|
attribute = create(:object_manager_attribute_tree_select)
|
|
|
|
|
2018-08-24 01:39:17 +00:00
|
|
|
expect { migrate }
|
|
|
|
.not_to change { attribute.reload.data_option }
|
2018-03-29 11:46:15 +00:00
|
|
|
end
|
2022-01-20 10:07:12 +00:00
|
|
|
|
|
|
|
it 'does not change multiselect attribute' do
|
|
|
|
attribute = create(:object_manager_attribute_multiselect)
|
|
|
|
|
|
|
|
expect { migrate }
|
|
|
|
.not_to change { attribute.reload.data_option }
|
|
|
|
end
|
2018-03-23 14:26:09 +00:00
|
|
|
end
|
|
|
|
|
2018-08-24 01:39:17 +00:00
|
|
|
context 'for #data_option key:' do
|
|
|
|
context ':options' do
|
2018-03-23 14:26:09 +00:00
|
|
|
|
2018-08-24 01:39:17 +00:00
|
|
|
it 'converts String to Hash' do
|
|
|
|
wrong = {
|
|
|
|
default: '',
|
|
|
|
options: '',
|
|
|
|
relation: '',
|
|
|
|
type: 'text',
|
|
|
|
maxlength: 255,
|
|
|
|
null: true
|
|
|
|
}
|
2018-03-23 14:26:09 +00:00
|
|
|
|
2018-08-24 01:39:17 +00:00
|
|
|
attribute = create(:object_manager_attribute_text, data_option: wrong)
|
|
|
|
migrate
|
|
|
|
attribute.reload
|
2018-03-23 14:26:09 +00:00
|
|
|
|
2018-08-24 01:39:17 +00:00
|
|
|
expect(attribute[:data_option][:options]).to be_a(Hash)
|
|
|
|
expect(attribute[:data_option][:options]).to be_blank
|
|
|
|
end
|
2018-03-23 14:26:09 +00:00
|
|
|
end
|
|
|
|
|
2018-08-24 01:39:17 +00:00
|
|
|
context ':relation' do
|
2018-03-23 14:26:09 +00:00
|
|
|
|
2018-08-24 01:39:17 +00:00
|
|
|
it 'ensures an empty String' do
|
|
|
|
wrong = {
|
|
|
|
default: '',
|
|
|
|
options: {},
|
|
|
|
type: 'text',
|
|
|
|
maxlength: 255,
|
|
|
|
null: true
|
|
|
|
}
|
2018-03-23 14:26:09 +00:00
|
|
|
|
2018-08-24 01:39:17 +00:00
|
|
|
attribute = create(:object_manager_attribute_text, data_option: wrong)
|
|
|
|
migrate
|
|
|
|
attribute.reload
|
|
|
|
|
|
|
|
expect(attribute[:data_option][:relation]).to be_a(String)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'converts Hash to String' do
|
|
|
|
wrong = {
|
|
|
|
default: '',
|
|
|
|
options: {},
|
|
|
|
relation: {},
|
|
|
|
type: 'text',
|
|
|
|
maxlength: 255,
|
|
|
|
null: true
|
|
|
|
}
|
|
|
|
|
|
|
|
attribute = create(:object_manager_attribute_text, data_option: wrong)
|
|
|
|
migrate
|
|
|
|
attribute.reload
|
2018-03-23 14:26:09 +00:00
|
|
|
|
2018-08-24 01:39:17 +00:00
|
|
|
expect(attribute[:data_option][:relation]).to be_a(String)
|
|
|
|
expect(attribute[:data_option][:relation]).to be_blank
|
|
|
|
end
|
2018-03-23 14:26:09 +00:00
|
|
|
end
|
|
|
|
|
2018-08-24 01:39:17 +00:00
|
|
|
# see https://github.com/zammad/zammad/issues/2159
|
|
|
|
context ':null' do
|
|
|
|
|
|
|
|
it 'does not fail on missing values' do
|
|
|
|
wrong = {
|
|
|
|
default: '',
|
|
|
|
options: '', # <- this is not the attribute under test,
|
|
|
|
relation: '', # but it must be invalid
|
|
|
|
type: 'text', # to trigger a #save in the migration.
|
|
|
|
maxlength: 255,
|
|
|
|
}
|
|
|
|
create(:object_manager_attribute_text)
|
|
|
|
.update_columns(data_option: wrong)
|
|
|
|
|
|
|
|
expect { migrate }.not_to raise_error
|
|
|
|
end
|
2018-03-23 14:26:09 +00:00
|
|
|
end
|
|
|
|
end
|
2018-10-31 13:14:26 +00:00
|
|
|
|
|
|
|
# regression test for issue #2318 - Upgrade to Zammad 2.7 was not possible (migration 20180220171219 CheckForObjectAttributes failed)
|
|
|
|
context 'for interger attributes' do
|
|
|
|
it 'missing :min and :max' do
|
|
|
|
attribute = create(:object_manager_attribute_integer)
|
2019-01-15 12:17:13 +00:00
|
|
|
attribute.update_columns(data_option: {})
|
2018-10-31 13:14:26 +00:00
|
|
|
|
|
|
|
expect { migrate }.not_to raise_error
|
|
|
|
|
|
|
|
attribute.reload
|
|
|
|
|
|
|
|
expect(attribute[:data_option][:min]).to be_a(Integer)
|
|
|
|
expect(attribute[:data_option][:max]).to be_a(Integer)
|
|
|
|
end
|
|
|
|
end
|
2018-03-23 14:26:09 +00:00
|
|
|
end
|