From 153032e82fa11bb3bdc53fa37cc26152c1584be5 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Thu, 28 Mar 2019 15:03:55 +0100 Subject: [PATCH] Follow up - 444e48e3772eb4abf8fb00170dca3d08ad65955f - Obsolete ObjectManager::Attribute data_option missing :diff option fails migration. --- ...nager_attribute_date_remove_future_past.rb | 6 +++++ ..._attribute_date_remove_future_past_spec.rb | 24 +++++++++++++++++++ 2 files changed, 30 insertions(+) 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