-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
after manageiq/pull/18368 the purpose of `set_data[:button_order]` has been changed, and an error is raised after going through an array, where the button does not exist anymore
- Loading branch information
1 parent
07d8380
commit 9610d43
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class UpdateCustomButtonSets < ActiveRecord::Migration[5.2] | ||
class MiqSet < ActiveRecord::Base | ||
serialize :set_data | ||
end | ||
|
||
class CustomButton < ActiveRecord::Base; end | ||
|
||
def up | ||
say_with_time("Removing deleted buttons from Custom Button Sets") do | ||
MiqSet.select(:id, :set_data).where(:set_type => 'CustomButtonSet').each do |cbs| | ||
next if cbs.set_data[:button_order].blank? | ||
existing_buttons = CustomButton | ||
.where(:id => cbs.set_data[:button_order]) | ||
.order("position(id::text in '#{cbs.set_data[:button_order].join(',')}')") | ||
.ids | ||
cbs.set_data[:button_order] = existing_buttons | ||
cbs.save! | ||
end | ||
end | ||
end | ||
end |
25 changes: 25 additions & 0 deletions
25
spec/migrations/20190509142148_update_custom_button_sets_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require_migration | ||
|
||
describe UpdateCustomButtonSets do | ||
let(:custom_button_set_stub) { migration_stub :MiqSet } | ||
let(:custom_button_stub) { migration_stub :CustomButton } | ||
|
||
migration_context :up do | ||
it 'Removes non-existing buttons while keeping the buttons sorted' do | ||
cb1 = custom_button_stub.create!(:id => 1) | ||
cb2 = custom_button_stub.create!(:id => 2) | ||
cb4 = custom_button_stub.create!(:id => 4) | ||
cb5 = custom_button_stub.create!(:id => 5) | ||
cb7 = custom_button_stub.create!(:id => 7) | ||
cbs = custom_button_set_stub.create!( | ||
:set_type => 'CustomButtonSet', | ||
:set_data => { :button_order => [ | ||
cb1.id, cb7.id, cb2.id, cb4.id, 6, cb5.id, 3]}) | ||
|
||
migrate | ||
|
||
cbs.reload | ||
expect(cbs.set_data[:button_order]).to eql([cb1.id, cb7.id, cb2.id, cb4.id, cb5.id]) | ||
end | ||
end | ||
end |