diff --git a/db/migrate/20180220171219_check_for_object_attributes.rb b/db/migrate/20180220171219_check_for_object_attributes.rb index 27b5a9b36..44767cd87 100644 --- a/db/migrate/20180220171219_check_for_object_attributes.rb +++ b/db/migrate/20180220171219_check_for_object_attributes.rb @@ -7,6 +7,7 @@ class CheckForObjectAttributes < ActiveRecord::Migration[5.1] fix_nil_data_option(attribute) fix_options(attribute) fix_relation(attribute) + fix_interger_missing_min_max(attribute) next if !attribute.changed? @@ -38,4 +39,12 @@ class CheckForObjectAttributes < ActiveRecord::Migration[5.1] attribute[:data_option][:relation] = '' end + + # fixes issue #2318 - Upgrade to Zammad 2.7 was not possible (migration 20180220171219 CheckForObjectAttributes failed) + def fix_interger_missing_min_max(attribute) + return if attribute[:data_type] != 'integer' + + attribute[:data_option][:min] = 0 if !attribute[:data_option][:min] + attribute[:data_option][:max] = 1_000_000 if !attribute[:data_option][:max] + end end diff --git a/spec/db/migrate/check_for_object_attributes_spec.rb b/spec/db/migrate/check_for_object_attributes_spec.rb index 7b60955b4..a4bb3c433 100644 --- a/spec/db/migrate/check_for_object_attributes_spec.rb +++ b/spec/db/migrate/check_for_object_attributes_spec.rb @@ -112,4 +112,19 @@ RSpec.describe CheckForObjectAttributes, type: :db_migration do end end end + + # 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) + attribute.update_columns(data_option: {}) # rubocop:disable Rails/SkipsModelValidations + + 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 end diff --git a/spec/factories/object_manager_attribute.rb b/spec/factories/object_manager_attribute.rb index 9f833edbf..3673adfd9 100644 --- a/spec/factories/object_manager_attribute.rb +++ b/spec/factories/object_manager_attribute.rb @@ -53,6 +53,17 @@ FactoryBot.define do end end + factory :object_manager_attribute_integer, parent: :object_manager_attribute do + data_type 'integer' + data_option do + { + 'default' => 0, + 'min' => 0, + 'max' => 9999, + } + end + end + factory :object_manager_attribute_date, parent: :object_manager_attribute do name 'date_attribute' data_type 'date'