Skip to content

Commit

Permalink
Merge pull request #641 from jeffibm/remove-col3-widgets
Browse files Browse the repository at this point in the history
Merging col3 with col2 items of dashboard widgets
  • Loading branch information
Fryguy authored Mar 14, 2022
2 parents 6b04e31 + 7531d03 commit 42759ce
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
31 changes: 31 additions & 0 deletions db/migrate/20220223095704_remove_col3_from_miq_widget_set.rb
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
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

0 comments on commit 42759ce

Please sign in to comment.