-
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 #546 from h-kataria/split_policy_export
Policy Import/Export startpage url migration to set it to new path
- 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/20210106200226_update_policy_export_startpage_url.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 UpdatePolicyExportStartpageUrl < ActiveRecord::Migration[5.2] | ||
class User < ActiveRecord::Base | ||
serialize :settings, Hash | ||
end | ||
|
||
def up | ||
say_with_time 'Update start page url path for users who had Policy Import/Export set' do | ||
User.select(:id, :settings).each do |user| | ||
if user.settings&.dig(:display, :startpage) == 'miq_policy/export' | ||
user.update!(:settings => user.settings.deep_merge(:display => {:startpage => 'miq_policy_export'})) | ||
end | ||
end | ||
end | ||
end | ||
|
||
def down | ||
say_with_time 'Reverting start page url path for users who had Policy Import/Export pages set' do | ||
User.select(:id, :settings).each do |user| | ||
if user.settings&.dig(:display, :startpage) == 'miq_policy_export' | ||
user.update!(:settings => user.settings.deep_merge(:display => {:startpage => 'miq_policy/export'})) | ||
end | ||
end | ||
end | ||
end | ||
end |
65 changes: 65 additions & 0 deletions
65
spec/migrations/20210106200226_update_policy_export_startpage_url_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 UpdatePolicyExportStartpageUrl do | ||
let(:user_stub) { migration_stub :User } | ||
|
||
migration_context :up do | ||
describe 'starting page update' do | ||
it 'update user start page if miq_policy/export' do | ||
user = user_stub.create!(:settings => {:display => {:startpage => 'miq_policy/export'}}) | ||
|
||
migrate | ||
user.reload | ||
|
||
expect(user.settings[:display][:startpage]).to eq('miq_policy_export') | ||
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_policy/export from miq_policy_export" do | ||
user = user_stub.create!(:settings => {:display => {:startpage => 'miq_policy_export'}}) | ||
|
||
migrate | ||
user.reload | ||
|
||
expect(user.settings[:display][:startpage]).to eq('miq_policy/export') | ||
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 |