Browse Source

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

Thorsten Eckel 7 years ago
parent
commit
2eaae8e5c4

+ 2 - 1
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
 

+ 2 - 1
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
 

+ 12 - 0
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

+ 111 - 0
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