Follow up - Fixed issue #1838 - Follow up issue #1752: Unable to migrate old object manager attribute fields.

This commit is contained in:
Thorsten Eckel 2018-03-29 13:46:15 +02:00
parent a088321498
commit 2eaae8e5c4
4 changed files with 127 additions and 2 deletions

View file

@ -127,7 +127,8 @@ class ObjectManagerAttributesController < ApplicationController
permitted[:data_option][:null] = true
end
if !permitted[:data_option][:options].is_a?(Hash) && !permitted[:data_option][:options].is_a?(Array)
if !permitted[:data_option][:options].is_a?(Hash) &&
!permitted[:data_option][:options].is_a?(Array)
permitted[:data_option][:options] = {}
end

View file

@ -26,7 +26,8 @@ class CheckForObjectAttributes < ActiveRecord::Migration[5.1]
end
def fix_options(attribute)
return if attribute[:data_option][:options].is_a?(Hash) || attribute[:data_option][:options].is_a?(Array)
return if attribute[:data_option][:options].is_a?(Hash)
return if attribute[:data_option][:options].is_a?(Array)
attribute[:data_option][:options] = {}
end

View file

@ -35,6 +35,18 @@ RSpec.describe CheckForObjectAttributes, type: :db_migration do
attribute.reload.data_option
}
end
it 'does not change tree_select attribute' do
system_init_done
attribute = create(:object_manager_attribute_tree_select)
expect do
migrate
end.not_to change {
attribute.reload.data_option
}
end
end
context '[:data_option]' do

View file

@ -72,4 +72,115 @@ FactoryBot.define do
}
end
end
factory :object_manager_attribute_tree_select, parent: :object_manager_attribute do
data_type 'tree_select'
data_option do
{
'options' => [
{
'name' => 'Incident',
'value' => 'Incident',
'children' => [
{
'name' => 'Hardware',
'value' => 'Incident::Hardware',
'children' => [
{
'name' => 'Monitor',
'value' => 'Incident::Hardware::Monitor'
},
{
'name' => 'Mouse',
'value' => 'Incident::Hardware::Mouse'
},
{
'name' => 'Keyboard',
'value' => 'Incident::Hardware::Keyboard'
}
]
},
{
'name' => 'Softwareproblem',
'value' => 'Incident::Softwareproblem',
'children' => [
{
'name' => 'CRM',
'value' => 'Incident::Softwareproblem::CRM'
},
{
'name' => 'EDI',
'value' => 'Incident::Softwareproblem::EDI'
},
{
'name' => 'SAP',
'value' => 'Incident::Softwareproblem::SAP',
'children' => [
{
'name' => 'Authentication',
'value' => 'Incident::Softwareproblem::SAP::Authentication'
},
{
'name' => 'Not reachable',
'value' => 'Incident::Softwareproblem::SAP::Not reachable'
}
]
},
{
'name' => 'MS Office',
'value' => 'Incident::Softwareproblem::MS Office',
'children' => [
{
'name' => 'Excel',
'value' => 'Incident::Softwareproblem::MS Office::Excel'
},
{
'name' => 'PowerPoint',
'value' => 'Incident::Softwareproblem::MS Office::PowerPoint'
},
{
'name' => 'Word',
'value' => 'Incident::Softwareproblem::MS Office::Word'
},
{
'name' => 'Outlook',
'value' => 'Incident::Softwareproblem::MS Office::Outlook'
}
]
}
]
}
]
},
{
'name' => 'Service request',
'value' => 'Service request',
'children' => [
{
'name' => 'New software requirement',
'value' => 'Service request::New software requirement'
},
{
'name' => 'New hardware',
'value' => 'Service request::New hardware'
},
{
'name' => 'Consulting',
'value' => 'Service request::Consulting'
}
]
},
{
'name' => 'Change request',
'value' => 'Change request'
}
],
'default' => '',
'null' => true,
'relation' => '',
'maxlength' => 255,
'nulloption' => true,
}
end
end
end