From 46e6afdf204ad724d7833ee15d2db29ee50c72ae Mon Sep 17 00:00:00 2001 From: Harpreet Kataria Date: Wed, 13 May 2020 10:47:08 -0400 Subject: [PATCH] Migration to update startpage entry for chargeback/explorer This migration will update startpage entry for any existing user from `chargeback/explorer` to `chargeback_reports/explorer` This issue was caused by changes in https://github.com/ManageIQ/manageiq-ui-classic/pull/7016 --- ...00512201614_update_chargeback_startpage.rb | 27 ++++++++++ ...201614_update_chargeback_startpage_spec.rb | 50 +++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 db/migrate/20200512201614_update_chargeback_startpage.rb create mode 100644 spec/migrations/20200512201614_update_chargeback_startpage_spec.rb diff --git a/db/migrate/20200512201614_update_chargeback_startpage.rb b/db/migrate/20200512201614_update_chargeback_startpage.rb new file mode 100644 index 000000000..eadfb74e5 --- /dev/null +++ b/db/migrate/20200512201614_update_chargeback_startpage.rb @@ -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 diff --git a/spec/migrations/20200512201614_update_chargeback_startpage_spec.rb b/spec/migrations/20200512201614_update_chargeback_startpage_spec.rb new file mode 100644 index 000000000..2b2a7d720 --- /dev/null +++ b/spec/migrations/20200512201614_update_chargeback_startpage_spec.rb @@ -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