Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Policy Import/Export startpage url migration to set it to new path #546

Merged
merged 1 commit into from
Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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