From eab09b4a847c9768308f0f86ae8e26a9b3792824 Mon Sep 17 00:00:00 2001 From: Brandon Dunne Date: Wed, 25 Apr 2018 15:59:14 -0400 Subject: [PATCH 1/2] Add spec for nil MiqDatabase#update_repo_name --- ..._repo_data_from_database_to_settings_spec.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/spec/migrations/20160913195129_move_repo_data_from_database_to_settings_spec.rb b/spec/migrations/20160913195129_move_repo_data_from_database_to_settings_spec.rb index c20b00449..805735b7e 100644 --- a/spec/migrations/20160913195129_move_repo_data_from_database_to_settings_spec.rb +++ b/spec/migrations/20160913195129_move_repo_data_from_database_to_settings_spec.rb @@ -33,6 +33,23 @@ ).first expect(setting_change.value).to eq(repo_list) end + + it "handles nil update_repo_name" do + database_attrs = { + :session_secret_token => SecureRandom.hex(64), + :csrf_secret_token => SecureRandom.hex(64), + } + database_stub.create!(database_attrs) + + migrate + + setting_change = settings_stub.where( + :key => described_class::SETTING_KEY, + :resource_id => region.id, + :resource_type => "MiqRegion" + ) + expect(setting_change.count).to eq(0) + end end migration_context :down do From 35c75c049f0776405e9799b0fa408675cd3e00c5 Mon Sep 17 00:00:00 2001 From: Brandon Dunne Date: Wed, 25 Apr 2018 15:55:59 -0400 Subject: [PATCH 2/2] When migrating from scratch, update_repo_name is nil --- .../20160913195129_move_repo_data_from_database_to_settings.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20160913195129_move_repo_data_from_database_to_settings.rb b/db/migrate/20160913195129_move_repo_data_from_database_to_settings.rb index 12a83b676..412c76010 100644 --- a/db/migrate/20160913195129_move_repo_data_from_database_to_settings.rb +++ b/db/migrate/20160913195129_move_repo_data_from_database_to_settings.rb @@ -9,7 +9,7 @@ class SettingsChange < ActiveRecord::Base def up db = MiqDatabase.first - return unless db && my_region + return unless db.try(:update_repo_name) && my_region say_with_time("Moving repo information from miq_databases to Settings") do repos = db.update_repo_name.split