Fixes #4086 - Custom sort on select returns "undefined method `merge' " for older objects.
This commit is contained in:
parent
d095cd6612
commit
e06d10978e
2 changed files with 48 additions and 0 deletions
|
@ -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
|
33
spec/db/migrate/issue_4086_fix_historical_options_spec.rb
Normal file
33
spec/db/migrate/issue_4086_fix_historical_options_spec.rb
Normal file
|
@ -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
|
Loading…
Reference in a new issue