-
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.
Merge pull request #641 from jeffibm/remove-col3-widgets
Merging col3 with col2 items of dashboard widgets
- Loading branch information
Showing
2 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
db/migrate/20220223095704_remove_col3_from_miq_widget_set.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,31 @@ | ||
class RemoveCol3FromMiqWidgetSet < ActiveRecord::Migration[6.0] | ||
class MiqWidgetSet < ActiveRecord::Base | ||
include ActiveRecord::IdRegions | ||
self.table_name = "miq_sets" | ||
serialize :set_data | ||
end | ||
|
||
def up | ||
say_with_time("Moving col3 widgets to col2 and removing col3") do | ||
MiqWidgetSet.all.each do |item| | ||
data = item.set_data | ||
if data | ||
data[:col2] = ((data[:col2] || []) + (data[:col3] || [])).uniq.compact | ||
item.update(:set_data => data.except(:col3)) | ||
end | ||
end | ||
end | ||
end | ||
|
||
def down | ||
say_with_time("Adding col3 to widgets and assigining blank to it") do | ||
MiqWidgetSet.all.each do |item| | ||
data = item.set_data | ||
if data | ||
data[:col3] = [] | ||
item.update(:set_data => data) | ||
end | ||
end | ||
end | ||
end | ||
end |
63 changes: 63 additions & 0 deletions
63
spec/migrations/20220223095704_remove_col3_from_miq_widget_set_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,63 @@ | ||
require_migration | ||
|
||
describe RemoveCol3FromMiqWidgetSet do | ||
let(:widget_stub) { migration_stub(:MiqWidgetSet) } | ||
|
||
migration_context :up do | ||
it "Moving col3 widgets to col2 and removing col3" do | ||
widget = widget_stub.create(:set_data => {:col1 => [1, 2, 3], :col2 => [4, 5, 6], :col3 => [7, 8, 9]}) | ||
migrate | ||
expect(widget.reload.set_data).to eq({:col1 => [1, 2, 3], :col2 => [4, 5, 6, 7, 8, 9]}) | ||
end | ||
|
||
it "Avoiding duplicate widgets after joining col3 with col2" do | ||
widget = widget_stub.create(:set_data => {:col1 => [1, 2, 3], :col2 => [4, 5, 6, 7, 8], :col3 => [4, 7, 8, 9]}) | ||
migrate | ||
expect(widget.reload.set_data).to eq({:col1 => [1, 2, 3], :col2 => [4, 5, 6, 7, 8, 9]}) | ||
end | ||
|
||
it "Moving col3 widget to col2 when col3 is not present" do | ||
widget = widget_stub.create(:set_data => {:col1 => [1, 2, 3], :col2 => [4, 5, 6]}) | ||
migrate | ||
expect(widget.reload.set_data).to eq({:col1 => [1, 2, 3], :col2 => [4, 5, 6]}) | ||
end | ||
|
||
it "Moving col3 widget to col2 when col2 is not present" do | ||
widget = widget_stub.create(:set_data => {:col1 => [1, 2, 3], :col3 => [4, 5, 6]}) | ||
migrate | ||
expect(widget.reload.set_data).to eq({:col1 => [1, 2, 3], :col2 => [4, 5, 6]}) | ||
end | ||
|
||
it "Moving col3 with nil data to col2" do | ||
widget = widget_stub.create(:set_data => {:col1 => [1, 2, 3], :col2 => [4, 5, 6], :col3 => nil}) | ||
migrate | ||
expect(widget.reload.set_data).to eq({:col1 => [1, 2, 3], :col2 => [4, 5, 6]}) | ||
end | ||
|
||
it "Moving col3 to col2 where col2 is nil" do | ||
widget = widget_stub.create(:set_data => {:col1 => [1, 2, 3], :col2 => nil, :col3 => [4, 5, 6]}) | ||
migrate | ||
expect(widget.reload.set_data).to eq({:col1 => [1, 2, 3], :col2 => [4, 5, 6]}) | ||
end | ||
|
||
it "Moving col3 with blank data to col2" do | ||
widget = widget_stub.create(:set_data => {:col1 => [1, 2, 3], :col2 => [4, 5, 6], :col3 => []}) | ||
migrate | ||
expect(widget.reload.set_data).to eq({:col1 => [1, 2, 3], :col2 => [4, 5, 6]}) | ||
end | ||
|
||
it "Moving col3 to col2 when col2 is blank" do | ||
widget = widget_stub.create(:set_data => {:col1 => [1, 2, 3], :col2 => [], :col3 => [4, 5, 6]}) | ||
migrate | ||
expect(widget.reload.set_data).to eq({:col1 => [1, 2, 3], :col2 => [4, 5, 6]}) | ||
end | ||
end | ||
|
||
migration_context :down do | ||
it "Adding col3 to widgets and assigining blank to it" do | ||
widget = widget_stub.create(:set_data => {:col1 => [1, 2, 3], :col2 => [4, 5, 6, 7, 8, 9]}) | ||
migrate | ||
expect(widget.reload.set_data).to eq({:col1 => [1, 2, 3], :col2 => [4, 5, 6, 7, 8, 9], :col3 => []}) | ||
end | ||
end | ||
end |