Skip to content

Commit

Permalink
Migration to update startpage entry for chargeback/explorer
Browse files Browse the repository at this point in the history
This migration will update startpage entry for any existing user from `chargeback/explorer` to `chargeback_reports/explorer`

This issue was caused by changes in ManageIQ/manageiq-ui-classic#7016
  • Loading branch information
h-kataria committed May 13, 2020
1 parent e3e5907 commit 46e6afd
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
27 changes: 27 additions & 0 deletions db/migrate/20200512201614_update_chargeback_startpage.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class UpdateChargebackStartpage < ActiveRecord::Migration[5.2]
class MiqProductFeature < ActiveRecord::Base; end
class MiqRolesFeature < ActiveRecord::Base; end
class User < ActiveRecord::Base
serialize :settings, Hash
end

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

def down
say_with_time 'Updating starting page for users who had non-explorer ems_configuration pages set' do
User.select(:id, :settings).each do |user|
if user.settings&.dig(:display, :startpage) == 'chargeback_reports/explorer'
user.update!(:settings => user.settings.deep_merge(:display => {:startpage => 'chargeback/explorer'}))
end
end
end
end
end
50 changes: 50 additions & 0 deletions spec/migrations/20200512201614_update_chargeback_startpage_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
require_migration

describe UpdateChargebackStartpage do
let(:feature_stub) { migration_stub :MiqProductFeature }
let(:user_stub) { migration_stub :User }

migration_context :up do
describe 'starting page replace' do
it 'replaces user starting page if chargeback/explorer' do
feature_stub.create!(:identifier => 'chargeback')
user = user_stub.create!(:settings => {:display => {:startpage => 'chargeback/explorer'}})

migrate
user.reload

expect(user.settings[:display][:startpage]).to eq('chargeback_reports/explorer')
end
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 'starting page replace' do
it "replaces user starting page to chargeback if chargeback_reports" do
user = user_stub.create!(:settings => {:display => {:startpage => 'chargeback_reports/explorer'}})

migrate
user.reload

expect(user.settings[:display][:startpage]).to eq('chargeback/explorer')
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 46e6afd

Please sign in to comment.