Skip to content

Commit

Permalink
Merge pull request #546 from h-kataria/split_policy_export
Browse files Browse the repository at this point in the history
Policy Import/Export startpage url migration to set it to new path
  • Loading branch information
gtanzillo authored Jan 11, 2021
2 parents ee78d9c + 2d1af6a commit 00c84a6
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
25 changes: 25 additions & 0 deletions db/migrate/20210106200226_update_policy_export_startpage_url.rb
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
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

0 comments on commit 00c84a6

Please sign in to comment.