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

Migration to update startpage entry for chargeback/explorer #481

Merged
merged 1 commit into from
May 18, 2020
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/20200512201614_update_chargeback_startpage.rb
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 spec/migrations/20200512201614_update_chargeback_startpage_spec.rb
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