diff --git a/db/migrate/20220517065751_issue4086_fix_historical_options.rb b/db/migrate/20220517065751_issue4086_fix_historical_options.rb new file mode 100644 index 000000000..65a3dac13 --- /dev/null +++ b/db/migrate/20220517065751_issue4086_fix_historical_options.rb @@ -0,0 +1,15 @@ +# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/ + +class Issue4086FixHistoricalOptions < ActiveRecord::Migration[5.0] + def change + # return if it's a new setup + return if !Setting.exists?(name: 'system_init_done') + + ObjectManager::Attribute.find_each do |attribute| + next if !%r{^(multi|tree_)?select$}.match?(attribute.data_type) + + attribute.data_option[:historical_options] = ObjectManager::Attribute.data_options_hash(attribute.data_option[:historical_options] || {}) + attribute.save + end + end +end diff --git a/spec/db/migrate/issue_4086_fix_historical_options_spec.rb b/spec/db/migrate/issue_4086_fix_historical_options_spec.rb new file mode 100644 index 000000000..03f5bd459 --- /dev/null +++ b/spec/db/migrate/issue_4086_fix_historical_options_spec.rb @@ -0,0 +1,33 @@ +# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/ + +require 'rails_helper' + +RSpec.describe Issue4086FixHistoricalOptions, type: :db_migration do + let(:expected) do + { + 'Sonstiges' => 'Sonstiges', + 'Hardware' => 'Hardware', + 'Software' => 'Software', + } + end + + let(:attribute) do + attribute = create(:object_manager_attribute_select) + attribute.data_option[:historical_options] = [ + { 'name' => 'Sonstiges', 'value' => 'Sonstiges' }, + { 'name' => 'Hardware', 'value' => 'Hardware' }, + { 'name' => 'Software', 'value' => 'Software' } + ] + attribute.save + attribute + end + + before do + attribute + end + + it 'does fix the broken historical_options' do + migrate + expect(attribute.reload.data_option[:historical_options]).to eq(expected) + end +end