diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 12:26:25 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 12:26:25 +0000 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/migrations | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) | |
download | gitlab-ce-a09983ae35713f5a2bbb100981116d31ce99826e.tar.gz |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/migrations')
122 files changed, 1088 insertions, 116 deletions
diff --git a/spec/migrations/20190924152703_migrate_issue_trackers_data_spec.rb b/spec/migrations/20190924152703_migrate_issue_trackers_data_spec.rb index dfa4cc21d63..750d3d1fa30 100644 --- a/spec/migrations/20190924152703_migrate_issue_trackers_data_spec.rb +++ b/spec/migrations/20190924152703_migrate_issue_trackers_data_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20190924152703_migrate_issue_trackers_data.rb') -describe MigrateIssueTrackersData do +RSpec.describe MigrateIssueTrackersData do let(:services) { table(:services) } let(:migration_class) { Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData } let(:migration_name) { migration_class.to_s.demodulize } diff --git a/spec/migrations/20191015154408_drop_merge_requests_require_code_owner_approval_from_projects_spec.rb b/spec/migrations/20191015154408_drop_merge_requests_require_code_owner_approval_from_projects_spec.rb index ac9ff5632eb..e2eacc00e5a 100644 --- a/spec/migrations/20191015154408_drop_merge_requests_require_code_owner_approval_from_projects_spec.rb +++ b/spec/migrations/20191015154408_drop_merge_requests_require_code_owner_approval_from_projects_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20191015154408_drop_merge_requests_require_code_owner_approval_from_projects.rb') -describe DropMergeRequestsRequireCodeOwnerApprovalFromProjects do +RSpec.describe DropMergeRequestsRequireCodeOwnerApprovalFromProjects do let(:projects_table) { table(:projects) } subject(:migration) { described_class.new } diff --git a/spec/migrations/20191125114345_add_admin_mode_protected_path_spec.rb b/spec/migrations/20191125114345_add_admin_mode_protected_path_spec.rb index 77d8dd002e3..51f798220c3 100644 --- a/spec/migrations/20191125114345_add_admin_mode_protected_path_spec.rb +++ b/spec/migrations/20191125114345_add_admin_mode_protected_path_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20191125114345_add_admin_mode_protected_path.rb') -describe AddAdminModeProtectedPath do +RSpec.describe AddAdminModeProtectedPath do subject(:migration) { described_class.new } let(:admin_mode_endpoint) { '/admin/session' } diff --git a/spec/migrations/20191204114127_delete_legacy_triggers_spec.rb b/spec/migrations/20191204114127_delete_legacy_triggers_spec.rb index 58061d80f21..07c69872497 100644 --- a/spec/migrations/20191204114127_delete_legacy_triggers_spec.rb +++ b/spec/migrations/20191204114127_delete_legacy_triggers_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20191204114127_delete_legacy_triggers.rb') -describe DeleteLegacyTriggers, schema: 2019_11_25_140458 do +RSpec.describe DeleteLegacyTriggers, schema: 2019_11_25_140458 do let(:ci_trigger_table) { table(:ci_triggers) } let(:user) { table(:users).create!(name: 'test', email: 'test@example.com', projects_limit: 1) } diff --git a/spec/migrations/20200107172020_add_timestamp_softwarelicensespolicy_spec.rb b/spec/migrations/20200107172020_add_timestamp_softwarelicensespolicy_spec.rb index 7a6b21d485b..1377d5e6ba0 100644 --- a/spec/migrations/20200107172020_add_timestamp_softwarelicensespolicy_spec.rb +++ b/spec/migrations/20200107172020_add_timestamp_softwarelicensespolicy_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20200107172020_add_timestamp_softwarelicensespolicy.rb') -describe AddTimestampSoftwarelicensespolicy do +RSpec.describe AddTimestampSoftwarelicensespolicy do let(:software_licenses_policy) { table(:software_license_policies) } let(:projects) { table(:projects) } let(:licenses) { table(:software_licenses) } diff --git a/spec/migrations/20200122123016_backfill_project_settings_spec.rb b/spec/migrations/20200122123016_backfill_project_settings_spec.rb index ce86e94b6d5..0992ddde0c1 100644 --- a/spec/migrations/20200122123016_backfill_project_settings_spec.rb +++ b/spec/migrations/20200122123016_backfill_project_settings_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20200122123016_backfill_project_settings.rb') -describe BackfillProjectSettings, :sidekiq, schema: 20200114113341 do +RSpec.describe BackfillProjectSettings, :sidekiq, schema: 20200114113341 do let(:projects) { table(:projects) } let(:namespace) { table(:namespaces).create(name: 'user', path: 'user') } let(:project) { projects.create(namespace_id: namespace.id) } diff --git a/spec/migrations/20200123155929_remove_invalid_jira_data_spec.rb b/spec/migrations/20200123155929_remove_invalid_jira_data_spec.rb index 253e39c1647..cae8e858af9 100644 --- a/spec/migrations/20200123155929_remove_invalid_jira_data_spec.rb +++ b/spec/migrations/20200123155929_remove_invalid_jira_data_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20200123155929_remove_invalid_jira_data.rb') -describe RemoveInvalidJiraData do +RSpec.describe RemoveInvalidJiraData do let(:jira_tracker_data) { table(:jira_tracker_data) } let(:services) { table(:services) } diff --git a/spec/migrations/20200127090233_remove_invalid_issue_tracker_data_spec.rb b/spec/migrations/20200127090233_remove_invalid_issue_tracker_data_spec.rb index ca7cde08071..a86b5d83a0b 100644 --- a/spec/migrations/20200127090233_remove_invalid_issue_tracker_data_spec.rb +++ b/spec/migrations/20200127090233_remove_invalid_issue_tracker_data_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20200127090233_remove_invalid_issue_tracker_data.rb') -describe RemoveInvalidIssueTrackerData do +RSpec.describe RemoveInvalidIssueTrackerData do let(:issue_tracker_data) { table(:issue_tracker_data) } let(:services) { table(:services) } diff --git a/spec/migrations/20200130145430_reschedule_migrate_issue_trackers_data_spec.rb b/spec/migrations/20200130145430_reschedule_migrate_issue_trackers_data_spec.rb index 8e3e55f3e19..146302ba650 100644 --- a/spec/migrations/20200130145430_reschedule_migrate_issue_trackers_data_spec.rb +++ b/spec/migrations/20200130145430_reschedule_migrate_issue_trackers_data_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20200130145430_reschedule_migrate_issue_trackers_data.rb') -describe RescheduleMigrateIssueTrackersData do +RSpec.describe RescheduleMigrateIssueTrackersData do let(:services) { table(:services) } let(:migration_class) { Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData } let(:migration_name) { migration_class.to_s.demodulize } diff --git a/spec/migrations/20200313203550_remove_orphaned_chat_names_spec.rb b/spec/migrations/20200313203550_remove_orphaned_chat_names_spec.rb index fd30ebaa66f..d9ce62fe475 100644 --- a/spec/migrations/20200313203550_remove_orphaned_chat_names_spec.rb +++ b/spec/migrations/20200313203550_remove_orphaned_chat_names_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20200313203550_remove_orphaned_chat_names.rb') -describe RemoveOrphanedChatNames, schema: 20200313202430 do +RSpec.describe RemoveOrphanedChatNames, schema: 20200313202430 do let(:projects) { table(:projects) } let(:namespaces) { table(:namespaces) } let(:services) { table(:services) } diff --git a/spec/migrations/20200406102120_backfill_deployment_clusters_from_deployments_spec.rb b/spec/migrations/20200406102120_backfill_deployment_clusters_from_deployments_spec.rb index fcb253677e1..47bc7428286 100644 --- a/spec/migrations/20200406102120_backfill_deployment_clusters_from_deployments_spec.rb +++ b/spec/migrations/20200406102120_backfill_deployment_clusters_from_deployments_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20200406102120_backfill_deployment_clusters_from_deployments.rb') -describe BackfillDeploymentClustersFromDeployments, :migration, :sidekiq, schema: 20200227140242 do +RSpec.describe BackfillDeploymentClustersFromDeployments, :migration, :sidekiq, schema: 20200227140242 do describe '#up' do it 'schedules BackfillDeploymentClustersFromDeployments background jobs' do stub_const("#{described_class}::BATCH_SIZE", 2) diff --git a/spec/migrations/20200511145545_change_variable_interpolation_format_in_common_metrics_spec.rb b/spec/migrations/20200511145545_change_variable_interpolation_format_in_common_metrics_spec.rb index f9e8a7ee6e9..e42a448a01e 100644 --- a/spec/migrations/20200511145545_change_variable_interpolation_format_in_common_metrics_spec.rb +++ b/spec/migrations/20200511145545_change_variable_interpolation_format_in_common_metrics_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20200511145545_change_variable_interpolation_format_in_common_metrics') -describe ChangeVariableInterpolationFormatInCommonMetrics, :migration do +RSpec.describe ChangeVariableInterpolationFormatInCommonMetrics, :migration do let(:prometheus_metrics) { table(:prometheus_metrics) } let!(:common_metric) do @@ -23,9 +23,14 @@ describe ChangeVariableInterpolationFormatInCommonMetrics, :migration do end it 'updates query to use {{}}' do - expected_query = 'avg(sum(container_memory_usage_bytes{container_name!="POD",' \ - 'pod_name=~"^{{ci_environment_slug}}-(.*)",namespace="{{kube_namespace}}"})' \ - ' by (job)) without (job) /1024/1024/1024' + expected_query = <<~EOS.chomp + avg(sum(container_memory_usage_bytes{container!="POD",\ + pod=~"^{{ci_environment_slug}}-(.*)",namespace="{{kube_namespace}}"}) \ + by (job)) without (job) /1024/1024/1024 OR \ + avg(sum(container_memory_usage_bytes{container_name!="POD",\ + pod_name=~"^{{ci_environment_slug}}-(.*)",namespace="{{kube_namespace}}"}) \ + by (job)) without (job) /1024/1024/1024 + EOS migrate! diff --git a/spec/migrations/20200526115436_dedup_mr_metrics_spec.rb b/spec/migrations/20200526115436_dedup_mr_metrics_spec.rb new file mode 100644 index 00000000000..f2698a0f352 --- /dev/null +++ b/spec/migrations/20200526115436_dedup_mr_metrics_spec.rb @@ -0,0 +1,68 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20200526115436_dedup_mr_metrics') + +RSpec.describe DedupMrMetrics, :migration, schema: 20200526013844 do + let(:namespaces) { table(:namespaces) } + let(:projects) { table(:projects) } + let(:merge_requests) { table(:merge_requests) } + let(:metrics) { table(:merge_request_metrics) } + let(:merge_request_params) { { source_branch: 'x', target_branch: 'y', target_project_id: project.id } } + + let!(:namespace) { namespaces.create(name: 'foo', path: 'foo') } + let!(:project) { projects.create!(namespace_id: namespace.id) } + let!(:merge_request_1) { merge_requests.create!(merge_request_params) } + let!(:merge_request_2) { merge_requests.create!(merge_request_params) } + let!(:merge_request_3) { merge_requests.create!(merge_request_params) } + + let!(:duplicated_metrics_1) { metrics.create(merge_request_id: merge_request_1.id, latest_build_started_at: 1.day.ago, first_deployed_to_production_at: 5.days.ago, updated_at: 2.months.ago) } + let!(:duplicated_metrics_2) { metrics.create(merge_request_id: merge_request_1.id, latest_build_started_at: Time.now, merged_at: Time.now, updated_at: 1.month.ago) } + + let!(:duplicated_metrics_3) { metrics.create(merge_request_id: merge_request_3.id, diff_size: 30, commits_count: 20, updated_at: 2.months.ago) } + let!(:duplicated_metrics_4) { metrics.create(merge_request_id: merge_request_3.id, added_lines: 5, commits_count: nil, updated_at: 1.month.ago) } + + let!(:non_duplicated_metrics) { metrics.create(merge_request_id: merge_request_2.id, latest_build_started_at: 2.days.ago) } + + it 'deduplicates merge_request_metrics table' do + expect { migrate! }.to change { metrics.count }.from(5).to(3) + end + + it 'merges `duplicated_metrics_1` with `duplicated_metrics_2`' do + migrate! + + expect(metrics.where(id: duplicated_metrics_1.id)).not_to exist + + merged_metrics = metrics.find_by(id: duplicated_metrics_2.id) + + expect(merged_metrics).to be_present + expect(merged_metrics.latest_build_started_at).to be_like_time(duplicated_metrics_2.latest_build_started_at) + expect(merged_metrics.merged_at).to be_like_time(duplicated_metrics_2.merged_at) + expect(merged_metrics.first_deployed_to_production_at).to be_like_time(duplicated_metrics_1.first_deployed_to_production_at) + end + + it 'merges `duplicated_metrics_3` with `duplicated_metrics_4`' do + migrate! + + expect(metrics.where(id: duplicated_metrics_3.id)).not_to exist + + merged_metrics = metrics.find_by(id: duplicated_metrics_4.id) + + expect(merged_metrics).to be_present + expect(merged_metrics.diff_size).to eq(duplicated_metrics_3.diff_size) + expect(merged_metrics.commits_count).to eq(duplicated_metrics_3.commits_count) + expect(merged_metrics.added_lines).to eq(duplicated_metrics_4.added_lines) + end + + it 'does not change non duplicated records' do + expect { migrate! }.not_to change { non_duplicated_metrics.reload.attributes } + end + + it 'does nothing when there are no metrics' do + metrics.delete_all + + migrate! + + expect(metrics.count).to eq(0) + end +end diff --git a/spec/migrations/20200526231421_update_index_approval_rule_name_for_code_owners_rule_type_spec.rb b/spec/migrations/20200526231421_update_index_approval_rule_name_for_code_owners_rule_type_spec.rb new file mode 100644 index 00000000000..9f26b698158 --- /dev/null +++ b/spec/migrations/20200526231421_update_index_approval_rule_name_for_code_owners_rule_type_spec.rb @@ -0,0 +1,175 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'migrate', '20200526231421_update_index_approval_rule_name_for_code_owners_rule_type.rb') + +RSpec.describe UpdateIndexApprovalRuleNameForCodeOwnersRuleType do + let(:migration) { described_class.new } + + let(:approval_rules) { table(:approval_merge_request_rules) } + let(:namespace) { table(:namespaces).create!(name: 'gitlab', path: 'gitlab') } + + let(:project) do + table(:projects).create!( + namespace_id: namespace.id, + name: 'gitlab', + path: 'gitlab' + ) + end + + let(:merge_request) do + table(:merge_requests).create!( + target_project_id: project.id, + source_project_id: project.id, + target_branch: 'feature', + source_branch: 'master' + ) + end + + let(:index_names) do + ActiveRecord::Base.connection + .indexes(:approval_merge_request_rules) + .collect(&:name) + end + + def create_sectional_approval_rules + approval_rules.create!( + merge_request_id: merge_request.id, + name: "*.rb", + code_owner: true, + rule_type: 2, + section: "First Section" + ) + + approval_rules.create!( + merge_request_id: merge_request.id, + name: "*.rb", + code_owner: true, + rule_type: 2, + section: "Second Section" + ) + end + + def create_two_matching_nil_section_approval_rules + 2.times do + approval_rules.create!( + merge_request_id: merge_request.id, + name: "nil_section", + code_owner: true, + rule_type: 2 + ) + end + end + + before do + approval_rules.delete_all + end + + describe "#up" do + it "creates the new index and removes the 'legacy' indices" do + # Confirm that existing legacy indices prevent duplicate entries + # + expect { create_sectional_approval_rules } + .to raise_exception(ActiveRecord::RecordNotUnique) + expect { create_two_matching_nil_section_approval_rules } + .to raise_exception(ActiveRecord::RecordNotUnique) + + approval_rules.delete_all + + disable_migrations_output { migrate! } + + # After running the migration, expect `section == nil` rules to still be + # blocked by the legacy indices, but sectional rules are allowed. + # + expect { create_sectional_approval_rules } + .to change { approval_rules.count }.by(2) + expect { create_two_matching_nil_section_approval_rules } + .to raise_exception(ActiveRecord::RecordNotUnique) + + # Attempt to rerun the creation of sectional rules, and see that sectional + # rules are unique by section + # + expect { create_sectional_approval_rules } + .to raise_exception(ActiveRecord::RecordNotUnique) + + expect(index_names).to include( + described_class::SECTIONAL_INDEX_NAME, + described_class::LEGACY_INDEX_NAME_RULE_TYPE, + described_class::LEGACY_INDEX_NAME_CODE_OWNERS + ) + end + end + + describe "#down" do + context "run as FOSS" do + before do + expect(Gitlab).to receive(:ee?).twice.and_return(false) + end + + it "recreates legacy indices, but does not invoke EE-specific code" do + disable_migrations_output { migrate! } + + expect(index_names).to include( + described_class::SECTIONAL_INDEX_NAME, + described_class::LEGACY_INDEX_NAME_RULE_TYPE, + described_class::LEGACY_INDEX_NAME_CODE_OWNERS + ) + + # Since ApprovalMergeRequestRules are EE-specific, we expect none to be + # deleted during the migration. + # + expect { disable_migrations_output { migration.down } } + .not_to change { approval_rules.count } + + index_names = ActiveRecord::Base.connection + .indexes(:approval_merge_request_rules) + .collect(&:name) + + expect(index_names).not_to include(described_class::SECTIONAL_INDEX_NAME) + expect(index_names).to include( + described_class::LEGACY_INDEX_NAME_RULE_TYPE, + described_class::LEGACY_INDEX_NAME_CODE_OWNERS + ) + end + end + + context "EE" do + it "recreates 'legacy' indices and removes duplicate code owner approval rules" do + skip("This test is skipped under FOSS") unless Gitlab.ee? + + disable_migrations_output { migrate! } + + expect { create_sectional_approval_rules } + .to change { approval_rules.count }.by(2) + expect { create_two_matching_nil_section_approval_rules } + .to raise_exception(ActiveRecord::RecordNotUnique) + + expect(MergeRequests::SyncCodeOwnerApprovalRules) + .to receive(:new).with(MergeRequest.find(merge_request.id)).once.and_call_original + + # Run the down migration. This will remove the 3 approval rules we create + # above, and call MergeRequests::SyncCodeOwnerApprovalRules to recreate + # new ones. However, as there is no CODEOWNERS file in this test + # context, no approval rules will be created, so we can expect + # approval_rules.count to be changed by -3. + # + expect { disable_migrations_output { migration.down } } + .to change { approval_rules.count }.by(-3) + + # Test that the index does not allow us to create the same rules as the + # previous sectional index. + # + expect { create_sectional_approval_rules } + .to raise_exception(ActiveRecord::RecordNotUnique) + expect { create_two_matching_nil_section_approval_rules } + .to raise_exception(ActiveRecord::RecordNotUnique) + + expect(index_names).not_to include(described_class::SECTIONAL_INDEX_NAME) + expect(index_names).to include( + described_class::LEGACY_INDEX_NAME_RULE_TYPE, + described_class::LEGACY_INDEX_NAME_CODE_OWNERS + ) + end + end + end +end diff --git a/spec/migrations/20200703125016_backfill_namespace_settings_spec.rb b/spec/migrations/20200703125016_backfill_namespace_settings_spec.rb new file mode 100644 index 00000000000..7b84ef9e236 --- /dev/null +++ b/spec/migrations/20200703125016_backfill_namespace_settings_spec.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20200703125016_backfill_namespace_settings.rb') + +RSpec.describe BackfillNamespaceSettings, :sidekiq, schema: 20200703124823 do + let(:namespaces) { table(:namespaces) } + + describe '#up' do + before do + stub_const("#{described_class}::BATCH_SIZE", 2) + + namespaces.create!(id: 1, name: 'test1', path: 'test1') + namespaces.create!(id: 2, name: 'test2', path: 'test2') + namespaces.create!(id: 3, name: 'test3', path: 'test3') + end + + it 'schedules BackfillNamespaceSettings background jobs' do + Sidekiq::Testing.fake! do + Timecop.freeze do + migrate! + + expect(described_class::MIGRATION).to be_scheduled_delayed_migration(2.minutes, 1, 2) + expect(described_class::MIGRATION).to be_scheduled_delayed_migration(4.minutes, 3, 3) + expect(BackgroundMigrationWorker.jobs.size).to eq(2) + end + end + end + end +end diff --git a/spec/migrations/20200706035141_adjust_unique_index_alert_management_alerts_spec.rb b/spec/migrations/20200706035141_adjust_unique_index_alert_management_alerts_spec.rb new file mode 100644 index 00000000000..0068571ad0d --- /dev/null +++ b/spec/migrations/20200706035141_adjust_unique_index_alert_management_alerts_spec.rb @@ -0,0 +1,57 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'migrate', '20200706035141_adjust_unique_index_alert_management_alerts.rb') + +RSpec.describe AdjustUniqueIndexAlertManagementAlerts, :migration do + let(:migration) { described_class.new } + let(:alerts) { AlertManagement::Alert } + let(:project) { create_project } + let(:other_project) { create_project } + let(:resolved_state) { 2 } + let(:triggered_state) { 1 } + let!(:existing_alert) { create_alert(project, resolved_state, '1234', 1) } + let!(:p2_alert) { create_alert(other_project, resolved_state, '1234', 1) } + let!(:p2_alert_diff_fingerprint) { create_alert(other_project, resolved_state, '4567', 2) } + + it 'can reverse the migration' do + expect(existing_alert.fingerprint).not_to eq(nil) + expect(p2_alert.fingerprint).not_to eq(nil) + expect(p2_alert_diff_fingerprint.fingerprint).not_to eq(nil) + + migrate! + + # Adding a second alert with the same fingerprint now that we can + second_alert = create_alert(project, triggered_state, '1234', 2) + expect(alerts.count).to eq(4) + + schema_migrate_down! + + # We keep the alerts, but the oldest ones fingerprint is removed + expect(alerts.count).to eq(4) + expect(second_alert.reload.fingerprint).not_to eq(nil) + expect(p2_alert.fingerprint).not_to eq(nil) + expect(p2_alert_diff_fingerprint.fingerprint).not_to eq(nil) + expect(existing_alert.reload.fingerprint).to eq(nil) + end + + def namespace + @namespace ||= table(:namespaces).create!(name: 'foo', path: 'foo') + end + + def create_project + table(:projects).create!(namespace_id: namespace.id) + end + + def create_alert(project, status, fingerprint, iid) + params = { + title: 'test', + started_at: Time.current, + iid: iid, + project_id: project.id, + status: status, + fingerprint: fingerprint + } + table(:alert_management_alerts).create!(params) + end +end diff --git a/spec/migrations/active_record/schema_spec.rb b/spec/migrations/active_record/schema_spec.rb index a3348424f47..8199f55f5fc 100644 --- a/spec/migrations/active_record/schema_spec.rb +++ b/spec/migrations/active_record/schema_spec.rb @@ -5,7 +5,7 @@ require 'spec_helper' # Check consistency of db/structure.sql version, migrations' timestamps, and the latest migration timestamp # stored in the database's schema_migrations table. -describe ActiveRecord::Schema, schema: :latest do +RSpec.describe ActiveRecord::Schema, schema: :latest do let(:all_migrations) do migrations_paths = %w[db/migrate db/post_migrate] .map { |path| Rails.root.join(*path, '*') } @@ -25,6 +25,6 @@ describe ActiveRecord::Schema, schema: :latest do it 'the schema_migrations table contains all schema versions' do versions = ActiveRecord::Base.connection.execute('SELECT version FROM schema_migrations ORDER BY version').map { |m| Integer(m['version']) } - expect(versions).to eq(all_migrations) + expect(versions).to match_array(all_migrations) end end diff --git a/spec/migrations/add_default_and_free_plans_spec.rb b/spec/migrations/add_default_and_free_plans_spec.rb index dffdeb8e71a..75787896999 100644 --- a/spec/migrations/add_default_and_free_plans_spec.rb +++ b/spec/migrations/add_default_and_free_plans_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20191023152913_add_default_and_free_plans.rb') -describe AddDefaultAndFreePlans do +RSpec.describe AddDefaultAndFreePlans do describe 'migrate' do let(:plans) { table(:plans) } diff --git a/spec/migrations/add_default_value_stream_to_groups_with_group_stages_spec.rb b/spec/migrations/add_default_value_stream_to_groups_with_group_stages_spec.rb new file mode 100644 index 00000000000..31dee29a39b --- /dev/null +++ b/spec/migrations/add_default_value_stream_to_groups_with_group_stages_spec.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20200701070435_add_default_value_stream_to_groups_with_group_stages.rb') + +RSpec.describe AddDefaultValueStreamToGroupsWithGroupStages, schema: 20200624142207 do + let(:groups) { table(:namespaces) } + let(:group_stages) { table(:analytics_cycle_analytics_group_stages) } + let(:value_streams) { table(:analytics_cycle_analytics_group_value_streams) } + + let!(:group) { groups.create!(name: 'test', path: 'path', type: 'Group') } + let!(:group_stage) { group_stages.create!(name: 'test', group_id: group.id, start_event_identifier: 1, end_event_identifier: 2) } + + describe '#up' do + it 'creates default value stream record for the group' do + migrate! + + group_value_streams = value_streams.where(group_id: group.id) + expect(group_value_streams.size).to eq(1) + + value_stream = group_value_streams.first + expect(value_stream.name).to eq('default') + end + + it 'migrates existing stages to the default value stream' do + migrate! + + group_stage.reload + + value_stream = value_streams.find_by(group_id: group.id, name: 'default') + expect(group_stage.group_value_stream_id).to eq(value_stream.id) + end + end + + describe '#down' do + it 'sets the group_value_stream_id to nil' do + described_class.new.down + + group_stage.reload + + expect(group_stage.group_value_stream_id).to be_nil + end + end +end diff --git a/spec/migrations/add_deploy_token_type_to_deploy_tokens_spec.rb b/spec/migrations/add_deploy_token_type_to_deploy_tokens_spec.rb index 3bc3d3f8ee2..f1fe27e72a1 100644 --- a/spec/migrations/add_deploy_token_type_to_deploy_tokens_spec.rb +++ b/spec/migrations/add_deploy_token_type_to_deploy_tokens_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20200122161638_add_deploy_token_type_to_deploy_tokens.rb') -describe AddDeployTokenTypeToDeployTokens do +RSpec.describe AddDeployTokenTypeToDeployTokens do let(:deploy_tokens) { table(:deploy_tokens) } let(:deploy_token) do deploy_tokens.create(name: 'token_test', diff --git a/spec/migrations/add_incident_settings_to_all_existing_projects_spec.rb b/spec/migrations/add_incident_settings_to_all_existing_projects_spec.rb index 507b1a8d580..dab42c0ffc3 100644 --- a/spec/migrations/add_incident_settings_to_all_existing_projects_spec.rb +++ b/spec/migrations/add_incident_settings_to_all_existing_projects_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20200609212701_add_incident_settings_to_all_existing_projects.rb') -describe AddIncidentSettingsToAllExistingProjects, :migration do +RSpec.describe AddIncidentSettingsToAllExistingProjects, :migration do let(:project_incident_management_settings) { table(:project_incident_management_settings) } let(:labels) { table(:labels) } let(:label_links) { table(:label_links) } @@ -67,7 +67,7 @@ describe AddIncidentSettingsToAllExistingProjects, :migration do context 'when project has incident labels' do before do issue = issues.create!(project_id: project.id) - incident_label_attrs = IncidentManagement::CreateIssueService::INCIDENT_LABEL + incident_label_attrs = IncidentManagement::CreateIncidentLabelService::LABEL_PROPERTIES incident_label = labels.create!(project_id: project.id, **incident_label_attrs) label_links.create!(target_id: issue.id, label_id: incident_label.id, target_type: 'Issue') end diff --git a/spec/migrations/add_temporary_partial_index_on_project_id_to_services_spec.rb b/spec/migrations/add_temporary_partial_index_on_project_id_to_services_spec.rb index ce790b0266c..1be699f5636 100644 --- a/spec/migrations/add_temporary_partial_index_on_project_id_to_services_spec.rb +++ b/spec/migrations/add_temporary_partial_index_on_project_id_to_services_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20200114112932_add_temporary_partial_index_on_project_id_to_services.rb') -describe AddTemporaryPartialIndexOnProjectIdToServices do +RSpec.describe AddTemporaryPartialIndexOnProjectIdToServices do let(:migration) { described_class.new } describe '#up' do diff --git a/spec/migrations/add_unique_constraint_to_approvals_user_id_and_merge_request_id_spec.rb b/spec/migrations/add_unique_constraint_to_approvals_user_id_and_merge_request_id_spec.rb index 74830ab4ce2..6c04be5fc60 100644 --- a/spec/migrations/add_unique_constraint_to_approvals_user_id_and_merge_request_id_spec.rb +++ b/spec/migrations/add_unique_constraint_to_approvals_user_id_and_merge_request_id_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20190404143330_add_unique_constraint_to_approvals_user_id_and_merge_request_id.rb') -describe AddUniqueConstraintToApprovalsUserIdAndMergeRequestId do +RSpec.describe AddUniqueConstraintToApprovalsUserIdAndMergeRequestId do let(:migration) { described_class.new } let(:namespaces) { table(:namespaces) } let(:projects) { table(:projects) } diff --git a/spec/migrations/backfill_and_add_not_null_constraint_to_released_at_column_on_releases_table_spec.rb b/spec/migrations/backfill_and_add_not_null_constraint_to_released_at_column_on_releases_table_spec.rb index 8fceba276ce..9d0ad5863c6 100644 --- a/spec/migrations/backfill_and_add_not_null_constraint_to_released_at_column_on_releases_table_spec.rb +++ b/spec/migrations/backfill_and_add_not_null_constraint_to_released_at_column_on_releases_table_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20190628185004_backfill_and_add_not_null_constraint_to_released_at_column_on_releases_table.rb') -describe BackfillAndAddNotNullConstraintToReleasedAtColumnOnReleasesTable do +RSpec.describe BackfillAndAddNotNullConstraintToReleasedAtColumnOnReleasesTable do let(:releases) { table(:releases) } let(:namespaces) { table(:namespaces) } let(:projects) { table(:projects) } diff --git a/spec/migrations/backfill_imported_snippet_repositories_spec.rb b/spec/migrations/backfill_imported_snippet_repositories_spec.rb index c77978b23e4..208bda274e2 100644 --- a/spec/migrations/backfill_imported_snippet_repositories_spec.rb +++ b/spec/migrations/backfill_imported_snippet_repositories_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20200608072931_backfill_imported_snippet_repositories.rb') -describe BackfillImportedSnippetRepositories do +RSpec.describe BackfillImportedSnippetRepositories do let(:users) { table(:users) } let(:snippets) { table(:snippets) } let(:user) { users.create(id: 1, email: 'user@example.com', projects_limit: 10, username: 'test', name: 'Test', state: 'active') } diff --git a/spec/migrations/backfill_operations_feature_flags_active_spec.rb b/spec/migrations/backfill_operations_feature_flags_active_spec.rb index c51ed9fea8c..4ec2a4a2a92 100644 --- a/spec/migrations/backfill_operations_feature_flags_active_spec.rb +++ b/spec/migrations/backfill_operations_feature_flags_active_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20191213184609_backfill_operations_feature_flags_active.rb') -describe BackfillOperationsFeatureFlagsActive do +RSpec.describe BackfillOperationsFeatureFlagsActive do let(:namespaces) { table(:namespaces) } let(:projects) { table(:projects) } let(:flags) { table(:operations_feature_flags) } diff --git a/spec/migrations/backfill_operations_feature_flags_iid_spec.rb b/spec/migrations/backfill_operations_feature_flags_iid_spec.rb index 4628780787c..bafe5830652 100644 --- a/spec/migrations/backfill_operations_feature_flags_iid_spec.rb +++ b/spec/migrations/backfill_operations_feature_flags_iid_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20200117194850_backfill_operations_feature_flags_iid.rb') -describe BackfillOperationsFeatureFlagsIid do +RSpec.describe BackfillOperationsFeatureFlagsIid do let(:namespaces) { table(:namespaces) } let(:projects) { table(:projects) } let(:flags) { table(:operations_feature_flags) } diff --git a/spec/migrations/backfill_releases_table_updated_at_and_add_not_null_constraints_to_timestamps_spec.rb b/spec/migrations/backfill_releases_table_updated_at_and_add_not_null_constraints_to_timestamps_spec.rb index bf9a8154e1e..4c3517bc574 100644 --- a/spec/migrations/backfill_releases_table_updated_at_and_add_not_null_constraints_to_timestamps_spec.rb +++ b/spec/migrations/backfill_releases_table_updated_at_and_add_not_null_constraints_to_timestamps_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20190920194925_backfill_releases_table_updated_at_and_add_not_null_constraints_to_timestamps.rb') -describe BackfillReleasesTableUpdatedAtAndAddNotNullConstraintsToTimestamps do +RSpec.describe BackfillReleasesTableUpdatedAtAndAddNotNullConstraintsToTimestamps do let(:releases) { table(:releases) } let(:namespaces) { table(:namespaces) } let(:projects) { table(:projects) } diff --git a/spec/migrations/backfill_snippet_repositories_spec.rb b/spec/migrations/backfill_snippet_repositories_spec.rb index e87bf7376dd..084faa16a37 100644 --- a/spec/migrations/backfill_snippet_repositories_spec.rb +++ b/spec/migrations/backfill_snippet_repositories_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20200420094444_backfill_snippet_repositories.rb') -describe BackfillSnippetRepositories do +RSpec.describe BackfillSnippetRepositories do let(:users) { table(:users) } let(:snippets) { table(:snippets) } let(:user) { users.create(id: 1, email: 'user@example.com', projects_limit: 10, username: 'test', name: 'Test', state: 'active') } diff --git a/spec/migrations/backfill_status_page_published_incidents_spec.rb b/spec/migrations/backfill_status_page_published_incidents_spec.rb index ccdc8be4168..2b1ab891038 100644 --- a/spec/migrations/backfill_status_page_published_incidents_spec.rb +++ b/spec/migrations/backfill_status_page_published_incidents_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20200421195234_backfill_status_page_published_incidents.rb') -describe BackfillStatusPagePublishedIncidents, :migration do +RSpec.describe BackfillStatusPagePublishedIncidents, :migration do subject(:migration) { described_class.new } describe '#up' do diff --git a/spec/migrations/backport_enterprise_schema_spec.rb b/spec/migrations/backport_enterprise_schema_spec.rb index c167301e1e3..b76b53dc259 100644 --- a/spec/migrations/backport_enterprise_schema_spec.rb +++ b/spec/migrations/backport_enterprise_schema_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20190402150158_backport_enterprise_schema.rb') -describe BackportEnterpriseSchema, schema: 20190329085614 do +RSpec.describe BackportEnterpriseSchema, schema: 20190329085614 do include MigrationsHelpers def drop_if_exists(table) diff --git a/spec/migrations/cap_designs_filename_length_to_new_limit_spec.rb b/spec/migrations/cap_designs_filename_length_to_new_limit_spec.rb index daa07953cb5..523c8864b63 100644 --- a/spec/migrations/cap_designs_filename_length_to_new_limit_spec.rb +++ b/spec/migrations/cap_designs_filename_length_to_new_limit_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20200602013901_cap_designs_filename_length_to_new_limit') -describe CapDesignsFilenameLengthToNewLimit, :migration, schema: 20200528125905 do +RSpec.describe CapDesignsFilenameLengthToNewLimit, :migration, schema: 20200528125905 do let(:namespaces) { table(:namespaces) } let(:projects) { table(:projects) } let(:issues) { table(:issues) } diff --git a/spec/migrations/change_outbound_local_requests_whitelist_default_spec.rb b/spec/migrations/change_outbound_local_requests_whitelist_default_spec.rb index dd45cac4a70..53b02425010 100644 --- a/spec/migrations/change_outbound_local_requests_whitelist_default_spec.rb +++ b/spec/migrations/change_outbound_local_requests_whitelist_default_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20190725012225_change_outbound_local_requests_whitelist_default.rb') -describe ChangeOutboundLocalRequestsWhitelistDefault do +RSpec.describe ChangeOutboundLocalRequestsWhitelistDefault do let(:application_settings) { table(:application_settings) } it 'defaults to empty array' do diff --git a/spec/migrations/change_packages_size_defaults_in_project_statistics_spec.rb b/spec/migrations/change_packages_size_defaults_in_project_statistics_spec.rb index c36506643de..8614bfea7cb 100644 --- a/spec/migrations/change_packages_size_defaults_in_project_statistics_spec.rb +++ b/spec/migrations/change_packages_size_defaults_in_project_statistics_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20190516155724_change_packages_size_defaults_in_project_statistics.rb') -describe ChangePackagesSizeDefaultsInProjectStatistics do +RSpec.describe ChangePackagesSizeDefaultsInProjectStatistics do let(:project_statistics) { table(:project_statistics) } let(:projects) { table(:projects) } diff --git a/spec/migrations/clean_grafana_url_spec.rb b/spec/migrations/clean_grafana_url_spec.rb index f6ea88a6f8d..caaf44b884d 100644 --- a/spec/migrations/clean_grafana_url_spec.rb +++ b/spec/migrations/clean_grafana_url_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20200214085940_clean_grafana_url.rb') -describe CleanGrafanaUrl do +RSpec.describe CleanGrafanaUrl do let(:application_settings_table) { table(:application_settings) } [ diff --git a/spec/migrations/clean_up_noteable_id_for_notes_on_commits_spec.rb b/spec/migrations/clean_up_noteable_id_for_notes_on_commits_spec.rb index 602e1c1fe93..531c1dbb76a 100644 --- a/spec/migrations/clean_up_noteable_id_for_notes_on_commits_spec.rb +++ b/spec/migrations/clean_up_noteable_id_for_notes_on_commits_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20190313092516_clean_up_noteable_id_for_notes_on_commits.rb') -describe CleanUpNoteableIdForNotesOnCommits do +RSpec.describe CleanUpNoteableIdForNotesOnCommits do let(:notes) { table(:notes) } before do diff --git a/spec/migrations/cleanup_empty_commit_user_mentions_spec.rb b/spec/migrations/cleanup_empty_commit_user_mentions_spec.rb index 529fe046e32..da714e7da4c 100644 --- a/spec/migrations/cleanup_empty_commit_user_mentions_spec.rb +++ b/spec/migrations/cleanup_empty_commit_user_mentions_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20200128133510_cleanup_empty_commit_user_mentions') -describe CleanupEmptyCommitUserMentions, :migration, :sidekiq do +RSpec.describe CleanupEmptyCommitUserMentions, :migration, :sidekiq do let(:users) { table(:users) } let(:namespaces) { table(:namespaces) } let(:projects) { table(:projects) } diff --git a/spec/migrations/cleanup_legacy_artifact_migration_spec.rb b/spec/migrations/cleanup_legacy_artifact_migration_spec.rb index 29a5c34373c..83b88a0cf1a 100644 --- a/spec/migrations/cleanup_legacy_artifact_migration_spec.rb +++ b/spec/migrations/cleanup_legacy_artifact_migration_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20190104182041_cleanup_legacy_artifact_migration.rb') -describe CleanupLegacyArtifactMigration, :redis do +RSpec.describe CleanupLegacyArtifactMigration, :redis do let(:migration) { spy('migration') } context 'when still legacy artifacts exist' do diff --git a/spec/migrations/cleanup_optimistic_locking_nulls_pt2_fixed_spec.rb b/spec/migrations/cleanup_optimistic_locking_nulls_pt2_fixed_spec.rb index 2e5e450afc7..7c7f87d4e06 100644 --- a/spec/migrations/cleanup_optimistic_locking_nulls_pt2_fixed_spec.rb +++ b/spec/migrations/cleanup_optimistic_locking_nulls_pt2_fixed_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20200427064130_cleanup_optimistic_locking_nulls_pt2_fixed.rb') -describe CleanupOptimisticLockingNullsPt2Fixed, :migration do +RSpec.describe CleanupOptimisticLockingNullsPt2Fixed, :migration, schema: 20200219193117 do test_tables = %w(ci_stages ci_builds ci_pipelines).freeze test_tables.each do |table| let(table.to_sym) { table(table.to_sym) } diff --git a/spec/migrations/cleanup_optimistic_locking_nulls_spec.rb b/spec/migrations/cleanup_optimistic_locking_nulls_spec.rb index 6e541c903ff..bcdcd3e9273 100644 --- a/spec/migrations/cleanup_optimistic_locking_nulls_spec.rb +++ b/spec/migrations/cleanup_optimistic_locking_nulls_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20200128210353_cleanup_optimistic_locking_nulls') -describe CleanupOptimisticLockingNulls do +RSpec.describe CleanupOptimisticLockingNulls do let(:epics) { table(:epics) } let(:merge_requests) { table(:merge_requests) } let(:issues) { table(:issues) } diff --git a/spec/migrations/cleanup_projects_with_missing_namespace_spec.rb b/spec/migrations/cleanup_projects_with_missing_namespace_spec.rb index 27c954d2984..cef6e0f470f 100644 --- a/spec/migrations/cleanup_projects_with_missing_namespace_spec.rb +++ b/spec/migrations/cleanup_projects_with_missing_namespace_spec.rb @@ -47,7 +47,7 @@ class SchemaVersionFinder end end -describe CleanupProjectsWithMissingNamespace, :migration, schema: SchemaVersionFinder.previous_migration do +RSpec.describe CleanupProjectsWithMissingNamespace, :migration, schema: SchemaVersionFinder.previous_migration do let(:projects) { table(:projects) } let(:namespaces) { table(:namespaces) } let(:users) { table(:users) } diff --git a/spec/migrations/confirm_project_bot_users_spec.rb b/spec/migrations/confirm_project_bot_users_spec.rb new file mode 100644 index 00000000000..11aa08d16a9 --- /dev/null +++ b/spec/migrations/confirm_project_bot_users_spec.rb @@ -0,0 +1,84 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20200713071042_confirm_project_bot_users.rb') + +RSpec.describe ConfirmProjectBotUsers, :migration do + let(:users) { table(:users) } + + context 'project bot users that are currently unconfirmed' do + let!(:project_bot_1) do + create_user!( + name: 'bot_1', + email: 'bot_1@example.com', + created_at: 2.days.ago, + user_type: described_class::User::USER_TYPE_PROJECT_BOT + ) + end + + let!(:project_bot_2) do + create_user!( + name: 'bot_2', + email: 'bot_2@example.com', + created_at: 4.days.ago, + user_type: described_class::User::USER_TYPE_PROJECT_BOT + ) + end + + it 'updates their `confirmed_at` attribute' do + expect { migrate! } + .to change { project_bot_1.reload.confirmed_at } + .and change { project_bot_2.reload.confirmed_at } + end + + it 'sets `confirmed_at` to be the same as their `created_at` attribute' do + migrate! + + [project_bot_1, project_bot_2].each do |bot| + expect(bot.reload.confirmed_at).to eq(bot.created_at) + end + end + end + + context 'project bot users that are currently confirmed' do + let!(:confirmed_project_bot) do + create_user!( + name: 'bot_1', + email: 'bot_1@example.com', + user_type: described_class::User::USER_TYPE_PROJECT_BOT, + confirmed_at: 1.day.ago + ) + end + + it 'does not update their `confirmed_at` attribute' do + expect { migrate! }.not_to change { confirmed_project_bot.reload.confirmed_at } + end + end + + context 'human users that are currently unconfirmed' do + let!(:unconfirmed_human) do + create_user!( + name: 'human', + email: 'human@example.com', + user_type: nil + ) + end + + it 'does not update their `confirmed_at` attribute' do + expect { migrate! }.not_to change { unconfirmed_human.reload.confirmed_at } + end + end + + private + + def create_user!(name:, email:, user_type:, created_at: Time.now, confirmed_at: nil) + users.create!( + name: name, + email: email, + username: name, + projects_limit: 0, + user_type: user_type, + confirmed_at: confirmed_at + ) + end +end diff --git a/spec/migrations/create_environment_for_self_monitoring_project_spec.rb b/spec/migrations/create_environment_for_self_monitoring_project_spec.rb index aee0651dee0..1ba464f1610 100644 --- a/spec/migrations/create_environment_for_self_monitoring_project_spec.rb +++ b/spec/migrations/create_environment_for_self_monitoring_project_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20200214214934_create_environment_for_self_monitoring_project') -describe CreateEnvironmentForSelfMonitoringProject do +RSpec.describe CreateEnvironmentForSelfMonitoringProject do let(:application_settings_table) { table(:application_settings) } let(:environments) { table(:environments) } diff --git a/spec/migrations/delete_internal_ids_where_feature_flags_usage_spec.rb b/spec/migrations/delete_internal_ids_where_feature_flags_usage_spec.rb index 6eecd0870ed..a58121fb708 100644 --- a/spec/migrations/delete_internal_ids_where_feature_flags_usage_spec.rb +++ b/spec/migrations/delete_internal_ids_where_feature_flags_usage_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20200117194900_delete_internal_ids_where_feature_flags_usage') -describe DeleteInternalIdsWhereFeatureFlagsUsage do +RSpec.describe DeleteInternalIdsWhereFeatureFlagsUsage do let(:namespaces) { table(:namespaces) } let(:projects) { table(:projects) } let(:internal_ids) { table(:internal_ids) } diff --git a/spec/migrations/delete_template_project_services_spec.rb b/spec/migrations/delete_template_project_services_spec.rb index 3c6709ec310..aacc4fcfd58 100644 --- a/spec/migrations/delete_template_project_services_spec.rb +++ b/spec/migrations/delete_template_project_services_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20200305151736_delete_template_project_services.rb') -describe DeleteTemplateProjectServices, :migration do +RSpec.describe DeleteTemplateProjectServices, :migration do let(:services) { table(:services) } let(:project) { table(:projects).create!(namespace_id: 1) } diff --git a/spec/migrations/delete_template_services_duplicated_by_type_spec.rb b/spec/migrations/delete_template_services_duplicated_by_type_spec.rb index 64da0664e2c..5bcbfb7c733 100644 --- a/spec/migrations/delete_template_services_duplicated_by_type_spec.rb +++ b/spec/migrations/delete_template_services_duplicated_by_type_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20200304160801_delete_template_services_duplicated_by_type.rb') -describe DeleteTemplateServicesDuplicatedByType do +RSpec.describe DeleteTemplateServicesDuplicatedByType do let(:services) { table(:services) } before do diff --git a/spec/migrations/delete_user_callout_alerts_moved_spec.rb b/spec/migrations/delete_user_callout_alerts_moved_spec.rb new file mode 100644 index 00000000000..f6b1a8982fb --- /dev/null +++ b/spec/migrations/delete_user_callout_alerts_moved_spec.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20200710102418_delete_user_callout_alerts_moved.rb') + +RSpec.describe DeleteUserCalloutAlertsMoved do + let(:users) { table(:users) } + let(:user_callouts) { table(:user_callouts) } + let(:alerts_moved_feature) { described_class::FEATURE_NAME_ALERTS_MOVED } + let(:unrelated_feature) { 1 } + + let!(:user1) { users.create!(email: '1', projects_limit: 0) } + let!(:user2) { users.create!(email: '2', projects_limit: 0) } + + subject(:migration) { described_class.new } + + before do + user_callouts.create!(user_id: user1.id, feature_name: alerts_moved_feature) + user_callouts.create!(user_id: user1.id, feature_name: unrelated_feature) + user_callouts.create!(user_id: user2.id, feature_name: alerts_moved_feature) + end + + describe '#up' do + it 'deletes `alerts_moved` user callouts' do + migration.up + + expect(user_callouts.all.map(&:feature_name)).to eq([unrelated_feature]) + end + end +end diff --git a/spec/migrations/drop_activate_prometheus_services_background_jobs_spec.rb b/spec/migrations/drop_activate_prometheus_services_background_jobs_spec.rb index a02a0819a7b..b4bbadd199e 100644 --- a/spec/migrations/drop_activate_prometheus_services_background_jobs_spec.rb +++ b/spec/migrations/drop_activate_prometheus_services_background_jobs_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20200221144534_drop_activate_prometheus_services_background_jobs.rb') -describe DropActivatePrometheusServicesBackgroundJobs, :sidekiq, :redis, schema: 2020_02_21_144534 do +RSpec.describe DropActivatePrometheusServicesBackgroundJobs, :sidekiq, :redis, schema: 2020_02_21_144534 do subject(:migration) { described_class.new } describe '#up' do diff --git a/spec/migrations/drop_background_migration_jobs_spec.rb b/spec/migrations/drop_background_migration_jobs_spec.rb index d9e0561f326..2896f4ca0eb 100644 --- a/spec/migrations/drop_background_migration_jobs_spec.rb +++ b/spec/migrations/drop_background_migration_jobs_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20200116051619_drop_background_migration_jobs.rb') -describe DropBackgroundMigrationJobs, :sidekiq, :redis, schema: 2020_01_16_051619 do +RSpec.describe DropBackgroundMigrationJobs, :sidekiq, :redis, schema: 2020_01_16_051619 do subject(:migration) { described_class.new } describe '#up' do diff --git a/spec/migrations/drop_project_ci_cd_settings_merge_trains_enabled_spec.rb b/spec/migrations/drop_project_ci_cd_settings_merge_trains_enabled_spec.rb index 9166f626922..3f6aae401be 100644 --- a/spec/migrations/drop_project_ci_cd_settings_merge_trains_enabled_spec.rb +++ b/spec/migrations/drop_project_ci_cd_settings_merge_trains_enabled_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20191128162854_drop_project_ci_cd_settings_merge_trains_enabled.rb') -describe DropProjectCiCdSettingsMergeTrainsEnabled do +RSpec.describe DropProjectCiCdSettingsMergeTrainsEnabled do let!(:project_ci_cd_setting) { table(:project_ci_cd_settings) } it 'correctly migrates up and down' do diff --git a/spec/migrations/encrypt_feature_flags_clients_tokens_spec.rb b/spec/migrations/encrypt_feature_flags_clients_tokens_spec.rb index 9b139c4b57b..ad83119f324 100644 --- a/spec/migrations/encrypt_feature_flags_clients_tokens_spec.rb +++ b/spec/migrations/encrypt_feature_flags_clients_tokens_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20190606175050_encrypt_feature_flags_clients_tokens.rb') -describe EncryptFeatureFlagsClientsTokens do +RSpec.describe EncryptFeatureFlagsClientsTokens do let(:migration) { described_class.new } let(:feature_flags_clients) { table(:operations_feature_flags_clients) } let(:projects) { table(:projects) } diff --git a/spec/migrations/encrypt_plaintext_attributes_on_application_settings_spec.rb b/spec/migrations/encrypt_plaintext_attributes_on_application_settings_spec.rb index fda810d1da9..ff5aa81b5b5 100644 --- a/spec/migrations/encrypt_plaintext_attributes_on_application_settings_spec.rb +++ b/spec/migrations/encrypt_plaintext_attributes_on_application_settings_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20191120115530_encrypt_plaintext_attributes_on_application_settings.rb') -describe EncryptPlaintextAttributesOnApplicationSettings do +RSpec.describe EncryptPlaintextAttributesOnApplicationSettings do let(:migration) { described_class.new } let(:application_settings) { table(:application_settings) } let(:plaintext) { 'secret-token' } diff --git a/spec/migrations/enqueue_reset_merge_status_second_run_spec.rb b/spec/migrations/enqueue_reset_merge_status_second_run_spec.rb index d4cf3d15758..f5728534675 100644 --- a/spec/migrations/enqueue_reset_merge_status_second_run_spec.rb +++ b/spec/migrations/enqueue_reset_merge_status_second_run_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20190620112608_enqueue_reset_merge_status_second_run.rb') -describe EnqueueResetMergeStatusSecondRun do +RSpec.describe EnqueueResetMergeStatusSecondRun do let(:namespaces) { table(:namespaces) } let(:projects) { table(:projects) } let(:namespace) { namespaces.create(name: 'gitlab', path: 'gitlab-org') } diff --git a/spec/migrations/enqueue_reset_merge_status_spec.rb b/spec/migrations/enqueue_reset_merge_status_spec.rb index 9728ada14ba..683d2caf9ca 100644 --- a/spec/migrations/enqueue_reset_merge_status_spec.rb +++ b/spec/migrations/enqueue_reset_merge_status_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20190528180441_enqueue_reset_merge_status.rb') -describe EnqueueResetMergeStatus do +RSpec.describe EnqueueResetMergeStatus do let(:namespaces) { table(:namespaces) } let(:projects) { table(:projects) } let(:namespace) { namespaces.create(name: 'gitlab', path: 'gitlab-org') } diff --git a/spec/migrations/fill_file_store_ci_job_artifacts_spec.rb b/spec/migrations/fill_file_store_ci_job_artifacts_spec.rb index 5435a438824..64ab879d53c 100644 --- a/spec/migrations/fill_file_store_ci_job_artifacts_spec.rb +++ b/spec/migrations/fill_file_store_ci_job_artifacts_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20200513235532_fill_file_store_ci_job_artifacts.rb') -describe FillFileStoreCiJobArtifacts do +RSpec.describe FillFileStoreCiJobArtifacts do let(:namespaces) { table(:namespaces) } let(:projects) { table(:projects) } let(:builds) { table(:ci_builds) } diff --git a/spec/migrations/fill_file_store_lfs_objects_spec.rb b/spec/migrations/fill_file_store_lfs_objects_spec.rb index e574eacca35..2a610e5311b 100644 --- a/spec/migrations/fill_file_store_lfs_objects_spec.rb +++ b/spec/migrations/fill_file_store_lfs_objects_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20200513234502_fill_file_store_lfs_objects.rb') -describe FillFileStoreLfsObjects do +RSpec.describe FillFileStoreLfsObjects do let(:lfs_objects) { table(:lfs_objects) } let(:oid) { 'b804383982bb89b00e828e3f44c038cc991d3d1768009fc39ba8e2c081b9fb75' } diff --git a/spec/migrations/fill_productivity_analytics_start_date_spec.rb b/spec/migrations/fill_productivity_analytics_start_date_spec.rb index 4ae7b0eed24..5d7f0ffba50 100644 --- a/spec/migrations/fill_productivity_analytics_start_date_spec.rb +++ b/spec/migrations/fill_productivity_analytics_start_date_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20191004081520_fill_productivity_analytics_start_date.rb') -describe FillProductivityAnalyticsStartDate do +RSpec.describe FillProductivityAnalyticsStartDate do let(:settings_table) { table('application_settings') } let(:metrics_table) { table('merge_request_metrics') } diff --git a/spec/migrations/fill_store_uploads_spec.rb b/spec/migrations/fill_store_uploads_spec.rb index 6a2a3c4ea8e..60eaf982c57 100644 --- a/spec/migrations/fill_store_uploads_spec.rb +++ b/spec/migrations/fill_store_uploads_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20200513235347_fill_store_uploads.rb') -describe FillStoreUploads do +RSpec.describe FillStoreUploads do let(:uploads) { table(:uploads) } let(:path) { 'uploads/-/system/avatar.jpg' } diff --git a/spec/migrations/fix_max_pages_size_spec.rb b/spec/migrations/fix_max_pages_size_spec.rb index 9882cda7fba..b44ce21b858 100644 --- a/spec/migrations/fix_max_pages_size_spec.rb +++ b/spec/migrations/fix_max_pages_size_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20191213120427_fix_max_pages_size.rb') -describe FixMaxPagesSize do +RSpec.describe FixMaxPagesSize do let(:application_settings) { table(:application_settings) } let!(:default_setting) { application_settings.create! } let!(:max_possible_setting) { application_settings.create!(max_pages_size: described_class::MAX_SIZE) } diff --git a/spec/migrations/fix_null_type_labels_spec.rb b/spec/migrations/fix_null_type_labels_spec.rb index b098141c5e9..fadc2a5d29e 100644 --- a/spec/migrations/fix_null_type_labels_spec.rb +++ b/spec/migrations/fix_null_type_labels_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20190131122559_fix_null_type_labels') -describe FixNullTypeLabels do +RSpec.describe FixNullTypeLabels do let(:migration) { described_class.new } let(:projects) { table(:projects) } let(:namespaces) { table(:namespaces) } diff --git a/spec/migrations/fix_pool_repository_source_project_id_spec.rb b/spec/migrations/fix_pool_repository_source_project_id_spec.rb index 5a878dba6e7..67a75b893ef 100644 --- a/spec/migrations/fix_pool_repository_source_project_id_spec.rb +++ b/spec/migrations/fix_pool_repository_source_project_id_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20190604184643_fix_pool_repository_source_project_id.rb') -describe FixPoolRepositorySourceProjectId do +RSpec.describe FixPoolRepositorySourceProjectId do let(:projects) { table(:projects) } let(:pool_repositories) { table(:pool_repositories) } let(:shards) { table(:shards) } diff --git a/spec/migrations/fix_projects_without_project_feature_spec.rb b/spec/migrations/fix_projects_without_project_feature_spec.rb index 01413261008..2a4ba3f3ca5 100644 --- a/spec/migrations/fix_projects_without_project_feature_spec.rb +++ b/spec/migrations/fix_projects_without_project_feature_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20200127111840_fix_projects_without_project_feature.rb') -describe FixProjectsWithoutProjectFeature do +RSpec.describe FixProjectsWithoutProjectFeature do let(:namespace) { table(:namespaces).create(name: 'gitlab', path: 'gitlab-org') } let!(:projects) do diff --git a/spec/migrations/fix_projects_without_prometheus_services_spec.rb b/spec/migrations/fix_projects_without_prometheus_services_spec.rb index ecfad313f58..73ede2ad90c 100644 --- a/spec/migrations/fix_projects_without_prometheus_services_spec.rb +++ b/spec/migrations/fix_projects_without_prometheus_services_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20200220115023_fix_projects_without_prometheus_service.rb') -describe FixProjectsWithoutPrometheusService, :migration do +RSpec.describe FixProjectsWithoutPrometheusService, :migration do let(:namespace) { table(:namespaces).create(name: 'gitlab', path: 'gitlab-org') } let!(:projects) do diff --git a/spec/migrations/fix_wrong_pages_access_level_spec.rb b/spec/migrations/fix_wrong_pages_access_level_spec.rb index e0d09add740..9ee5fa783a4 100644 --- a/spec/migrations/fix_wrong_pages_access_level_spec.rb +++ b/spec/migrations/fix_wrong_pages_access_level_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20190703185326_fix_wrong_pages_access_level.rb') -describe FixWrongPagesAccessLevel, :sidekiq_might_not_need_inline, schema: 20190628185004 do +RSpec.describe FixWrongPagesAccessLevel, :sidekiq_might_not_need_inline, schema: 20190628185004 do using RSpec::Parameterized::TableSyntax let(:migration_class) { described_class::MIGRATION } diff --git a/spec/migrations/generate_lets_encrypt_private_key_spec.rb b/spec/migrations/generate_lets_encrypt_private_key_spec.rb index c0cb39fd519..cad257c18a0 100644 --- a/spec/migrations/generate_lets_encrypt_private_key_spec.rb +++ b/spec/migrations/generate_lets_encrypt_private_key_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20190524062810_generate_lets_encrypt_private_key.rb') -describe GenerateLetsEncryptPrivateKey do +RSpec.describe GenerateLetsEncryptPrivateKey do describe '#up' do it 'does not fail' do expect do diff --git a/spec/migrations/generate_missing_routes_for_bots_spec.rb b/spec/migrations/generate_missing_routes_for_bots_spec.rb new file mode 100644 index 00000000000..8af22042350 --- /dev/null +++ b/spec/migrations/generate_missing_routes_for_bots_spec.rb @@ -0,0 +1,80 @@ +# frozen_string_literal: true + +require 'spec_helper' + +require Rails.root.join('db', 'post_migrate', '20200703064117_generate_missing_routes_for_bots.rb') + +RSpec.describe GenerateMissingRoutesForBots, :migration do + let(:users) { table(:users) } + let(:namespaces) { table(:namespaces) } + let(:routes) { table(:routes) } + + let(:visual_review_bot) do + users.create!(email: 'visual-review-bot@gitlab.com', name: 'GitLab Visual Review Bot', username: 'visual-review-bot', user_type: 3, projects_limit: 5) + end + + let(:migration_bot) do + users.create!(email: 'migration-bot@gitlab.com', name: 'GitLab Migration Bot', username: 'migration-bot', user_type: 7, projects_limit: 5) + end + + let!(:visual_review_bot_namespace) do + namespaces.create!(owner_id: visual_review_bot.id, name: visual_review_bot.name, path: visual_review_bot.username) + end + + let!(:migration_bot_namespace) do + namespaces.create!(owner_id: migration_bot.id, name: migration_bot.name, path: migration_bot.username) + end + + context 'for bot users without an existing route' do + it 'creates new routes' do + expect { migrate! }.to change { routes.count }.by(2) + end + + it 'creates new routes with the same path and name as their namespace' do + migrate! + + [visual_review_bot, migration_bot].each do |bot| + namespace = namespaces.find_by(owner_id: bot.id) + route = route_for(namespace: namespace) + + expect(route.path).to eq(namespace.path) + expect(route.name).to eq(namespace.name) + end + end + end + + it 'does not create routes for bot users with existing routes' do + create_route!(namespace: visual_review_bot_namespace) + create_route!(namespace: migration_bot_namespace) + + expect { migrate! }.not_to change { routes.count } + end + + it 'does not create routes for human users without an existing route' do + human_namespace = create_human_namespace!(name: 'GitLab Human', username: 'human') + + expect { migrate! }.not_to change { route_for(namespace: human_namespace) } + end + + it 'does not create route for a bot user with a missing route, if a human user with the same path already exists' do + human_namespace = create_human_namespace!(name: visual_review_bot.name, username: visual_review_bot.username) + create_route!(namespace: human_namespace) + + expect { migrate! }.not_to change { route_for(namespace: visual_review_bot_namespace) } + end + + private + + def create_human_namespace!(name:, username:) + human = users.create!(email: 'human@gitlab.com', name: name, username: username, user_type: nil, projects_limit: 5) + namespaces.create!(owner_id: human.id, name: human.name, path: human.username) + end + + def create_route!(namespace:) + routes.create!(path: namespace.path, name: namespace.name, source_id: namespace.id, source_type: 'Namespace') + end + + def route_for(namespace:) + routes.find_by(source_type: 'Namespace', source_id: namespace.id) + end +end diff --git a/spec/migrations/insert_project_hooks_plan_limits_spec.rb b/spec/migrations/insert_project_hooks_plan_limits_spec.rb index e4bdda4cf5e..09fae160a6f 100644 --- a/spec/migrations/insert_project_hooks_plan_limits_spec.rb +++ b/spec/migrations/insert_project_hooks_plan_limits_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20191216183532_insert_project_hooks_plan_limits.rb') -describe InsertProjectHooksPlanLimits do +RSpec.describe InsertProjectHooksPlanLimits do let(:migration) { described_class.new } let(:plans) { table(:plans) } let(:plan_limits) { table(:plan_limits) } diff --git a/spec/migrations/migrate_auto_dev_ops_domain_to_cluster_domain_spec.rb b/spec/migrations/migrate_auto_dev_ops_domain_to_cluster_domain_spec.rb index 2fe6f3f62a9..d0abc777326 100644 --- a/spec/migrations/migrate_auto_dev_ops_domain_to_cluster_domain_spec.rb +++ b/spec/migrations/migrate_auto_dev_ops_domain_to_cluster_domain_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20190204115450_migrate_auto_dev_ops_domain_to_cluster_domain.rb') -describe MigrateAutoDevOpsDomainToClusterDomain do +RSpec.describe MigrateAutoDevOpsDomainToClusterDomain do include MigrationHelpers::ClusterHelpers let(:migration) { described_class.new } diff --git a/spec/migrations/migrate_bot_type_to_user_type_spec.rb b/spec/migrations/migrate_bot_type_to_user_type_spec.rb index 9686aae0cd3..2b85f2a7f69 100644 --- a/spec/migrations/migrate_bot_type_to_user_type_spec.rb +++ b/spec/migrations/migrate_bot_type_to_user_type_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20200311074438_migrate_bot_type_to_user_type.rb') -describe MigrateBotTypeToUserType, :migration do +RSpec.describe MigrateBotTypeToUserType, :migration do let(:users) { table(:users) } it 'updates bots & ignores humans' do diff --git a/spec/migrations/migrate_code_owner_approval_status_to_protected_branches_in_batches_spec.rb b/spec/migrations/migrate_code_owner_approval_status_to_protected_branches_in_batches_spec.rb index cda965135b0..70304a4deb2 100644 --- a/spec/migrations/migrate_code_owner_approval_status_to_protected_branches_in_batches_spec.rb +++ b/spec/migrations/migrate_code_owner_approval_status_to_protected_branches_in_batches_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20190827102026_migrate_code_owner_approval_status_to_protected_branches_in_batches.rb') -describe MigrateCodeOwnerApprovalStatusToProtectedBranchesInBatches do +RSpec.describe MigrateCodeOwnerApprovalStatusToProtectedBranchesInBatches do let(:namespaces) { table(:namespaces) } let(:projects) { table(:projects) } let(:protected_branches) { table(:protected_branches) } diff --git a/spec/migrations/migrate_commit_notes_mentions_to_db_spec.rb b/spec/migrations/migrate_commit_notes_mentions_to_db_spec.rb index dc40d0865f2..eb7fb7d4fc5 100644 --- a/spec/migrations/migrate_commit_notes_mentions_to_db_spec.rb +++ b/spec/migrations/migrate_commit_notes_mentions_to_db_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20200128134110_migrate_commit_notes_mentions_to_db') -describe MigrateCommitNotesMentionsToDb, :migration, :sidekiq do +RSpec.describe MigrateCommitNotesMentionsToDb, :migration, :sidekiq do let(:users) { table(:users) } let(:namespaces) { table(:namespaces) } let(:projects) { table(:projects) } diff --git a/spec/migrations/migrate_create_commit_signature_worker_sidekiq_queue_spec.rb b/spec/migrations/migrate_create_commit_signature_worker_sidekiq_queue_spec.rb index 3d7803b7563..5f7b4755980 100644 --- a/spec/migrations/migrate_create_commit_signature_worker_sidekiq_queue_spec.rb +++ b/spec/migrations/migrate_create_commit_signature_worker_sidekiq_queue_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20200206091544_migrate_create_commit_signature_worker_sidekiq_queue.rb') -describe MigrateCreateCommitSignatureWorkerSidekiqQueue, :sidekiq, :redis do +RSpec.describe MigrateCreateCommitSignatureWorkerSidekiqQueue, :sidekiq, :redis do include Gitlab::Database::MigrationHelpers include StubWorker diff --git a/spec/migrations/migrate_discussion_id_on_promoted_epics_spec.rb b/spec/migrations/migrate_discussion_id_on_promoted_epics_spec.rb index 0a8975402da..e3119be495d 100644 --- a/spec/migrations/migrate_discussion_id_on_promoted_epics_spec.rb +++ b/spec/migrations/migrate_discussion_id_on_promoted_epics_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20190715193142_migrate_discussion_id_on_promoted_epics.rb') -describe MigrateDiscussionIdOnPromotedEpics do +RSpec.describe MigrateDiscussionIdOnPromotedEpics do let(:migration_class) { described_class::MIGRATION } let(:migration_name) { migration_class.to_s.demodulize } diff --git a/spec/migrations/migrate_k8s_service_integration_spec.rb b/spec/migrations/migrate_k8s_service_integration_spec.rb index 660e958eb42..a1b2f2ae841 100644 --- a/spec/migrations/migrate_k8s_service_integration_spec.rb +++ b/spec/migrations/migrate_k8s_service_integration_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20190517153211_migrate_k8s_service_integration.rb') -describe MigrateK8sServiceIntegration do +RSpec.describe MigrateK8sServiceIntegration do context 'template service' do context 'with namespace' do let!(:service) do diff --git a/spec/migrations/migrate_legacy_managed_clusters_to_unmanaged_spec.rb b/spec/migrations/migrate_legacy_managed_clusters_to_unmanaged_spec.rb index e3462e1d6bd..c8bfeec8049 100644 --- a/spec/migrations/migrate_legacy_managed_clusters_to_unmanaged_spec.rb +++ b/spec/migrations/migrate_legacy_managed_clusters_to_unmanaged_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20190606163724_migrate_legacy_managed_clusters_to_unmanaged.rb') -describe MigrateLegacyManagedClustersToUnmanaged do +RSpec.describe MigrateLegacyManagedClustersToUnmanaged do let(:cluster_type) { 'project_type' } let(:created_at) { 1.hour.ago } diff --git a/spec/migrations/migrate_managed_clusters_with_no_token_to_unmanaged_spec.rb b/spec/migrations/migrate_managed_clusters_with_no_token_to_unmanaged_spec.rb index 2931fba3eb2..1fc92f6ceea 100644 --- a/spec/migrations/migrate_managed_clusters_with_no_token_to_unmanaged_spec.rb +++ b/spec/migrations/migrate_managed_clusters_with_no_token_to_unmanaged_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20190613231640_migrate_managed_clusters_with_no_token_to_unmanaged.rb') -describe MigrateManagedClustersWithNoTokenToUnmanaged do +RSpec.describe MigrateManagedClustersWithNoTokenToUnmanaged do let(:cluster_type) { 'project_type' } let(:created_at) { Date.new(2018, 11, 1).midnight } diff --git a/spec/migrations/migrate_merge_request_mentions_to_db_spec.rb b/spec/migrations/migrate_merge_request_mentions_to_db_spec.rb index aef8fd6490b..83388cc6314 100644 --- a/spec/migrations/migrate_merge_request_mentions_to_db_spec.rb +++ b/spec/migrations/migrate_merge_request_mentions_to_db_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20200211155539_migrate_merge_request_mentions_to_db') -describe MigrateMergeRequestMentionsToDb, :migration do +RSpec.describe MigrateMergeRequestMentionsToDb, :migration do let(:users) { table(:users) } let(:projects) { table(:projects) } let(:namespaces) { table(:namespaces) } diff --git a/spec/migrations/migrate_ops_feature_flags_scopes_target_user_ids_spec.rb b/spec/migrations/migrate_ops_feature_flags_scopes_target_user_ids_spec.rb index fc5d814a2de..b2c36db2e1d 100644 --- a/spec/migrations/migrate_ops_feature_flags_scopes_target_user_ids_spec.rb +++ b/spec/migrations/migrate_ops_feature_flags_scopes_target_user_ids_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20191118211629_migrate_ops_feature_flags_scopes_target_user_ids.rb') -describe MigrateOpsFeatureFlagsScopesTargetUserIds do +RSpec.describe MigrateOpsFeatureFlagsScopesTargetUserIds do let(:namespaces) { table(:namespaces) } let(:projects) { table(:projects) } let(:flags) { table(:operations_feature_flags) } diff --git a/spec/migrations/migrate_storage_migrator_sidekiq_queue_spec.rb b/spec/migrations/migrate_storage_migrator_sidekiq_queue_spec.rb index 557eb52632f..1181c169f57 100644 --- a/spec/migrations/migrate_storage_migrator_sidekiq_queue_spec.rb +++ b/spec/migrations/migrate_storage_migrator_sidekiq_queue_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20190124200344_migrate_storage_migrator_sidekiq_queue.rb') -describe MigrateStorageMigratorSidekiqQueue, :redis do +RSpec.describe MigrateStorageMigratorSidekiqQueue, :redis do include Gitlab::Database::MigrationHelpers include StubWorker diff --git a/spec/migrations/migrate_store_security_reports_sidekiq_queue_spec.rb b/spec/migrations/migrate_store_security_reports_sidekiq_queue_spec.rb index ddffa036af1..4face37bd66 100644 --- a/spec/migrations/migrate_store_security_reports_sidekiq_queue_spec.rb +++ b/spec/migrations/migrate_store_security_reports_sidekiq_queue_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20200213220159_migrate_store_security_reports_sidekiq_queue.rb') -describe MigrateStoreSecurityReportsSidekiqQueue, :redis do +RSpec.describe MigrateStoreSecurityReportsSidekiqQueue, :redis do include Gitlab::Database::MigrationHelpers include StubWorker diff --git a/spec/migrations/migrate_sync_security_reports_to_report_approval_rules_sidekiq_queue_spec.rb b/spec/migrations/migrate_sync_security_reports_to_report_approval_rules_sidekiq_queue_spec.rb index 6dfaff06ddb..15c5761bd99 100644 --- a/spec/migrations/migrate_sync_security_reports_to_report_approval_rules_sidekiq_queue_spec.rb +++ b/spec/migrations/migrate_sync_security_reports_to_report_approval_rules_sidekiq_queue_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20200213220211_migrate_sync_security_reports_to_report_approval_rules_sidekiq_queue.rb') -describe MigrateSyncSecurityReportsToReportApprovalRulesSidekiqQueue, :redis do +RSpec.describe MigrateSyncSecurityReportsToReportApprovalRulesSidekiqQueue, :redis do include Gitlab::Database::MigrationHelpers include StubWorker diff --git a/spec/migrations/move_limits_from_plans_spec.rb b/spec/migrations/move_limits_from_plans_spec.rb index aeb36100205..16f94ba6dbb 100644 --- a/spec/migrations/move_limits_from_plans_spec.rb +++ b/spec/migrations/move_limits_from_plans_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20191030152934_move_limits_from_plans.rb') -describe MoveLimitsFromPlans do +RSpec.describe MoveLimitsFromPlans do let(:plans) { table(:plans) } let(:plan_limits) { table(:plan_limits) } diff --git a/spec/migrations/nullify_users_role_spec.rb b/spec/migrations/nullify_users_role_spec.rb index b11929ef76f..3cdeb81f362 100644 --- a/spec/migrations/nullify_users_role_spec.rb +++ b/spec/migrations/nullify_users_role_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20191104142124_nullify_users_role.rb') -describe NullifyUsersRole do +RSpec.describe NullifyUsersRole do let(:users) { table(:users) } before do diff --git a/spec/migrations/populate_project_statistics_packages_size_spec.rb b/spec/migrations/populate_project_statistics_packages_size_spec.rb index c316a4bc8b7..9024406c614 100644 --- a/spec/migrations/populate_project_statistics_packages_size_spec.rb +++ b/spec/migrations/populate_project_statistics_packages_size_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20190418132125_populate_project_statistics_packages_size.rb') -describe PopulateProjectStatisticsPackagesSize do +RSpec.describe PopulateProjectStatisticsPackagesSize do let(:project_statistics) { table(:project_statistics) } let(:namespaces) { table(:namespaces) } let(:projects) { table(:projects) } diff --git a/spec/migrations/populate_rule_type_on_approval_merge_request_rules_spec.rb b/spec/migrations/populate_rule_type_on_approval_merge_request_rules_spec.rb index d6362528068..2ac912d7979 100644 --- a/spec/migrations/populate_rule_type_on_approval_merge_request_rules_spec.rb +++ b/spec/migrations/populate_rule_type_on_approval_merge_request_rules_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20190520201748_populate_rule_type_on_approval_merge_request_rules.rb') -describe PopulateRuleTypeOnApprovalMergeRequestRules do +RSpec.describe PopulateRuleTypeOnApprovalMergeRequestRules do let(:migration) { described_class.new } describe '#up' do diff --git a/spec/migrations/remove_additional_application_settings_rows_spec.rb b/spec/migrations/remove_additional_application_settings_rows_spec.rb index 379fa385b8e..a865e8e8dd7 100644 --- a/spec/migrations/remove_additional_application_settings_rows_spec.rb +++ b/spec/migrations/remove_additional_application_settings_rows_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20200420162730_remove_additional_application_settings_rows.rb') -describe RemoveAdditionalApplicationSettingsRows do +RSpec.describe RemoveAdditionalApplicationSettingsRows do let(:application_settings) { table(:application_settings) } it 'removes additional rows from application settings' do diff --git a/spec/migrations/remove_deprecated_jenkins_service_records_spec.rb b/spec/migrations/remove_deprecated_jenkins_service_records_spec.rb index 9c9abd36203..00fde88c528 100644 --- a/spec/migrations/remove_deprecated_jenkins_service_records_spec.rb +++ b/spec/migrations/remove_deprecated_jenkins_service_records_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20200511130129_remove_deprecated_jenkins_service_records.rb') require Rails.root.join('db', 'post_migrate', '20200511130130_ensure_deprecated_jenkins_service_records_removal.rb') -shared_examples 'remove DeprecatedJenkinsService records' do +RSpec.shared_examples 'remove DeprecatedJenkinsService records' do let(:services) { table(:services) } before do @@ -19,10 +19,10 @@ shared_examples 'remove DeprecatedJenkinsService records' do end end -describe RemoveDeprecatedJenkinsServiceRecords, :migration do +RSpec.describe RemoveDeprecatedJenkinsServiceRecords, :migration do it_behaves_like 'remove DeprecatedJenkinsService records' end -describe EnsureDeprecatedJenkinsServiceRecordsRemoval, :migration do +RSpec.describe EnsureDeprecatedJenkinsServiceRecordsRemoval, :migration do it_behaves_like 'remove DeprecatedJenkinsService records' end diff --git a/spec/migrations/remove_duplicate_labels_from_project_spec.rb b/spec/migrations/remove_duplicate_labels_from_project_spec.rb new file mode 100644 index 00000000000..5e287eaa4ed --- /dev/null +++ b/spec/migrations/remove_duplicate_labels_from_project_spec.rb @@ -0,0 +1,238 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20200305082754_remove_duplicate_labels_from_project.rb') + +RSpec.describe RemoveDuplicateLabelsFromProject do + let(:labels_table) { table(:labels) } + let(:labels) { labels_table.all } + let(:projects_table) { table(:projects) } + let(:projects) { projects_table.all } + let(:namespaces_table) { table(:namespaces) } + let(:namespaces) { namespaces_table.all } + let(:backup_labels_table) { table(:backup_labels) } + let(:backup_labels) { backup_labels_table.all } + + # all the possible tables with records that may have a relationship with a label + let(:analytics_cycle_analytics_group_stages_table) { table(:analytics_cycle_analytics_group_stages) } + let(:analytics_cycle_analytics_project_stages_table) { table(:analytics_cycle_analytics_project_stages) } + let(:board_labels_table) { table(:board_labels) } + let(:label_links_table) { table(:label_links) } + let(:label_priorities_table) { table(:label_priorities) } + let(:lists_table) { table(:lists) } + let(:resource_label_events_table) { table(:resource_label_events) } + + let!(:group_one) { namespaces_table.create!(id: 1, type: 'Group', name: 'group', path: 'group') } + let!(:project_one) do + projects_table.create!(id: 1, name: 'project', path: 'project', + visibility_level: 0, namespace_id: group_one.id) + end + let(:label_title) { 'bug' } + let(:label_color) { 'red' } + let(:label_description) { 'nice label' } + let(:group_id) { group_one.id } + let(:project_id) { project_one.id } + let(:other_title) { 'feature' } + + let(:group_label_attributes) do + { + title: label_title, color: label_color, group_id: group_id, type: 'GroupLabel', template: false, description: label_description + } + end + + let(:project_label_attributes) do + { + title: label_title, color: label_color, project_id: project_id, type: 'ProjectLabel', template: false, description: label_description + } + end + + let(:migration) { described_class.new } + + describe 'removing full duplicates' do + context 'when there are no duplicate labels' do + let!(:first_label) { labels_table.create!(project_label_attributes.merge(id: 1, title: "a different label")) } + let!(:second_label) { labels_table.create!(project_label_attributes.merge(id: 2, title: "a totally different label")) } + + it 'does not remove anything' do + expect { migration.up }.not_to change { backup_labels_table.count } + end + + it 'restores removed records when rolling back - no change' do + migration.up + + expect { migration.down }.not_to change { labels_table.count } + end + end + + context 'with duplicates with no relationships' do + # can't use the activerecord class because the `type` makes it think it has polymorphism and should be/have a ProjectLabel subclass + let(:backup_labels) { ApplicationRecord.connection.execute('SELECT * from backup_labels') } + + let!(:first_label) { labels_table.create!(project_label_attributes.merge(id: 1)) } + let!(:second_label) { labels_table.create!(project_label_attributes.merge(id: 2)) } + let!(:third_label) { labels_table.create!(project_label_attributes.merge(id: 3, title: other_title)) } + let!(:fourth_label) { labels_table.create!(project_label_attributes.merge(id: 4, title: other_title)) } + + it 'creates a backup record for each removed record' do + expect { migration.up }.to change { backup_labels_table.count }.from(0).to(2) + end + + it 'creates the correct backup records with `create` restore_action' do + migration.up + + expect(backup_labels.find { |bl| bl["id"] == 2 }).to include(second_label.attributes.merge("restore_action" => described_class::CREATE, "new_title" => nil, "created_at" => anything, "updated_at" => anything)) + expect(backup_labels.find { |bl| bl["id"] == 4 }).to include(fourth_label.attributes.merge("restore_action" => described_class::CREATE, "new_title" => nil, "created_at" => anything, "updated_at" => anything)) + end + + it 'deletes all but one' do + migration.up + + expect { second_label.reload }.to raise_error(ActiveRecord::RecordNotFound) + expect { fourth_label.reload }.to raise_error(ActiveRecord::RecordNotFound) + end + + it 'restores removed records on rollback' do + second_label_attributes = modified_attributes(second_label) + fourth_label_attributes = modified_attributes(fourth_label) + + migration.up + + migration.down + + expect(second_label.attributes).to include(second_label_attributes) + expect(fourth_label.attributes).to include(fourth_label_attributes) + end + end + + context 'two duplicate records, one of which has a relationship' do + let!(:first_label) { labels_table.create!(project_label_attributes.merge(id: 1)) } + let!(:second_label) { labels_table.create!(project_label_attributes.merge(id: 2)) } + let!(:label_priority) { label_priorities_table.create!(label_id: second_label.id, project_id: project_id, priority: 1) } + + it 'does not remove anything' do + expect { migration.up }.not_to change { labels_table.count } + end + + it 'does not create a backup record with `create` restore_action' do + expect { migration.up }.not_to change { backup_labels_table.where(restore_action: described_class::CREATE).count } + end + + it 'restores removed records when rolling back - no change' do + migration.up + + expect { migration.down }.not_to change { labels_table.count } + end + end + + context 'multiple duplicates, a subset of which have relationships' do + let!(:first_label) { labels_table.create!(project_label_attributes.merge(id: 1)) } + let!(:second_label) { labels_table.create!(project_label_attributes.merge(id: 2)) } + let!(:label_priority_for_second_label) { label_priorities_table.create!(label_id: second_label.id, project_id: project_id, priority: 1) } + let!(:third_label) { labels_table.create!(project_label_attributes.merge(id: 3)) } + let!(:fourth_label) { labels_table.create!(project_label_attributes.merge(id: 4)) } + let!(:label_priority_for_fourth_label) { label_priorities_table.create!(label_id: fourth_label.id, project_id: project_id, priority: 2) } + + it 'creates a backup record with `create` restore_action for each removed record' do + expect { migration.up }.to change { backup_labels_table.where(restore_action: described_class::CREATE).count }.from(0).to(1) + end + + it 'creates the correct backup records' do + migration.up + + # can't use the activerecord class because the `type` column makes it think it has polymorphism and should be/have a ProjectLabel subclass + backup_labels = ApplicationRecord.connection.execute('SELECT * from backup_labels') + + expect(backup_labels.find { |bl| bl["id"] == 3 }).to include(third_label.attributes.merge("restore_action" => described_class::CREATE, "new_title" => nil, "created_at" => anything, "updated_at" => anything)) + end + + it 'deletes the duplicate record' do + migration.up + + expect { first_label.reload }.not_to raise_error + expect { second_label.reload }.not_to raise_error + expect { third_label.reload }.to raise_error(ActiveRecord::RecordNotFound) + end + + it 'restores removed records on rollback' do + third_label_attributes = modified_attributes(third_label) + + migration.up + migration.down + + expect(third_label.attributes).to include(third_label_attributes) + end + end + end + + describe 'renaming partial duplicates' do + # partial duplicates - only project_id and title match. Distinct colour prevents deletion. + context 'when there are no duplicate labels' do + let!(:first_label) { labels_table.create!(project_label_attributes.merge(id: 1, title: "a unique label", color: 'green')) } + let!(:second_label) { labels_table.create!(project_label_attributes.merge(id: 2, title: "a totally different, unique, label", color: 'blue')) } + + it 'does not rename anything' do + expect { migration.up }.not_to change { backup_labels_table.count } + end + end + + context 'with duplicates with no relationships' do + let!(:first_label) { labels_table.create!(project_label_attributes.merge(id: 1, color: 'green')) } + let!(:second_label) { labels_table.create!(project_label_attributes.merge(id: 2, color: 'blue')) } + let!(:third_label) { labels_table.create!(project_label_attributes.merge(id: 3, title: other_title, color: 'purple')) } + let!(:fourth_label) { labels_table.create!(project_label_attributes.merge(id: 4, title: other_title, color: 'yellow')) } + + it 'creates a backup record for each renamed record' do + expect { migration.up }.to change { backup_labels_table.count }.from(0).to(2) + end + + it 'creates the correct backup records with `rename` restore_action' do + migration.up + + # can't use the activerecord class because the `type` makes it think it has polymorphism and should be/have a ProjectLabel subclass + backup_labels = ApplicationRecord.connection.execute('SELECT * from backup_labels') + + expect(backup_labels.find { |bl| bl["id"] == 2 }).to include(second_label.attributes.merge("restore_action" => described_class::RENAME, "created_at" => anything, "updated_at" => anything)) + expect(backup_labels.find { |bl| bl["id"] == 4 }).to include(fourth_label.attributes.merge("restore_action" => described_class::RENAME, "created_at" => anything, "updated_at" => anything)) + end + + it 'modifies the titles of the partial duplicates' do + migration.up + + expect(second_label.reload.title).to match(/#{label_title}_duplicate#{second_label.id}$/) + expect(fourth_label.reload.title).to match(/#{other_title}_duplicate#{fourth_label.id}$/) + end + + it 'restores renamed records on rollback' do + second_label_attributes = modified_attributes(second_label) + fourth_label_attributes = modified_attributes(fourth_label) + + migration.up + + migration.down + + expect(second_label.reload.attributes).to include(second_label_attributes) + expect(fourth_label.reload.attributes).to include(fourth_label_attributes) + end + + context 'when the labels have a long title that might overflow' do + let(:long_title) { "a" * 255 } + + before do + first_label.update_attribute(:title, long_title) + second_label.update_attribute(:title, long_title) + end + + it 'keeps the length within the limit' do + migration.up + + expect(second_label.reload.title).to eq("#{"a" * 244}_duplicate#{second_label.id}") + expect(second_label.title.length).to eq 255 + end + end + end + end + + def modified_attributes(label) + label.attributes.except('created_at', 'updated_at') + end +end diff --git a/spec/migrations/remove_empty_github_service_templates_spec.rb b/spec/migrations/remove_empty_github_service_templates_spec.rb index 51b29ec6efc..7a77e342efd 100644 --- a/spec/migrations/remove_empty_github_service_templates_spec.rb +++ b/spec/migrations/remove_empty_github_service_templates_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20191021101942_remove_empty_github_service_templates.rb') -describe RemoveEmptyGithubServiceTemplates do +RSpec.describe RemoveEmptyGithubServiceTemplates do subject(:migration) { described_class.new } let(:services) do diff --git a/spec/migrations/remove_gitlab_issue_tracker_service_records_spec.rb b/spec/migrations/remove_gitlab_issue_tracker_service_records_spec.rb new file mode 100644 index 00000000000..81fa29f4c54 --- /dev/null +++ b/spec/migrations/remove_gitlab_issue_tracker_service_records_spec.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20200623142159_remove_gitlab_issue_tracker_service_records.rb') + +RSpec.describe RemoveGitlabIssueTrackerServiceRecords do + let(:services) { table(:services) } + + before do + 5.times { services.create!(type: 'GitlabIssueTrackerService') } + services.create!(type: 'SomeOtherType') + end + + it 'removes services records of type GitlabIssueTrackerService', :aggregate_failures do + expect { migrate! }.to change { services.count }.from(6).to(1) + expect(services.first.type).to eq('SomeOtherType') + expect(services.where(type: 'GitlabIssueTrackerService')).to be_empty + end +end diff --git a/spec/migrations/remove_orphaned_invited_members_spec.rb b/spec/migrations/remove_orphaned_invited_members_spec.rb index 0ed4c15428a..0474b5362be 100644 --- a/spec/migrations/remove_orphaned_invited_members_spec.rb +++ b/spec/migrations/remove_orphaned_invited_members_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20200424050250_remove_orphaned_invited_members.rb') -describe RemoveOrphanedInvitedMembers do +RSpec.describe RemoveOrphanedInvitedMembers do let(:members_table) { table(:members) } let(:users_table) { table(:users) } let(:namespaces_table) { table(:namespaces) } diff --git a/spec/migrations/remove_packages_deprecated_dependencies_spec.rb b/spec/migrations/remove_packages_deprecated_dependencies_spec.rb index 2ba7a3b268b..84c23240af9 100644 --- a/spec/migrations/remove_packages_deprecated_dependencies_spec.rb +++ b/spec/migrations/remove_packages_deprecated_dependencies_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20200210135504_remove_packages_deprecated_dependencies.rb') -describe RemovePackagesDeprecatedDependencies do +RSpec.describe RemovePackagesDeprecatedDependencies do let(:projects) { table(:projects) } let(:packages) { table(:packages_packages) } let(:dependency_links) { table(:packages_dependency_links) } diff --git a/spec/migrations/remove_security_dashboard_feature_flag_spec.rb b/spec/migrations/remove_security_dashboard_feature_flag_spec.rb index fa0489526e2..77363aebfe6 100644 --- a/spec/migrations/remove_security_dashboard_feature_flag_spec.rb +++ b/spec/migrations/remove_security_dashboard_feature_flag_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20200214034836_remove_security_dashboard_feature_flag.rb') -describe RemoveSecurityDashboardFeatureFlag do +RSpec.describe RemoveSecurityDashboardFeatureFlag do let(:feature_gates) { table(:feature_gates) } subject(:migration) { described_class.new } diff --git a/spec/migrations/rename_security_dashboard_feature_flag_to_instance_security_dashboard_spec.rb b/spec/migrations/rename_security_dashboard_feature_flag_to_instance_security_dashboard_spec.rb index 07be7a4ad51..83a79ac9795 100644 --- a/spec/migrations/rename_security_dashboard_feature_flag_to_instance_security_dashboard_spec.rb +++ b/spec/migrations/rename_security_dashboard_feature_flag_to_instance_security_dashboard_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20200212014653_rename_security_dashboard_feature_flag_to_instance_security_dashboard.rb') -describe RenameSecurityDashboardFeatureFlagToInstanceSecurityDashboard do +RSpec.describe RenameSecurityDashboardFeatureFlagToInstanceSecurityDashboard do let(:feature_gates) { table(:feature_gates) } subject(:migration) { described_class.new } diff --git a/spec/migrations/save_instance_administrators_group_id_spec.rb b/spec/migrations/save_instance_administrators_group_id_spec.rb index 74ced009fa5..cb11cd1653a 100644 --- a/spec/migrations/save_instance_administrators_group_id_spec.rb +++ b/spec/migrations/save_instance_administrators_group_id_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20200210092405_save_instance_administrators_group_id') -describe SaveInstanceAdministratorsGroupId do +RSpec.describe SaveInstanceAdministratorsGroupId do let(:application_settings_table) { table(:application_settings) } let(:instance_administrators_group) do diff --git a/spec/migrations/schedule_backfill_push_rules_id_in_projects_spec.rb b/spec/migrations/schedule_backfill_push_rules_id_in_projects_spec.rb index 77721eab77d..37a769bbc52 100644 --- a/spec/migrations/schedule_backfill_push_rules_id_in_projects_spec.rb +++ b/spec/migrations/schedule_backfill_push_rules_id_in_projects_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20200325162730_schedule_backfill_push_rules_id_in_projects.rb') -describe ScheduleBackfillPushRulesIdInProjects do +RSpec.describe ScheduleBackfillPushRulesIdInProjects do let(:push_rules) { table(:push_rules) } it 'adds global rule association to application settings' do diff --git a/spec/migrations/schedule_calculate_wiki_sizes_spec.rb b/spec/migrations/schedule_calculate_wiki_sizes_spec.rb new file mode 100644 index 00000000000..39a93f3ed25 --- /dev/null +++ b/spec/migrations/schedule_calculate_wiki_sizes_spec.rb @@ -0,0 +1,60 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20190527194900_schedule_calculate_wiki_sizes.rb') + +RSpec.describe ScheduleCalculateWikiSizes do + let(:migration_class) { Gitlab::BackgroundMigration::CalculateWikiSizes } + let(:migration_name) { migration_class.to_s.demodulize } + + let(:namespaces) { table(:namespaces) } + let(:projects) { table(:projects) } + let(:project_statistics) { table(:project_statistics) } + let(:namespace) { namespaces.create!(name: 'wiki-migration', path: 'wiki-migration') } + let(:project1) { projects.create!(name: 'wiki-project-1', path: 'wiki-project-1', namespace_id: namespace.id) } + let(:project2) { projects.create!(name: 'wiki-project-2', path: 'wiki-project-2', namespace_id: namespace.id) } + let(:project3) { projects.create!(name: 'wiki-project-3', path: 'wiki-project-3', namespace_id: namespace.id) } + + context 'when missing wiki sizes exist' do + let!(:project_statistic1) { project_statistics.create!(id: 1, project_id: project1.id, namespace_id: namespace.id, wiki_size: 1000) } + let!(:project_statistic2) { project_statistics.create!(id: 2, project_id: project2.id, namespace_id: namespace.id, wiki_size: nil) } + let!(:project_statistic3) { project_statistics.create!(id: 3, project_id: project3.id, namespace_id: namespace.id, wiki_size: nil) } + + it 'schedules a background migration' do + Timecop.freeze do + migrate! + + expect(migration_name).to be_scheduled_delayed_migration(5.minutes, project_statistic2.id, project_statistic3.id) + expect(BackgroundMigrationWorker.jobs.size).to eq 1 + end + end + + it 'calculates missing wiki sizes', :sidekiq_inline do + expect(project_statistic2.wiki_size).to be_nil + expect(project_statistic3.wiki_size).to be_nil + + migrate! + + expect(project_statistic2.reload.wiki_size).not_to be_nil + expect(project_statistic3.reload.wiki_size).not_to be_nil + end + end + + context 'when missing wiki sizes do not exist' do + before do + namespace = namespaces.create!(name: 'wiki-migration', path: 'wiki-migration') + project = projects.create!(name: 'wiki-project-1', path: 'wiki-project-1', namespace_id: namespace.id) + project_statistics.create!(project_id: project.id, namespace_id: 1, wiki_size: 1000) + end + + it 'does not schedule a background migration' do + Sidekiq::Testing.fake! do + Timecop.freeze do + migrate! + + expect(BackgroundMigrationWorker.jobs.size).to eq 0 + end + end + end + end +end diff --git a/spec/migrations/schedule_fill_valid_time_for_pages_domain_certificates_spec.rb b/spec/migrations/schedule_fill_valid_time_for_pages_domain_certificates_spec.rb index 30cb68c742c..a51bc374d5f 100644 --- a/spec/migrations/schedule_fill_valid_time_for_pages_domain_certificates_spec.rb +++ b/spec/migrations/schedule_fill_valid_time_for_pages_domain_certificates_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20190524073827_schedule_fill_valid_time_for_pages_domain_certificates.rb') -describe ScheduleFillValidTimeForPagesDomainCertificates do +RSpec.describe ScheduleFillValidTimeForPagesDomainCertificates do let(:migration_class) { described_class::MIGRATION } let(:migration_name) { migration_class.to_s.demodulize } diff --git a/spec/migrations/schedule_link_lfs_objects_projects_spec.rb b/spec/migrations/schedule_link_lfs_objects_projects_spec.rb index 055ab3cdd83..04ca18de91f 100644 --- a/spec/migrations/schedule_link_lfs_objects_projects_spec.rb +++ b/spec/migrations/schedule_link_lfs_objects_projects_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20200310075115_schedule_link_lfs_objects_projects.rb') -describe ScheduleLinkLfsObjectsProjects, :migration, :sidekiq do +RSpec.describe ScheduleLinkLfsObjectsProjects, :migration, :sidekiq do let(:namespaces) { table(:namespaces) } let(:projects) { table(:projects) } let(:fork_networks) { table(:fork_networks) } diff --git a/spec/migrations/schedule_merge_request_assignees_migration_progress_check_spec.rb b/spec/migrations/schedule_merge_request_assignees_migration_progress_check_spec.rb index bea985fabb1..0a69f49f10d 100644 --- a/spec/migrations/schedule_merge_request_assignees_migration_progress_check_spec.rb +++ b/spec/migrations/schedule_merge_request_assignees_migration_progress_check_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20190402224749_schedule_merge_request_assignees_migration_progress_check.rb') -describe ScheduleMergeRequestAssigneesMigrationProgressCheck do +RSpec.describe ScheduleMergeRequestAssigneesMigrationProgressCheck do describe '#up' do it 'schedules MergeRequestAssigneesMigrationProgressCheck background job' do expect(BackgroundMigrationWorker).to receive(:perform_async) diff --git a/spec/migrations/schedule_migrate_security_scans_spec.rb b/spec/migrations/schedule_migrate_security_scans_spec.rb index 29e4e2b5cac..4fd17b20666 100644 --- a/spec/migrations/schedule_migrate_security_scans_spec.rb +++ b/spec/migrations/schedule_migrate_security_scans_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20200217225719_schedule_migrate_security_scans.rb') # rubocop: disable RSpec/FactoriesInMigrationSpecs -describe ScheduleMigrateSecurityScans, :sidekiq do +RSpec.describe ScheduleMigrateSecurityScans, :sidekiq do let(:migration) { described_class.new } let(:namespaces) { table(:namespaces) } let(:projects) { table(:projects) } diff --git a/spec/migrations/schedule_pages_metadata_migration_spec.rb b/spec/migrations/schedule_pages_metadata_migration_spec.rb index 748b9fe1cd1..c37e19eb71c 100644 --- a/spec/migrations/schedule_pages_metadata_migration_spec.rb +++ b/spec/migrations/schedule_pages_metadata_migration_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20191002031332_schedule_pages_metadata_migration') -describe SchedulePagesMetadataMigration do +RSpec.describe SchedulePagesMetadataMigration do let(:namespaces) { table(:namespaces) } let(:projects) { table(:projects) } diff --git a/spec/migrations/schedule_populate_merge_request_assignees_table_spec.rb b/spec/migrations/schedule_populate_merge_request_assignees_table_spec.rb index d778b47179f..8b26cd589fd 100644 --- a/spec/migrations/schedule_populate_merge_request_assignees_table_spec.rb +++ b/spec/migrations/schedule_populate_merge_request_assignees_table_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20190322132835_schedule_populate_merge_request_assignees_table.rb') -describe SchedulePopulateMergeRequestAssigneesTable do +RSpec.describe SchedulePopulateMergeRequestAssigneesTable do let(:namespaces) { table(:namespaces) } let(:projects) { table(:projects) } let(:namespace) { namespaces.create(name: 'gitlab', path: 'gitlab-org') } diff --git a/spec/migrations/schedule_populate_project_snippet_statistics_spec.rb b/spec/migrations/schedule_populate_project_snippet_statistics_spec.rb new file mode 100644 index 00000000000..05e9d4d2f79 --- /dev/null +++ b/spec/migrations/schedule_populate_project_snippet_statistics_spec.rb @@ -0,0 +1,61 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20200709101408_schedule_populate_project_snippet_statistics.rb') + +RSpec.describe SchedulePopulateProjectSnippetStatistics do + let(:users) { table(:users) } + let(:snippets) { table(:snippets) } + let(:projects) { table(:projects) } + let(:namespaces) { table(:namespaces) } + let(:user1) { users.create!(id: 1, email: 'user1@example.com', projects_limit: 10, username: 'test1', name: 'Test1', state: 'active') } + let(:user2) { users.create!(id: 2, email: 'user2@example.com', projects_limit: 10, username: 'test2', name: 'Test2', state: 'active') } + let(:namespace1) { namespaces.create!(id: 1, owner_id: user1.id, name: 'user1', path: 'user1') } + let(:namespace2) { namespaces.create!(id: 2, owner_id: user2.id, name: 'user2', path: 'user2') } + let(:project1) { projects.create!(id: 1, namespace_id: namespace1.id) } + let(:project2) { projects.create!(id: 2, namespace_id: namespace1.id) } + let(:project3) { projects.create!(id: 3, namespace_id: namespace2.id) } + + def create_snippet(id, user_id, project_id, type = 'ProjectSnippet') + params = { + id: id, + type: type, + author_id: user_id, + project_id: project_id, + file_name: 'foo', + content: 'bar' + } + + snippets.create!(params) + end + + it 'correctly schedules background migrations' do + # Creating the snippets in different order + create_snippet(1, user1.id, project1.id) + create_snippet(2, user2.id, project3.id) + create_snippet(3, user1.id, project1.id) + create_snippet(4, user1.id, project2.id) + create_snippet(5, user2.id, project3.id) + create_snippet(6, user1.id, project1.id) + # Creating a personal snippet to ensure we don't pick it + create_snippet(7, user1.id, nil, 'PersonalSnippet') + + stub_const("#{described_class}::BATCH_SIZE", 4) + + Sidekiq::Testing.fake! do + Timecop.freeze do + migrate! + + aggregate_failures do + expect(described_class::MIGRATION) + .to be_scheduled_migration([1, 3, 6, 4]) + + expect(described_class::MIGRATION) + .to be_scheduled_delayed_migration(2.minutes, [2, 5]) + + expect(BackgroundMigrationWorker.jobs.size).to eq(2) + end + end + end + end +end diff --git a/spec/migrations/schedule_populate_user_highest_roles_table_spec.rb b/spec/migrations/schedule_populate_user_highest_roles_table_spec.rb index 67e0b994265..c7e5c6f30a6 100644 --- a/spec/migrations/schedule_populate_user_highest_roles_table_spec.rb +++ b/spec/migrations/schedule_populate_user_highest_roles_table_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20200311130802_schedule_populate_user_highest_roles_table.rb') -describe SchedulePopulateUserHighestRolesTable do +RSpec.describe SchedulePopulateUserHighestRolesTable do let(:users) { table(:users) } def create_user(id, params = {}) diff --git a/spec/migrations/schedule_recalculate_project_authorizations_second_run_spec.rb b/spec/migrations/schedule_recalculate_project_authorizations_second_run_spec.rb index 4c05f7d57a1..06f1a7e28eb 100644 --- a/spec/migrations/schedule_recalculate_project_authorizations_second_run_spec.rb +++ b/spec/migrations/schedule_recalculate_project_authorizations_second_run_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20200204113224_schedule_recalculate_project_authorizations_second_run.rb') -describe ScheduleRecalculateProjectAuthorizationsSecondRun do +RSpec.describe ScheduleRecalculateProjectAuthorizationsSecondRun do let(:users_table) { table(:users) } before do diff --git a/spec/migrations/schedule_recalculate_project_authorizations_spec.rb b/spec/migrations/schedule_recalculate_project_authorizations_spec.rb index d30ebf825ef..9519b103284 100644 --- a/spec/migrations/schedule_recalculate_project_authorizations_spec.rb +++ b/spec/migrations/schedule_recalculate_project_authorizations_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20200204113223_schedule_recalculate_project_authorizations.rb') -describe ScheduleRecalculateProjectAuthorizations do +RSpec.describe ScheduleRecalculateProjectAuthorizations do let(:users_table) { table(:users) } let(:namespaces_table) { table(:namespaces) } let(:projects_table) { table(:projects) } diff --git a/spec/migrations/schedule_recalculate_project_authorizations_third_run_spec.rb b/spec/migrations/schedule_recalculate_project_authorizations_third_run_spec.rb index 19ba8984224..300bb940dd8 100644 --- a/spec/migrations/schedule_recalculate_project_authorizations_third_run_spec.rb +++ b/spec/migrations/schedule_recalculate_project_authorizations_third_run_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20200204113225_schedule_recalculate_project_authorizations_third_run.rb') -describe ScheduleRecalculateProjectAuthorizationsThirdRun do +RSpec.describe ScheduleRecalculateProjectAuthorizationsThirdRun do let(:users_table) { table(:users) } before do diff --git a/spec/migrations/schedule_sync_issuables_state_id_spec.rb b/spec/migrations/schedule_sync_issuables_state_id_spec.rb index 408e7e6d19d..ecfebbde348 100644 --- a/spec/migrations/schedule_sync_issuables_state_id_spec.rb +++ b/spec/migrations/schedule_sync_issuables_state_id_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20190214112022_schedule_sync_issuables_state_id.rb') -describe ScheduleSyncIssuablesStateId do +RSpec.describe ScheduleSyncIssuablesStateId do let(:namespaces) { table(:namespaces) } let(:projects) { table(:projects) } let(:merge_requests) { table(:merge_requests) } diff --git a/spec/migrations/schedule_sync_issuables_state_id_where_nil_spec.rb b/spec/migrations/schedule_sync_issuables_state_id_where_nil_spec.rb index e26a864b8ba..d23f5b69d22 100644 --- a/spec/migrations/schedule_sync_issuables_state_id_where_nil_spec.rb +++ b/spec/migrations/schedule_sync_issuables_state_id_where_nil_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20190506135400_schedule_sync_issuables_state_id_where_nil') -describe ScheduleSyncIssuablesStateIdWhereNil do +RSpec.describe ScheduleSyncIssuablesStateIdWhereNil do let(:namespaces) { table(:namespaces) } let(:projects) { table(:projects) } let(:merge_requests) { table(:merge_requests) } diff --git a/spec/migrations/schedule_update_existing_subgroup_to_match_visibility_level_of_parent_spec.rb b/spec/migrations/schedule_update_existing_subgroup_to_match_visibility_level_of_parent_spec.rb index 098fe68927c..949d8d8794f 100644 --- a/spec/migrations/schedule_update_existing_subgroup_to_match_visibility_level_of_parent_spec.rb +++ b/spec/migrations/schedule_update_existing_subgroup_to_match_visibility_level_of_parent_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20200110121314_schedule_update_existing_subgroup_to_match_visibility_level_of_parent.rb') -describe ScheduleUpdateExistingSubgroupToMatchVisibilityLevelOfParent do +RSpec.describe ScheduleUpdateExistingSubgroupToMatchVisibilityLevelOfParent do include MigrationHelpers::NamespacesHelpers let(:migration_class) { described_class::MIGRATION } let(:migration_name) { migration_class.to_s.demodulize } diff --git a/spec/migrations/seed_repository_storages_weighted_spec.rb b/spec/migrations/seed_repository_storages_weighted_spec.rb index 9a68ff5fb2f..fb077a3e345 100644 --- a/spec/migrations/seed_repository_storages_weighted_spec.rb +++ b/spec/migrations/seed_repository_storages_weighted_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20200526000407_seed_repository_storages_weighted.rb') -describe SeedRepositoryStoragesWeighted do +RSpec.describe SeedRepositoryStoragesWeighted do let(:storages) { { "foo" => {}, "baz" => {} } } let(:application_settings) do table(:application_settings).tap do |klass| diff --git a/spec/migrations/services_remove_temporary_index_on_project_id_spec.rb b/spec/migrations/services_remove_temporary_index_on_project_id_spec.rb index d4f9969b71b..6cab4c16cfb 100644 --- a/spec/migrations/services_remove_temporary_index_on_project_id_spec.rb +++ b/spec/migrations/services_remove_temporary_index_on_project_id_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20200203104214_services_remove_temporary_index_on_project_id.rb') -describe ServicesRemoveTemporaryIndexOnProjectId do +RSpec.describe ServicesRemoveTemporaryIndexOnProjectId do let(:migration_instance) { described_class.new } it 'adds and removes temporary partial index in up and down methods' do diff --git a/spec/migrations/set_issue_id_for_all_versions_spec.rb b/spec/migrations/set_issue_id_for_all_versions_spec.rb index ff281947db8..0908d054e70 100644 --- a/spec/migrations/set_issue_id_for_all_versions_spec.rb +++ b/spec/migrations/set_issue_id_for_all_versions_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20190715043954_set_issue_id_for_all_versions.rb') -describe SetIssueIdForAllVersions do +RSpec.describe SetIssueIdForAllVersions do let(:projects) { table(:projects) } let(:issues) { table(:issues) } let(:designs) { table(:design_management_designs) } diff --git a/spec/migrations/sync_issuables_state_id_spec.rb b/spec/migrations/sync_issuables_state_id_spec.rb index 4bd30172cbe..dcddbca6a36 100644 --- a/spec/migrations/sync_issuables_state_id_spec.rb +++ b/spec/migrations/sync_issuables_state_id_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20190911251732_sync_issuables_state_id') -describe SyncIssuablesStateId do +RSpec.describe SyncIssuablesStateId do let(:migration) { described_class.new } describe '#up' do diff --git a/spec/migrations/truncate_user_fullname_spec.rb b/spec/migrations/truncate_user_fullname_spec.rb index a5e6a0a4fce..cb95c222790 100644 --- a/spec/migrations/truncate_user_fullname_spec.rb +++ b/spec/migrations/truncate_user_fullname_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20190325080727_truncate_user_fullname.rb') -describe TruncateUserFullname do +RSpec.describe TruncateUserFullname do let(:users) { table(:users) } let(:user_short) { create_user(name: 'abc', email: 'test_short@example.com') } diff --git a/spec/migrations/unconfirm_wrongfully_verified_emails_spec.rb b/spec/migrations/unconfirm_wrongfully_verified_emails_spec.rb new file mode 100644 index 00000000000..e93f2cb64de --- /dev/null +++ b/spec/migrations/unconfirm_wrongfully_verified_emails_spec.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20200615111857_unconfirm_wrongfully_verified_emails.rb') + +RSpec.describe UnconfirmWrongfullyVerifiedEmails do + before do + user = table(:users).create!(name: 'user1', email: 'test1@test.com', projects_limit: 1) + table(:emails).create!(email: 'test2@test.com', user_id: user.id) + end + + it 'enqueues WrongullyConfirmedEmailUnconfirmer job' do + Sidekiq::Testing.fake! do + migrate! + + jobs = BackgroundMigrationWorker.jobs + expect(jobs.size).to eq(1) + expect(jobs.first["args"].first).to eq(Gitlab::BackgroundMigration::WrongfullyConfirmedEmailUnconfirmer.name.demodulize) + end + end +end diff --git a/spec/migrations/update_application_setting_npm_package_requests_forwarding_default_spec.rb b/spec/migrations/update_application_setting_npm_package_requests_forwarding_default_spec.rb index f9523e0e582..8b241d1b28e 100644 --- a/spec/migrations/update_application_setting_npm_package_requests_forwarding_default_spec.rb +++ b/spec/migrations/update_application_setting_npm_package_requests_forwarding_default_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20200221105436_update_application_setting_npm_package_requests_forwarding_default.rb') -describe UpdateApplicationSettingNpmPackageRequestsForwardingDefault do +RSpec.describe UpdateApplicationSettingNpmPackageRequestsForwardingDefault do # Create test data - pipeline and CI/CD jobs. let(:application_settings) { table(:application_settings) } diff --git a/spec/migrations/update_fingerprint_sha256_within_keys_spec.rb b/spec/migrations/update_fingerprint_sha256_within_keys_spec.rb index d149ec230a7..7f5ae892391 100644 --- a/spec/migrations/update_fingerprint_sha256_within_keys_spec.rb +++ b/spec/migrations/update_fingerprint_sha256_within_keys_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20200106071113_update_fingerprint_sha256_within_keys.rb') -describe UpdateFingerprintSha256WithinKeys do +RSpec.describe UpdateFingerprintSha256WithinKeys do let(:key_table) { table(:keys) } describe '#up' do diff --git a/spec/migrations/update_minimum_password_length_spec.rb b/spec/migrations/update_minimum_password_length_spec.rb index ed9c85362f5..a4485dfbcea 100644 --- a/spec/migrations/update_minimum_password_length_spec.rb +++ b/spec/migrations/update_minimum_password_length_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20191205084057_update_minimum_password_length') -describe UpdateMinimumPasswordLength do +RSpec.describe UpdateMinimumPasswordLength do let(:application_settings) { table(:application_settings) } let(:application_setting) do application_settings.create!( diff --git a/spec/migrations/update_routes_for_lost_and_found_group_and_orphaned_projects_spec.rb b/spec/migrations/update_routes_for_lost_and_found_group_and_orphaned_projects_spec.rb index 103b6f114c4..ffab5c40182 100644 --- a/spec/migrations/update_routes_for_lost_and_found_group_and_orphaned_projects_spec.rb +++ b/spec/migrations/update_routes_for_lost_and_found_group_and_orphaned_projects_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20200602143020_update_routes_for_lost_and_found_group_and_orphaned_projects.rb') -describe UpdateRoutesForLostAndFoundGroupAndOrphanedProjects, :migration do +RSpec.describe UpdateRoutesForLostAndFoundGroupAndOrphanedProjects, :migration do let(:users) { table(:users) } let(:namespaces) { table(:namespaces) } let(:members) { table(:members) } diff --git a/spec/migrations/update_timestamp_softwarelicensespolicy_spec.rb b/spec/migrations/update_timestamp_softwarelicensespolicy_spec.rb index 918c5fb567f..f55d55f94c7 100644 --- a/spec/migrations/update_timestamp_softwarelicensespolicy_spec.rb +++ b/spec/migrations/update_timestamp_softwarelicensespolicy_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20200116175538_update_timestamp_softwarelicensespolicy.rb') -describe UpdateTimestampSoftwarelicensespolicy do +RSpec.describe UpdateTimestampSoftwarelicensespolicy do let(:software_licenses_policy) { table(:software_license_policies) } let(:projects) { table(:projects) } let(:licenses) { table(:software_licenses) } |