-
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.
Data Migration for Startpage url update
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
Showing
2 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
db/migrate/20210112003720_update_events_startpage_url_after_de_explorization.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 @@ | ||
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/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/show_list' | ||
user.update!(:settings => user.settings.deep_merge(:display => {:startpage => 'miq_event/explorer'})) | ||
end | ||
end | ||
end | ||
end | ||
end |
65 changes: 65 additions & 0 deletions
65
spec/migrations/20210112003720_update_events_startpage_url_after_de_explorization_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,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/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/show_list" do | ||
user = user_stub.create!(:settings => {:display => {:startpage => 'miq_event/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 |