diff --git a/app/controllers/object_manager_attributes_controller.rb b/app/controllers/object_manager_attributes_controller.rb index ab55ba001..02f702129 100644 --- a/app/controllers/object_manager_attributes_controller.rb +++ b/app/controllers/object_manager_attributes_controller.rb @@ -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 diff --git a/db/migrate/20180220171219_check_for_object_attributes.rb b/db/migrate/20180220171219_check_for_object_attributes.rb index 6b76a6a3d..d5988b903 100644 --- a/db/migrate/20180220171219_check_for_object_attributes.rb +++ b/db/migrate/20180220171219_check_for_object_attributes.rb @@ -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 diff --git a/spec/db/migrate/check_for_object_attributes_spec.rb b/spec/db/migrate/check_for_object_attributes_spec.rb index 45cd23889..dd5dc6dfc 100644 --- a/spec/db/migrate/check_for_object_attributes_spec.rb +++ b/spec/db/migrate/check_for_object_attributes_spec.rb @@ -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 diff --git a/spec/factories/object_manager_attribute.rb b/spec/factories/object_manager_attribute.rb index 0a644dcae..92ef0992a 100644 --- a/spec/factories/object_manager_attribute.rb +++ b/spec/factories/object_manager_attribute.rb @@ -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