Fix #2318 - migration 20180220171219 CheckForObjectAttributes failed

This commit is contained in:
Billy Zhou 2018-10-31 21:14:26 +08:00 committed by Martin Edenhofer
parent 4c90a87f5b
commit f711e1019e
3 changed files with 35 additions and 0 deletions

View file

@ -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

View file

@ -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

View file

@ -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'