diff --git a/db/migrate/20190314084909_object_manager_attribute_date_remove_future_past.rb b/db/migrate/20190314084909_object_manager_attribute_date_remove_future_past.rb index 47df6274a..8e3a4e07a 100644 --- a/db/migrate/20190314084909_object_manager_attribute_date_remove_future_past.rb +++ b/db/migrate/20190314084909_object_manager_attribute_date_remove_future_past.rb @@ -6,6 +6,12 @@ class ObjectManagerAttributeDateRemoveFuturePast < ActiveRecord::Migration[5.1] ObjectManager::Attribute.where(data_type: 'date').each do |attribute| attribute.data_option = attribute.data_option.except(:future, :past) + + # some attributes from the early Zammad days don't have all + # required data_option attributes because they were not properly migrated + # so we need to fix them now + attribute.data_option[:diff] ||= 24 + attribute.save! end end diff --git a/spec/db/migrate/object_manager_attribute_date_remove_future_past_spec.rb b/spec/db/migrate/object_manager_attribute_date_remove_future_past_spec.rb index 779e4ceac..f6a9cdde8 100644 --- a/spec/db/migrate/object_manager_attribute_date_remove_future_past_spec.rb +++ b/spec/db/migrate/object_manager_attribute_date_remove_future_past_spec.rb @@ -21,5 +21,29 @@ RSpec.describe ObjectManagerAttributeDateRemoveFuturePast, type: :db_migration d expect(subject.data_option).to_not include(:past, :future) end + + context 'when incomplete data_option is given' do + + it 'adds missing :diff option' do + subject = build(:object_manager_attribute_date) + + # add data_options manually because the factory doesn't contain them anymore + subject.data_option = subject.data_option.merge( + future: false, + past: false, + ) + + # remove diff option as for some attributes + # from older Zammad installations + subject.data_option.delete(:diff) + + # mock interfaces to save time + # otherwise we would have to reseed the database + expect(ObjectManager::Attribute).to receive(:where).and_return([subject]) + # expect(subject).to receive(:save!) + + expect { migrate }.not_to raise_error + end + end end end