-
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 #481 from h-kataria/chargeback_startpage_migration
Migration to update startpage entry for chargeback/explorer
- Loading branch information
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
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 UpdateChargebackStartpage < ActiveRecord::Migration[5.2] | ||
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 |
47 changes: 47 additions & 0 deletions
47
spec/migrations/20200512201614_update_chargeback_startpage_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,47 @@ | ||
require_migration | ||
|
||
describe UpdateChargebackStartpage do | ||
let(:user_stub) { migration_stub :User } | ||
|
||
migration_context :up do | ||
describe 'starting page replace' do | ||
it 'replaces user starting page if chargeback/explorer' do | ||
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 |