Skip to content

Commit

Permalink
Data Migration for Startpage url update
Browse files Browse the repository at this point in the history
If any of the users had their startpage set to Policy Events explorer screen, this migration sets it to non-explorer version screen of Policy Events list view.

UI PR ManageIQ/manageiq-ui-classic#7569
Core PR ManageIQ/manageiq#20947
  • Loading branch information
h-kataria committed Feb 8, 2021
1 parent 00c84a6 commit e34cd5f
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class UpdateEventsStartpageUrlAfterDeExplorization < ActiveRecord::Migration[6.0]
class User < ActiveRecord::Base
serialize :settings, Hash
end

def up
say_with_time 'Updating start page for users who had Policy Events explorer set' do
User.select(:id, :settings).each do |user|
if user.settings&.dig(:display, :startpage) == 'miq_event/explorer'
user.update!(:settings => user.settings.deep_merge(:display => {:startpage => 'miq_event_definition/show_list'}))
end
end
end
end

def down
say_with_time 'Reverting start page for users who had non-explorer Policy Events pages set' do
User.select(:id, :settings).each do |user|
if user.settings&.dig(:display, :startpage) == 'miq_event_definition/show_list'
user.update!(:settings => user.settings.deep_merge(:display => {:startpage => 'miq_event/explorer'}))
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
require_migration

describe UpdateEventsStartpageUrlAfterDeExplorization do
let(:user_stub) { migration_stub :User }

migration_context :up do
describe 'starting page update' do
it 'update user start page if miq_event/explorer' do
user = user_stub.create!(:settings => {:display => {:startpage => 'miq_event/explorer'}})

migrate
user.reload

expect(user.settings[:display][:startpage]).to eq('miq_event_definition/show_list')
end
end

it "user start page remains unchanged if it is set to some other url" do
user = user_stub.create!(:settings => {:display => {:startpage => 'host/show_list'}})

migrate
user.reload

expect(user.settings[:display][:startpage]).to eq('host/show_list')
end

it 'does not affect users without settings' do
user = user_stub.create!

migrate

expect(user_stub.find(user.id)).to eq(user)
end
end

migration_context :down do
describe 'revert start page' do
it "reverts user start page to miq_event/explorer from miq_event_definition/show_list" do
user = user_stub.create!(:settings => {:display => {:startpage => 'miq_event_definition/show_list'}})

migrate
user.reload

expect(user.settings[:display][:startpage]).to eq('miq_event/explorer')
end

it "user start page remains unchanged if it is set to some other url" do
user = user_stub.create!(:settings => {:display => {:startpage => 'host/show_list'}})

migrate
user.reload

expect(user.settings[:display][:startpage]).to eq('host/show_list')
end

it 'does not affect users without settings' do
user = user_stub.create!

migrate

expect(user_stub.find(user.id)).to eq(user)
end
end
end
end

0 comments on commit e34cd5f

Please sign in to comment.