summaryrefslogtreecommitdiff
path: root/spec/migrations
diff options
context:
space:
mode:
Diffstat (limited to 'spec/migrations')
-rw-r--r--spec/migrations/20190924152703_migrate_issue_trackers_data_spec.rb16
-rw-r--r--spec/migrations/20200122123016_backfill_project_settings_spec.rb10
-rw-r--r--spec/migrations/20200123155929_remove_invalid_jira_data_spec.rb22
-rw-r--r--spec/migrations/20200127090233_remove_invalid_issue_tracker_data_spec.rb18
-rw-r--r--spec/migrations/20200130145430_reschedule_migrate_issue_trackers_data_spec.rb24
-rw-r--r--spec/migrations/20200313203550_remove_orphaned_chat_names_spec.rb6
-rw-r--r--spec/migrations/20200406102120_backfill_deployment_clusters_from_deployments_spec.rb10
-rw-r--r--spec/migrations/20200526115436_dedup_mr_metrics_spec.rb12
-rw-r--r--spec/migrations/add_deploy_token_type_to_deploy_tokens_spec.rb2
-rw-r--r--spec/migrations/add_incident_settings_to_all_existing_projects_spec.rb2
-rw-r--r--spec/migrations/add_unique_constraint_to_approvals_user_id_and_merge_request_id_spec.rb12
-rw-r--r--spec/migrations/backfill_and_add_not_null_constraint_to_released_at_column_on_releases_table_spec.rb2
-rw-r--r--spec/migrations/backfill_imported_snippet_repositories_spec.rb2
-rw-r--r--spec/migrations/backfill_releases_table_updated_at_and_add_not_null_constraints_to_timestamps_spec.rb4
-rw-r--r--spec/migrations/backfill_snippet_repositories_spec.rb2
-rw-r--r--spec/migrations/encrypt_plaintext_attributes_on_application_settings_spec.rb4
-rw-r--r--spec/migrations/enqueue_reset_merge_status_second_run_spec.rb4
-rw-r--r--spec/migrations/enqueue_reset_merge_status_spec.rb4
-rw-r--r--spec/migrations/ensure_namespace_settings_creation_spec.rb2
-rw-r--r--spec/migrations/ensure_u2f_registrations_migrated_spec.rb41
-rw-r--r--spec/migrations/fill_file_store_lfs_objects_spec.rb6
-rw-r--r--spec/migrations/fill_store_uploads_spec.rb6
-rw-r--r--spec/migrations/fix_null_type_labels_spec.rb12
-rw-r--r--spec/migrations/fix_pool_repository_source_project_id_spec.rb4
-rw-r--r--spec/migrations/fix_projects_without_project_feature_spec.rb8
-rw-r--r--spec/migrations/fix_projects_without_prometheus_services_spec.rb8
-rw-r--r--spec/migrations/fix_wrong_pages_access_level_spec.rb2
-rw-r--r--spec/migrations/insert_project_hooks_plan_limits_spec.rb10
-rw-r--r--spec/migrations/migrate_auto_dev_ops_domain_to_cluster_domain_spec.rb2
-rw-r--r--spec/migrations/move_limits_from_plans_spec.rb10
-rw-r--r--spec/migrations/populate_project_statistics_packages_size_spec.rb2
-rw-r--r--spec/migrations/populate_remaining_missing_dismissal_information_for_vulnerabilities_spec.rb31
-rw-r--r--spec/migrations/remove_orphan_service_hooks_spec.rb26
-rw-r--r--spec/migrations/schedule_link_lfs_objects_projects_spec.rb34
-rw-r--r--spec/migrations/schedule_populate_merge_request_assignees_table_spec.rb4
-rw-r--r--spec/migrations/schedule_repopulate_historical_vulnerability_statistics_spec.rb36
-rw-r--r--spec/migrations/schedule_update_existing_users_that_require_two_factor_auth_spec.rb29
-rw-r--r--spec/migrations/seed_repository_storages_weighted_spec.rb2
-rw-r--r--spec/migrations/update_internal_ids_last_value_for_epics_renamed_spec.rb30
39 files changed, 327 insertions, 134 deletions
diff --git a/spec/migrations/20190924152703_migrate_issue_trackers_data_spec.rb b/spec/migrations/20190924152703_migrate_issue_trackers_data_spec.rb
index 11398685549..47f85df01ac 100644
--- a/spec/migrations/20190924152703_migrate_issue_trackers_data_spec.rb
+++ b/spec/migrations/20190924152703_migrate_issue_trackers_data_spec.rb
@@ -15,35 +15,35 @@ RSpec.describe MigrateIssueTrackersData do
end
let!(:jira_service) do
- services.create(type: 'JiraService', properties: properties, category: 'issue_tracker')
+ services.create!(type: 'JiraService', properties: properties, category: 'issue_tracker')
end
let!(:jira_service_nil) do
- services.create(type: 'JiraService', properties: nil, category: 'issue_tracker')
+ services.create!(type: 'JiraService', properties: nil, category: 'issue_tracker')
end
let!(:bugzilla_service) do
- services.create(type: 'BugzillaService', properties: properties, category: 'issue_tracker')
+ services.create!(type: 'BugzillaService', properties: properties, category: 'issue_tracker')
end
let!(:youtrack_service) do
- services.create(type: 'YoutrackService', properties: properties, category: 'issue_tracker')
+ services.create!(type: 'YoutrackService', properties: properties, category: 'issue_tracker')
end
let!(:youtrack_service_empty) do
- services.create(type: 'YoutrackService', properties: '', category: 'issue_tracker')
+ services.create!(type: 'YoutrackService', properties: '', category: 'issue_tracker')
end
let!(:gitlab_service) do
- services.create(type: 'GitlabIssueTrackerService', properties: properties, category: 'issue_tracker')
+ services.create!(type: 'GitlabIssueTrackerService', properties: properties, category: 'issue_tracker')
end
let!(:gitlab_service_empty) do
- services.create(type: 'GitlabIssueTrackerService', properties: {}, category: 'issue_tracker')
+ services.create!(type: 'GitlabIssueTrackerService', properties: {}, category: 'issue_tracker')
end
let!(:other_service) do
- services.create(type: 'OtherService', properties: properties, category: 'other_category')
+ services.create!(type: 'OtherService', properties: properties, category: 'other_category')
end
before do
diff --git a/spec/migrations/20200122123016_backfill_project_settings_spec.rb b/spec/migrations/20200122123016_backfill_project_settings_spec.rb
index 60c6206a83b..9ae492a36aa 100644
--- a/spec/migrations/20200122123016_backfill_project_settings_spec.rb
+++ b/spec/migrations/20200122123016_backfill_project_settings_spec.rb
@@ -5,16 +5,16 @@ require Rails.root.join('db', 'post_migrate', '20200122123016_backfill_project_s
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) }
+ let(:namespace) { table(:namespaces).create!(name: 'user', path: 'user') }
+ let(:project) { projects.create!(namespace_id: namespace.id) }
describe '#up' do
before do
stub_const("#{described_class}::BATCH_SIZE", 2)
- projects.create(id: 1, namespace_id: namespace.id)
- projects.create(id: 2, namespace_id: namespace.id)
- projects.create(id: 3, namespace_id: namespace.id)
+ projects.create!(id: 1, namespace_id: namespace.id)
+ projects.create!(id: 2, namespace_id: namespace.id)
+ projects.create!(id: 3, namespace_id: namespace.id)
end
it 'schedules BackfillProjectSettings background jobs' do
diff --git a/spec/migrations/20200123155929_remove_invalid_jira_data_spec.rb b/spec/migrations/20200123155929_remove_invalid_jira_data_spec.rb
index e69a30752db..a6ef0b29461 100644
--- a/spec/migrations/20200123155929_remove_invalid_jira_data_spec.rb
+++ b/spec/migrations/20200123155929_remove_invalid_jira_data_spec.rb
@@ -7,7 +7,7 @@ RSpec.describe RemoveInvalidJiraData do
let(:jira_tracker_data) { table(:jira_tracker_data) }
let(:services) { table(:services) }
- let(:service) { services.create(id: 1) }
+ let(:service) { services.create!(id: 1) }
let(:data) do
{
service_id: service.id,
@@ -22,49 +22,49 @@ RSpec.describe RemoveInvalidJiraData do
}
end
- let!(:valid_data) { jira_tracker_data.create(data) }
- let!(:empty_data) { jira_tracker_data.create(service_id: service.id) }
+ let!(:valid_data) { jira_tracker_data.create!(data) }
+ let!(:empty_data) { jira_tracker_data.create!(service_id: service.id) }
let!(:invalid_api_url) do
data[:encrypted_api_url_iv] = nil
- jira_tracker_data.create(data)
+ jira_tracker_data.create!(data)
end
let!(:missing_api_url) do
data[:encrypted_api_url] = ''
data[:encrypted_api_url_iv] = nil
- jira_tracker_data.create(data)
+ jira_tracker_data.create!(data)
end
let!(:invalid_url) do
data[:encrypted_url_iv] = nil
- jira_tracker_data.create(data)
+ jira_tracker_data.create!(data)
end
let!(:missing_url) do
data[:encrypted_url] = ''
- jira_tracker_data.create(data)
+ jira_tracker_data.create!(data)
end
let!(:invalid_username) do
data[:encrypted_username_iv] = nil
- jira_tracker_data.create(data)
+ jira_tracker_data.create!(data)
end
let!(:missing_username) do
data[:encrypted_username] = nil
data[:encrypted_username_iv] = nil
- jira_tracker_data.create(data)
+ jira_tracker_data.create!(data)
end
let!(:invalid_password) do
data[:encrypted_password_iv] = nil
- jira_tracker_data.create(data)
+ jira_tracker_data.create!(data)
end
let!(:missing_password) do
data[:encrypted_password] = nil
data[:encrypted_username_iv] = nil
- jira_tracker_data.create(data)
+ jira_tracker_data.create!(data)
end
it 'removes the invalid data' do
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 e7917cf5d72..9ddf188b15e 100644
--- a/spec/migrations/20200127090233_remove_invalid_issue_tracker_data_spec.rb
+++ b/spec/migrations/20200127090233_remove_invalid_issue_tracker_data_spec.rb
@@ -7,7 +7,7 @@ RSpec.describe RemoveInvalidIssueTrackerData do
let(:issue_tracker_data) { table(:issue_tracker_data) }
let(:services) { table(:services) }
- let(:service) { services.create(id: 1) }
+ let(:service) { services.create!(id: 1) }
let(:data) do
{
service_id: service.id,
@@ -20,38 +20,38 @@ RSpec.describe RemoveInvalidIssueTrackerData do
}
end
- let!(:valid_data) { issue_tracker_data.create(data) }
- let!(:empty_data) { issue_tracker_data.create(service_id: service.id) }
+ let!(:valid_data) { issue_tracker_data.create!(data) }
+ let!(:empty_data) { issue_tracker_data.create!(service_id: service.id) }
let!(:invalid_issues_url) do
data[:encrypted_issues_url_iv] = nil
- issue_tracker_data.create(data)
+ issue_tracker_data.create!(data)
end
let!(:missing_issues_url) do
data[:encrypted_issues_url] = ''
data[:encrypted_issues_url_iv] = nil
- issue_tracker_data.create(data)
+ issue_tracker_data.create!(data)
end
let!(:invalid_new_isue_url) do
data[:encrypted_new_issue_url_iv] = nil
- issue_tracker_data.create(data)
+ issue_tracker_data.create!(data)
end
let!(:missing_new_issue_url) do
data[:encrypted_new_issue_url] = ''
- issue_tracker_data.create(data)
+ issue_tracker_data.create!(data)
end
let!(:invalid_project_url) do
data[:encrypted_project_url_iv] = nil
- issue_tracker_data.create(data)
+ issue_tracker_data.create!(data)
end
let!(:missing_project_url) do
data[:encrypted_project_url] = nil
data[:encrypted_project_url_iv] = nil
- issue_tracker_data.create(data)
+ issue_tracker_data.create!(data)
end
it 'removes the invalid data' do
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 e140be476ab..9947718d11b 100644
--- a/spec/migrations/20200130145430_reschedule_migrate_issue_trackers_data_spec.rb
+++ b/spec/migrations/20200130145430_reschedule_migrate_issue_trackers_data_spec.rb
@@ -15,35 +15,35 @@ RSpec.describe RescheduleMigrateIssueTrackersData do
end
let!(:jira_service) do
- services.create(id: 10, type: 'JiraService', properties: properties, category: 'issue_tracker')
+ services.create!(id: 10, type: 'JiraService', properties: properties, category: 'issue_tracker')
end
let!(:jira_service_nil) do
- services.create(id: 11, type: 'JiraService', properties: nil, category: 'issue_tracker')
+ services.create!(id: 11, type: 'JiraService', properties: nil, category: 'issue_tracker')
end
let!(:bugzilla_service) do
- services.create(id: 12, type: 'BugzillaService', properties: properties, category: 'issue_tracker')
+ services.create!(id: 12, type: 'BugzillaService', properties: properties, category: 'issue_tracker')
end
let!(:youtrack_service) do
- services.create(id: 13, type: 'YoutrackService', properties: properties, category: 'issue_tracker')
+ services.create!(id: 13, type: 'YoutrackService', properties: properties, category: 'issue_tracker')
end
let!(:youtrack_service_empty) do
- services.create(id: 14, type: 'YoutrackService', properties: '', category: 'issue_tracker')
+ services.create!(id: 14, type: 'YoutrackService', properties: '', category: 'issue_tracker')
end
let!(:gitlab_service) do
- services.create(id: 15, type: 'GitlabIssueTrackerService', properties: properties, category: 'issue_tracker')
+ services.create!(id: 15, type: 'GitlabIssueTrackerService', properties: properties, category: 'issue_tracker')
end
let!(:gitlab_service_empty) do
- services.create(id: 16, type: 'GitlabIssueTrackerService', properties: {}, category: 'issue_tracker')
+ services.create!(id: 16, type: 'GitlabIssueTrackerService', properties: {}, category: 'issue_tracker')
end
let!(:other_service) do
- services.create(id: 17, type: 'OtherService', properties: properties, category: 'other_category')
+ services.create!(id: 17, type: 'OtherService', properties: properties, category: 'other_category')
end
before do
@@ -69,7 +69,7 @@ RSpec.describe RescheduleMigrateIssueTrackersData do
let(:jira_tracker_data) { table(:jira_tracker_data) }
let!(:valid_issue_tracker_data) do
- issue_tracker_data.create(
+ issue_tracker_data.create!(
service_id: bugzilla_service.id,
encrypted_issues_url: 'http://url.com',
encrypted_issues_url_iv: 'somevalue'
@@ -77,7 +77,7 @@ RSpec.describe RescheduleMigrateIssueTrackersData do
end
let!(:invalid_issue_tracker_data) do
- issue_tracker_data.create(
+ issue_tracker_data.create!(
service_id: bugzilla_service.id,
encrypted_issues_url: 'http:url.com',
encrypted_issues_url_iv: nil
@@ -85,7 +85,7 @@ RSpec.describe RescheduleMigrateIssueTrackersData do
end
let!(:valid_jira_tracker_data) do
- jira_tracker_data.create(
+ jira_tracker_data.create!(
service_id: bugzilla_service.id,
encrypted_url: 'http://url.com',
encrypted_url_iv: 'somevalue'
@@ -93,7 +93,7 @@ RSpec.describe RescheduleMigrateIssueTrackersData do
end
let!(:invalid_jira_tracker_data) do
- jira_tracker_data.create(
+ jira_tracker_data.create!(
service_id: bugzilla_service.id,
encrypted_url: 'http://url.com',
encrypted_url_iv: nil
diff --git a/spec/migrations/20200313203550_remove_orphaned_chat_names_spec.rb b/spec/migrations/20200313203550_remove_orphaned_chat_names_spec.rb
index d9ce62fe475..f16e7b483e9 100644
--- a/spec/migrations/20200313203550_remove_orphaned_chat_names_spec.rb
+++ b/spec/migrations/20200313203550_remove_orphaned_chat_names_spec.rb
@@ -9,9 +9,9 @@ RSpec.describe RemoveOrphanedChatNames, schema: 20200313202430 do
let(:services) { table(:services) }
let(:chat_names) { table(:chat_names) }
- let(:namespace) { namespaces.create(name: 'foo', path: 'foo') }
- let(:project) { projects.create(namespace_id: namespace.id) }
- let(:service) { services.create(project_id: project.id, type: 'chat') }
+ let(:namespace) { namespaces.create!(name: 'foo', path: 'foo') }
+ let(:project) { projects.create!(namespace_id: namespace.id) }
+ let(:service) { services.create!(project_id: project.id, type: 'chat') }
let(:chat_name) { chat_names.create!(service_id: service.id, team_id: 'TEAM', user_id: 12345, chat_id: 12345) }
let(:orphaned_chat_name) { chat_names.create!(team_id: 'TEAM', service_id: 0, user_id: 12345, chat_id: 12345) }
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 c6b221b09a5..9950cc23889 100644
--- a/spec/migrations/20200406102120_backfill_deployment_clusters_from_deployments_spec.rb
+++ b/spec/migrations/20200406102120_backfill_deployment_clusters_from_deployments_spec.rb
@@ -8,10 +8,10 @@ RSpec.describe BackfillDeploymentClustersFromDeployments, :migration, :sidekiq,
it 'schedules BackfillDeploymentClustersFromDeployments background jobs' do
stub_const("#{described_class}::BATCH_SIZE", 2)
- namespace = table(:namespaces).create(name: 'the-namespace', path: 'the-path')
- project = table(:projects).create(name: 'the-project', namespace_id: namespace.id)
- environment = table(:environments).create(name: 'the-environment', project_id: project.id, slug: 'slug')
- cluster = table(:clusters).create(name: 'the-cluster')
+ namespace = table(:namespaces).create!(name: 'the-namespace', path: 'the-path')
+ project = table(:projects).create!(name: 'the-project', namespace_id: namespace.id)
+ environment = table(:environments).create!(name: 'the-environment', project_id: project.id, slug: 'slug')
+ cluster = table(:clusters).create!(name: 'the-cluster')
deployment_data = { cluster_id: cluster.id, project_id: project.id, environment_id: environment.id, ref: 'abc', tag: false, sha: 'sha', status: 1 }
@@ -44,7 +44,7 @@ RSpec.describe BackfillDeploymentClustersFromDeployments, :migration, :sidekiq,
def create_deployment(**data)
@iid ||= 0
@iid += 1
- table(:deployments).create(iid: @iid, **data)
+ table(:deployments).create!(iid: @iid, **data)
end
end
end
diff --git a/spec/migrations/20200526115436_dedup_mr_metrics_spec.rb b/spec/migrations/20200526115436_dedup_mr_metrics_spec.rb
index f2698a0f352..9d3851ed5b0 100644
--- a/spec/migrations/20200526115436_dedup_mr_metrics_spec.rb
+++ b/spec/migrations/20200526115436_dedup_mr_metrics_spec.rb
@@ -10,19 +10,19 @@ RSpec.describe DedupMrMetrics, :migration, schema: 20200526013844 do
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!(: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_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!(: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) }
+ 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)
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 f1fe27e72a1..b33320c922a 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
@@ -6,7 +6,7 @@ require Rails.root.join('db', 'migrate', '20200122161638_add_deploy_token_type_t
RSpec.describe AddDeployTokenTypeToDeployTokens do
let(:deploy_tokens) { table(:deploy_tokens) }
let(:deploy_token) do
- deploy_tokens.create(name: 'token_test',
+ deploy_tokens.create!(name: 'token_test',
username: 'gitlab+deploy-token-1',
token_encrypted: 'dr8rPXwM+Mbs2p3Bg1+gpnXqrnH/wu6vaHdcc7A3isPR67WB',
read_repository: true,
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 dab42c0ffc3..a62fc43df02 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
@@ -38,7 +38,7 @@ RSpec.describe AddIncidentSettingsToAllExistingProjects, :migration do
RSpec.shared_context 'with incident settings' do
let(:existing_create_issue) { false }
before do
- project_incident_management_settings.create(
+ project_incident_management_settings.create!(
project_id: project.id,
create_issue: existing_create_issue
)
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 6c04be5fc60..391bc59cdc0 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
@@ -12,15 +12,15 @@ RSpec.describe AddUniqueConstraintToApprovalsUserIdAndMergeRequestId do
describe '#up' do
before do
- namespaces.create(id: 1, name: 'ns', path: 'ns')
- projects.create(id: 1, namespace_id: 1)
- merge_requests.create(id: 1, target_branch: 'master', source_branch: 'feature-1', target_project_id: 1)
- merge_requests.create(id: 2, target_branch: 'master', source_branch: 'feature-2', target_project_id: 1)
+ namespaces.create!(id: 1, name: 'ns', path: 'ns')
+ projects.create!(id: 1, namespace_id: 1)
+ merge_requests.create!(id: 1, target_branch: 'master', source_branch: 'feature-1', target_project_id: 1)
+ merge_requests.create!(id: 2, target_branch: 'master', source_branch: 'feature-2', target_project_id: 1)
end
it 'deletes duplicate records and keeps the first one' do
- first_approval = approvals.create(id: 1, merge_request_id: 1, user_id: 1)
- approvals.create(id: 2, merge_request_id: 1, user_id: 1)
+ first_approval = approvals.create!(id: 1, merge_request_id: 1, user_id: 1)
+ approvals.create!(id: 2, merge_request_id: 1, user_id: 1)
migration.up
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 9d0ad5863c6..6c782af9a31 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
@@ -13,7 +13,7 @@ RSpec.describe BackfillAndAddNotNullConstraintToReleasedAtColumnOnReleasesTable
it 'fills released_at with the value of created_at' do
created_at_a = Time.zone.parse('2019-02-10T08:00:00Z')
created_at_b = Time.zone.parse('2019-03-10T18:00:00Z')
- namespace = namespaces.create(name: 'foo', path: 'foo')
+ namespace = namespaces.create!(name: 'foo', path: 'foo')
project = projects.create!(namespace_id: namespace.id)
release_a = releases.create!(project_id: project.id, created_at: created_at_a)
release_b = releases.create!(project_id: project.id, created_at: created_at_b)
diff --git a/spec/migrations/backfill_imported_snippet_repositories_spec.rb b/spec/migrations/backfill_imported_snippet_repositories_spec.rb
index 998a691bf77..356551f176e 100644
--- a/spec/migrations/backfill_imported_snippet_repositories_spec.rb
+++ b/spec/migrations/backfill_imported_snippet_repositories_spec.rb
@@ -6,7 +6,7 @@ require Rails.root.join('db', 'post_migrate', '20200608072931_backfill_imported_
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') }
+ let(:user) { users.create!(id: 1, email: 'user@example.com', projects_limit: 10, username: 'test', name: 'Test', state: 'active') }
def create_snippet(id)
params = {
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 4c3517bc574..22c93d37816 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
@@ -13,7 +13,7 @@ RSpec.describe BackfillReleasesTableUpdatedAtAndAddNotNullConstraintsToTimestamp
it 'fills null updated_at rows with the value of created_at' do
created_at_a = Time.zone.parse('2014-03-11T04:30:00Z')
created_at_b = Time.zone.parse('2019-09-10T12:00:00Z')
- namespace = namespaces.create(name: 'foo', path: 'foo')
+ namespace = namespaces.create!(name: 'foo', path: 'foo')
project = projects.create!(namespace_id: namespace.id)
release_a = releases.create!(project_id: project.id,
released_at: Time.zone.parse('2014-12-10T06:00:00Z'),
@@ -36,7 +36,7 @@ RSpec.describe BackfillReleasesTableUpdatedAtAndAddNotNullConstraintsToTimestamp
created_at_a = Time.zone.parse('2014-03-11T04:30:00Z')
updated_at_a = Time.zone.parse('2015-01-16T10:00:00Z')
created_at_b = Time.zone.parse('2019-09-10T12:00:00Z')
- namespace = namespaces.create(name: 'foo', path: 'foo')
+ namespace = namespaces.create!(name: 'foo', path: 'foo')
project = projects.create!(namespace_id: namespace.id)
release_a = releases.create!(project_id: project.id,
released_at: Time.zone.parse('2014-12-10T06:00:00Z'),
diff --git a/spec/migrations/backfill_snippet_repositories_spec.rb b/spec/migrations/backfill_snippet_repositories_spec.rb
index 6d417669ad6..b176b8d49ec 100644
--- a/spec/migrations/backfill_snippet_repositories_spec.rb
+++ b/spec/migrations/backfill_snippet_repositories_spec.rb
@@ -6,7 +6,7 @@ require Rails.root.join('db', 'post_migrate', '20200420094444_backfill_snippet_r
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') }
+ let(:user) { users.create!(id: 1, email: 'user@example.com', projects_limit: 10, username: 'test', name: 'Test', state: 'active') }
def create_snippet(id)
params = {
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 ff5aa81b5b5..7cd3646d107 100644
--- a/spec/migrations/encrypt_plaintext_attributes_on_application_settings_spec.rb
+++ b/spec/migrations/encrypt_plaintext_attributes_on_application_settings_spec.rb
@@ -19,7 +19,7 @@ RSpec.describe EncryptPlaintextAttributesOnApplicationSettings do
describe '#up' do
it 'encrypts token and saves it' do
- application_setting = application_settings.create
+ application_setting = application_settings.create!
application_setting.update_columns(
plaintext_attributes.each_with_object({}) do |plaintext_attribute, attributes|
attributes[plaintext_attribute] = plaintext
@@ -39,7 +39,7 @@ RSpec.describe EncryptPlaintextAttributesOnApplicationSettings do
describe '#down' do
it 'decrypts encrypted token and saves it' do
- application_setting = application_settings.create(
+ application_setting = application_settings.create!(
plaintext_attributes.each_with_object({}) do |plaintext_attribute, attributes|
attributes[plaintext_attribute] = plaintext
end
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 d4189326366..2bbc67c4db3 100644
--- a/spec/migrations/enqueue_reset_merge_status_second_run_spec.rb
+++ b/spec/migrations/enqueue_reset_merge_status_second_run_spec.rb
@@ -6,8 +6,8 @@ require Rails.root.join('db', 'post_migrate', '20190620112608_enqueue_reset_merg
RSpec.describe EnqueueResetMergeStatusSecondRun do
let(:namespaces) { table(:namespaces) }
let(:projects) { table(:projects) }
- let(:namespace) { namespaces.create(name: 'gitlab', path: 'gitlab-org') }
- let(:project) { projects.create(namespace_id: namespace.id, name: 'foo') }
+ let(:namespace) { namespaces.create!(name: 'gitlab', path: 'gitlab-org') }
+ let(:project) { projects.create!(namespace_id: namespace.id, name: 'foo') }
let(:merge_requests) { table(:merge_requests) }
def create_merge_request(id, extra_params = {})
diff --git a/spec/migrations/enqueue_reset_merge_status_spec.rb b/spec/migrations/enqueue_reset_merge_status_spec.rb
index c581293ddcd..0843bbacd5f 100644
--- a/spec/migrations/enqueue_reset_merge_status_spec.rb
+++ b/spec/migrations/enqueue_reset_merge_status_spec.rb
@@ -6,8 +6,8 @@ require Rails.root.join('db', 'post_migrate', '20190528180441_enqueue_reset_merg
RSpec.describe EnqueueResetMergeStatus do
let(:namespaces) { table(:namespaces) }
let(:projects) { table(:projects) }
- let(:namespace) { namespaces.create(name: 'gitlab', path: 'gitlab-org') }
- let(:project) { projects.create(namespace_id: namespace.id, name: 'foo') }
+ let(:namespace) { namespaces.create!(name: 'gitlab', path: 'gitlab-org') }
+ let(:project) { projects.create!(namespace_id: namespace.id, name: 'foo') }
let(:merge_requests) { table(:merge_requests) }
def create_merge_request(id, extra_params = {})
diff --git a/spec/migrations/ensure_namespace_settings_creation_spec.rb b/spec/migrations/ensure_namespace_settings_creation_spec.rb
index 8574063f7fe..cececc1e569 100644
--- a/spec/migrations/ensure_namespace_settings_creation_spec.rb
+++ b/spec/migrations/ensure_namespace_settings_creation_spec.rb
@@ -23,7 +23,7 @@ RSpec.describe EnsureNamespaceSettingsCreation do
end
end
- it 'schedules migrations in batches ' do
+ it 'schedules migrations in batches' do
stub_const("#{described_class.name}::BATCH_SIZE", 2)
namespace_3 = namespaces.create!(name: 'gitlab', path: 'gitlab-org3')
diff --git a/spec/migrations/ensure_u2f_registrations_migrated_spec.rb b/spec/migrations/ensure_u2f_registrations_migrated_spec.rb
new file mode 100644
index 00000000000..77eab3b829a
--- /dev/null
+++ b/spec/migrations/ensure_u2f_registrations_migrated_spec.rb
@@ -0,0 +1,41 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require Rails.root.join('db', 'post_migrate', '20201026185514_ensure_u2f_registrations_migrated.rb')
+
+RSpec.describe EnsureU2fRegistrationsMigrated, schema: 20201022144501 do
+ let(:u2f_registrations) { table(:u2f_registrations) }
+ let(:webauthn_registrations) { table(:webauthn_registrations) }
+ let(:users) { table(:users) }
+
+ let(:user) { users.create!(email: 'email@email.com', name: 'foo', username: 'foo', projects_limit: 0) }
+
+ before do
+ create_u2f_registration(1, 'reg1')
+ create_u2f_registration(2, 'reg2')
+ webauthn_registrations.create!({ name: 'reg1', u2f_registration_id: 1, credential_xid: '', public_key: '', user_id: user.id })
+ end
+
+ it 'correctly migrates u2f registrations previously not migrated' do
+ expect { migrate! }.to change { webauthn_registrations.count }.from(1).to(2)
+ end
+
+ it 'migrates all valid u2f registrations depite errors' do
+ create_u2f_registration(3, 'reg3', 'invalid!')
+ create_u2f_registration(4, 'reg4')
+
+ expect { migrate! }.to change { webauthn_registrations.count }.from(1).to(3)
+ end
+
+ def create_u2f_registration(id, name, public_key = nil)
+ device = U2F::FakeU2F.new(FFaker::BaconIpsum.characters(5), { key_handle: SecureRandom.random_bytes(255) })
+ public_key ||= Base64.strict_encode64(device.origin_public_key_raw)
+ u2f_registrations.create!({ id: id,
+ certificate: Base64.strict_encode64(device.cert_raw),
+ key_handle: U2F.urlsafe_encode64(device.key_handle_raw),
+ public_key: public_key,
+ counter: 5,
+ name: name,
+ user_id: user.id })
+ end
+end
diff --git a/spec/migrations/fill_file_store_lfs_objects_spec.rb b/spec/migrations/fill_file_store_lfs_objects_spec.rb
index 2a610e5311b..23063cc9cd0 100644
--- a/spec/migrations/fill_file_store_lfs_objects_spec.rb
+++ b/spec/migrations/fill_file_store_lfs_objects_spec.rb
@@ -9,7 +9,7 @@ RSpec.describe FillFileStoreLfsObjects do
context 'when file_store is nil' do
it 'updates file_store to local' do
- lfs_objects.create(oid: oid, size: 1062, file_store: nil)
+ lfs_objects.create!(oid: oid, size: 1062, file_store: nil)
lfs_object = lfs_objects.find_by(oid: oid)
expect { migrate! }.to change { lfs_object.reload.file_store }.from(nil).to(1)
@@ -18,7 +18,7 @@ RSpec.describe FillFileStoreLfsObjects do
context 'when file_store is set to local' do
it 'does not update file_store' do
- lfs_objects.create(oid: oid, size: 1062, file_store: 1)
+ lfs_objects.create!(oid: oid, size: 1062, file_store: 1)
lfs_object = lfs_objects.find_by(oid: oid)
expect { migrate! }.not_to change { lfs_object.reload.file_store }
@@ -27,7 +27,7 @@ RSpec.describe FillFileStoreLfsObjects do
context 'when file_store is set to object storage' do
it 'does not update file_store' do
- lfs_objects.create(oid: oid, size: 1062, file_store: 2)
+ lfs_objects.create!(oid: oid, size: 1062, file_store: 2)
lfs_object = lfs_objects.find_by(oid: oid)
expect { migrate! }.not_to change { lfs_object.reload.file_store }
diff --git a/spec/migrations/fill_store_uploads_spec.rb b/spec/migrations/fill_store_uploads_spec.rb
index 60eaf982c57..bcb5d45e1c0 100644
--- a/spec/migrations/fill_store_uploads_spec.rb
+++ b/spec/migrations/fill_store_uploads_spec.rb
@@ -9,7 +9,7 @@ RSpec.describe FillStoreUploads do
context 'when store is nil' do
it 'updates store to local' do
- uploads.create(size: 100.kilobytes,
+ uploads.create!(size: 100.kilobytes,
uploader: 'AvatarUploader',
path: path,
store: nil)
@@ -22,7 +22,7 @@ RSpec.describe FillStoreUploads do
context 'when store is set to local' do
it 'does not update store' do
- uploads.create(size: 100.kilobytes,
+ uploads.create!(size: 100.kilobytes,
uploader: 'AvatarUploader',
path: path,
store: 1)
@@ -35,7 +35,7 @@ RSpec.describe FillStoreUploads do
context 'when store is set to object storage' do
it 'does not update store' do
- uploads.create(size: 100.kilobytes,
+ uploads.create!(size: 100.kilobytes,
uploader: 'AvatarUploader',
path: path,
store: 2)
diff --git a/spec/migrations/fix_null_type_labels_spec.rb b/spec/migrations/fix_null_type_labels_spec.rb
index fadc2a5d29e..b3fc0e30687 100644
--- a/spec/migrations/fix_null_type_labels_spec.rb
+++ b/spec/migrations/fix_null_type_labels_spec.rb
@@ -10,14 +10,14 @@ RSpec.describe FixNullTypeLabels do
let(:labels) { table(:labels) }
before do
- group = namespaces.create(name: 'labels-test-project', path: 'labels-test-project', type: 'Group')
+ group = namespaces.create!(name: 'labels-test-project', path: 'labels-test-project', type: 'Group')
project = projects.create!(namespace_id: group.id, name: 'labels-test-group', path: 'labels-test-group')
- @template_label = labels.create(title: 'template', template: true)
- @project_label = labels.create(title: 'project label', project_id: project.id, type: 'ProjectLabel')
- @group_label = labels.create(title: 'group_label', group_id: group.id, type: 'GroupLabel')
- @broken_label_1 = labels.create(title: 'broken 1', project_id: project.id)
- @broken_label_2 = labels.create(title: 'broken 2', project_id: project.id)
+ @template_label = labels.create!(title: 'template', template: true)
+ @project_label = labels.create!(title: 'project label', project_id: project.id, type: 'ProjectLabel')
+ @group_label = labels.create!(title: 'group_label', group_id: group.id, type: 'GroupLabel')
+ @broken_label_1 = labels.create!(title: 'broken 1', project_id: project.id)
+ @broken_label_2 = labels.create!(title: 'broken 2', project_id: project.id)
end
describe '#up' do
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 67a75b893ef..3413cef3c8b 100644
--- a/spec/migrations/fix_pool_repository_source_project_id_spec.rb
+++ b/spec/migrations/fix_pool_repository_source_project_id_spec.rb
@@ -13,11 +13,11 @@ RSpec.describe FixPoolRepositorySourceProjectId do
# gitaly is a project with a pool repository that has a source_project_id
gitaly = projects.create!(name: 'gitaly', path: 'gitlab-org/gitaly', namespace_id: 1)
- pool_repository = pool_repositories.create(shard_id: shard.id, source_project_id: gitaly.id)
+ pool_repository = pool_repositories.create!(shard_id: shard.id, source_project_id: gitaly.id)
gitaly.update_column(:pool_repository_id, pool_repository.id)
# gitlab is a project with a pool repository that's missing a source_project_id
- pool_repository_without_source_project = pool_repositories.create(shard_id: shard.id, source_project_id: nil)
+ pool_repository_without_source_project = pool_repositories.create!(shard_id: shard.id, source_project_id: nil)
gitlab = projects.create!(name: 'gitlab', path: 'gitlab-org/gitlab-ce', namespace_id: 1, pool_repository_id: pool_repository_without_source_project.id)
projects.create!(name: 'gitlab-fork-1', path: 'my-org-1/gitlab-ce', namespace_id: 1, pool_repository_id: pool_repository_without_source_project.id)
diff --git a/spec/migrations/fix_projects_without_project_feature_spec.rb b/spec/migrations/fix_projects_without_project_feature_spec.rb
index 1ec67c07ba3..696c9e86384 100644
--- a/spec/migrations/fix_projects_without_project_feature_spec.rb
+++ b/spec/migrations/fix_projects_without_project_feature_spec.rb
@@ -4,13 +4,13 @@ require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20200127111840_fix_projects_without_project_feature.rb')
RSpec.describe FixProjectsWithoutProjectFeature do
- let(:namespace) { table(:namespaces).create(name: 'gitlab', path: 'gitlab-org') }
+ let(:namespace) { table(:namespaces).create!(name: 'gitlab', path: 'gitlab-org') }
let!(:projects) do
[
- table(:projects).create(namespace_id: namespace.id, name: 'foo 1'),
- table(:projects).create(namespace_id: namespace.id, name: 'foo 2'),
- table(:projects).create(namespace_id: namespace.id, name: 'foo 3')
+ table(:projects).create!(namespace_id: namespace.id, name: 'foo 1'),
+ table(:projects).create!(namespace_id: namespace.id, name: 'foo 2'),
+ table(:projects).create!(namespace_id: namespace.id, name: 'foo 3')
]
end
diff --git a/spec/migrations/fix_projects_without_prometheus_services_spec.rb b/spec/migrations/fix_projects_without_prometheus_services_spec.rb
index a4504ab6773..987350847ca 100644
--- a/spec/migrations/fix_projects_without_prometheus_services_spec.rb
+++ b/spec/migrations/fix_projects_without_prometheus_services_spec.rb
@@ -4,13 +4,13 @@ require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20200220115023_fix_projects_without_prometheus_service.rb')
RSpec.describe FixProjectsWithoutPrometheusService, :migration do
- let(:namespace) { table(:namespaces).create(name: 'gitlab', path: 'gitlab-org') }
+ let(:namespace) { table(:namespaces).create!(name: 'gitlab', path: 'gitlab-org') }
let!(:projects) do
[
- table(:projects).create(namespace_id: namespace.id, name: 'foo 1'),
- table(:projects).create(namespace_id: namespace.id, name: 'foo 2'),
- table(:projects).create(namespace_id: namespace.id, name: 'foo 3')
+ table(:projects).create!(namespace_id: namespace.id, name: 'foo 1'),
+ table(:projects).create!(namespace_id: namespace.id, name: 'foo 2'),
+ table(:projects).create!(namespace_id: namespace.id, name: 'foo 3')
]
end
diff --git a/spec/migrations/fix_wrong_pages_access_level_spec.rb b/spec/migrations/fix_wrong_pages_access_level_spec.rb
index 80787e0f115..310076f2e0a 100644
--- a/spec/migrations/fix_wrong_pages_access_level_spec.rb
+++ b/spec/migrations/fix_wrong_pages_access_level_spec.rb
@@ -17,7 +17,7 @@ RSpec.describe FixWrongPagesAccessLevel, :sidekiq_might_not_need_inline, schema:
let(:features_table) { table(:project_features) }
let(:subgroup) do
- root_group = namespaces_table.create(path: "group", name: "group")
+ root_group = namespaces_table.create!(path: "group", name: "group")
namespaces_table.create!(path: "subgroup", name: "group", parent_id: root_group.id)
end
diff --git a/spec/migrations/insert_project_hooks_plan_limits_spec.rb b/spec/migrations/insert_project_hooks_plan_limits_spec.rb
index 09fae160a6f..f29d72168bc 100644
--- a/spec/migrations/insert_project_hooks_plan_limits_spec.rb
+++ b/spec/migrations/insert_project_hooks_plan_limits_spec.rb
@@ -9,11 +9,11 @@ RSpec.describe InsertProjectHooksPlanLimits do
let(:plan_limits) { table(:plan_limits) }
before do
- plans.create(id: 34, name: 'free')
- plans.create(id: 2, name: 'bronze')
- plans.create(id: 3, name: 'silver')
- plans.create(id: 4, name: 'gold')
- plan_limits.create(plan_id: 34, ci_active_jobs: 5)
+ plans.create!(id: 34, name: 'free')
+ plans.create!(id: 2, name: 'bronze')
+ plans.create!(id: 3, name: 'silver')
+ plans.create!(id: 4, name: 'gold')
+ plan_limits.create!(plan_id: 34, ci_active_jobs: 5)
end
context 'when on Gitlab.com' do
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 d0abc777326..c7c846c7ef3 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
@@ -80,7 +80,7 @@ RSpec.describe MigrateAutoDevOpsDomainToClusterDomain do
cluster_projects.each do |cluster_project|
specific_domain = "#{cluster_project.id}-#{domain}" if domain
- project_auto_devops_table.create(
+ project_auto_devops_table.create!(
project_id: cluster_project.project_id,
enabled: true,
domain: specific_domain
diff --git a/spec/migrations/move_limits_from_plans_spec.rb b/spec/migrations/move_limits_from_plans_spec.rb
index a7a7d540ed3..c65fc439dd6 100644
--- a/spec/migrations/move_limits_from_plans_spec.rb
+++ b/spec/migrations/move_limits_from_plans_spec.rb
@@ -7,11 +7,11 @@ RSpec.describe MoveLimitsFromPlans do
let(:plans) { table(:plans) }
let(:plan_limits) { table(:plan_limits) }
- let!(:gold_plan) { plans.create(name: 'gold', title: 'Gold', active_pipelines_limit: 20, pipeline_size_limit: 21, active_jobs_limit: 22) }
- let!(:silver_plan) { plans.create(name: 'silver', title: 'Silver', active_pipelines_limit: 30, pipeline_size_limit: 31, active_jobs_limit: 32) }
- let!(:bronze_plan) { plans.create(name: 'bronze', title: 'Bronze', active_pipelines_limit: 40, pipeline_size_limit: 41, active_jobs_limit: 42) }
- let!(:free_plan) { plans.create(name: 'free', title: 'Free', active_pipelines_limit: 50, pipeline_size_limit: 51, active_jobs_limit: 52) }
- let!(:other_plan) { plans.create(name: 'other', title: 'Other', active_pipelines_limit: nil, pipeline_size_limit: nil, active_jobs_limit: 0) }
+ let!(:gold_plan) { plans.create!(name: 'gold', title: 'Gold', active_pipelines_limit: 20, pipeline_size_limit: 21, active_jobs_limit: 22) }
+ let!(:silver_plan) { plans.create!(name: 'silver', title: 'Silver', active_pipelines_limit: 30, pipeline_size_limit: 31, active_jobs_limit: 32) }
+ let!(:bronze_plan) { plans.create!(name: 'bronze', title: 'Bronze', active_pipelines_limit: 40, pipeline_size_limit: 41, active_jobs_limit: 42) }
+ let!(:free_plan) { plans.create!(name: 'free', title: 'Free', active_pipelines_limit: 50, pipeline_size_limit: 51, active_jobs_limit: 52) }
+ let!(:other_plan) { plans.create!(name: 'other', title: 'Other', active_pipelines_limit: nil, pipeline_size_limit: nil, active_jobs_limit: 0) }
describe 'migrate' do
it 'populates plan_limits from all the records in plans' do
diff --git a/spec/migrations/populate_project_statistics_packages_size_spec.rb b/spec/migrations/populate_project_statistics_packages_size_spec.rb
index 9024406c614..6c838e83c56 100644
--- a/spec/migrations/populate_project_statistics_packages_size_spec.rb
+++ b/spec/migrations/populate_project_statistics_packages_size_spec.rb
@@ -16,7 +16,7 @@ RSpec.describe PopulateProjectStatisticsPackagesSize do
let(:artifacts_size) { 4.terabytes }
let(:storage_size) { repo_size + lfs_size + artifacts_size }
- let(:namespace) { namespaces.create(name: 'foo', path: 'foo') }
+ let(:namespace) { namespaces.create!(name: 'foo', path: 'foo') }
let(:package) { packages.create!(project_id: project.id, name: 'a package', package_type: 1) }
let(:project) { projects.create!(namespace_id: namespace.id) }
diff --git a/spec/migrations/populate_remaining_missing_dismissal_information_for_vulnerabilities_spec.rb b/spec/migrations/populate_remaining_missing_dismissal_information_for_vulnerabilities_spec.rb
new file mode 100644
index 00000000000..986436971ac
--- /dev/null
+++ b/spec/migrations/populate_remaining_missing_dismissal_information_for_vulnerabilities_spec.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require_migration!
+
+RSpec.describe PopulateRemainingMissingDismissalInformationForVulnerabilities do
+ let(:users) { table(:users) }
+ let(:namespaces) { table(:namespaces) }
+ let(:projects) { table(:projects) }
+ let(:vulnerabilities) { table(:vulnerabilities) }
+
+ let(:user) { users.create!(name: 'test', email: 'test@example.com', projects_limit: 5) }
+ let(:namespace) { namespaces.create!(name: 'gitlab', path: 'gitlab-org') }
+ let(:project) { projects.create!(namespace_id: namespace.id, name: 'foo') }
+
+ let(:states) { { detected: 1, dismissed: 2, resolved: 3, confirmed: 4 } }
+ let!(:vulnerability_1) { vulnerabilities.create!(title: 'title', state: states[:detected], severity: 0, confidence: 5, report_type: 2, project_id: project.id, author_id: user.id) }
+ let!(:vulnerability_2) { vulnerabilities.create!(title: 'title', state: states[:dismissed], severity: 0, confidence: 5, report_type: 2, project_id: project.id, author_id: user.id) }
+ let!(:vulnerability_3) { vulnerabilities.create!(title: 'title', state: states[:resolved], severity: 0, confidence: 5, report_type: 2, project_id: project.id, author_id: user.id) }
+ let!(:vulnerability_4) { vulnerabilities.create!(title: 'title', state: states[:confirmed], severity: 0, confidence: 5, report_type: 2, project_id: project.id, author_id: user.id) }
+
+ describe '#perform' do
+ it 'calls the background migration class instance with broken vulnerability IDs' do
+ expect_next_instance_of(::Gitlab::BackgroundMigration::PopulateMissingVulnerabilityDismissalInformation) do |migrator|
+ expect(migrator).to receive(:perform).with(vulnerability_2.id)
+ end
+
+ migrate!
+ end
+ end
+end
diff --git a/spec/migrations/remove_orphan_service_hooks_spec.rb b/spec/migrations/remove_orphan_service_hooks_spec.rb
new file mode 100644
index 00000000000..c06a8b97738
--- /dev/null
+++ b/spec/migrations/remove_orphan_service_hooks_spec.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+require_migration!
+require Rails.root.join('db', 'migrate', '20201119125730_add_web_hooks_service_foreign_key.rb')
+
+RSpec.describe RemoveOrphanServiceHooks, schema: 20201203123201 do
+ let(:web_hooks) { table(:web_hooks) }
+ let(:services) { table(:services) }
+
+ before do
+ services.create!
+ web_hooks.create!(service_id: services.first.id, type: 'ServiceHook')
+ web_hooks.create!(service_id: nil)
+
+ AddWebHooksServiceForeignKey.new.down
+ web_hooks.create!(service_id: non_existing_record_id, type: 'ServiceHook')
+ AddWebHooksServiceForeignKey.new.up
+ end
+
+ it 'removes service hooks where the referenced service does not exist', :aggregate_failures do
+ expect { RemoveOrphanServiceHooks.new.up }.to change { web_hooks.count }.by(-1)
+ expect(web_hooks.where.not(service_id: services.select(:id)).count).to eq(0)
+ end
+end
diff --git a/spec/migrations/schedule_link_lfs_objects_projects_spec.rb b/spec/migrations/schedule_link_lfs_objects_projects_spec.rb
index 04ca18de91f..2384c5d5ce7 100644
--- a/spec/migrations/schedule_link_lfs_objects_projects_spec.rb
+++ b/spec/migrations/schedule_link_lfs_objects_projects_spec.rb
@@ -11,42 +11,42 @@ RSpec.describe ScheduleLinkLfsObjectsProjects, :migration, :sidekiq do
let(:lfs_objects) { table(:lfs_objects) }
let(:lfs_objects_projects) { table(:lfs_objects_projects) }
- let(:namespace) { namespaces.create(name: 'GitLab', path: 'gitlab') }
+ let(:namespace) { namespaces.create!(name: 'GitLab', path: 'gitlab') }
- let(:fork_network) { fork_networks.create(root_project_id: source_project.id) }
- let(:another_fork_network) { fork_networks.create(root_project_id: another_source_project.id) }
+ let(:fork_network) { fork_networks.create!(root_project_id: source_project.id) }
+ let(:another_fork_network) { fork_networks.create!(root_project_id: another_source_project.id) }
- let(:source_project) { projects.create(namespace_id: namespace.id) }
- let(:another_source_project) { projects.create(namespace_id: namespace.id) }
- let(:project) { projects.create(namespace_id: namespace.id) }
- let(:another_project) { projects.create(namespace_id: namespace.id) }
+ let(:source_project) { projects.create!(namespace_id: namespace.id) }
+ let(:another_source_project) { projects.create!(namespace_id: namespace.id) }
+ let(:project) { projects.create!(namespace_id: namespace.id) }
+ let(:another_project) { projects.create!(namespace_id: namespace.id) }
- let(:lfs_object) { lfs_objects.create(oid: 'abc123', size: 100) }
- let(:another_lfs_object) { lfs_objects.create(oid: 'def456', size: 200) }
+ let(:lfs_object) { lfs_objects.create!(oid: 'abc123', size: 100) }
+ let(:another_lfs_object) { lfs_objects.create!(oid: 'def456', size: 200) }
let!(:source_project_lop_1) do
- lfs_objects_projects.create(
+ lfs_objects_projects.create!(
lfs_object_id: lfs_object.id,
project_id: source_project.id
)
end
let!(:source_project_lop_2) do
- lfs_objects_projects.create(
+ lfs_objects_projects.create!(
lfs_object_id: another_lfs_object.id,
project_id: source_project.id
)
end
let!(:another_source_project_lop_1) do
- lfs_objects_projects.create(
+ lfs_objects_projects.create!(
lfs_object_id: lfs_object.id,
project_id: another_source_project.id
)
end
let!(:another_source_project_lop_2) do
- lfs_objects_projects.create(
+ lfs_objects_projects.create!(
lfs_object_id: another_lfs_object.id,
project_id: another_source_project.id
)
@@ -56,10 +56,10 @@ RSpec.describe ScheduleLinkLfsObjectsProjects, :migration, :sidekiq do
stub_const("#{described_class.name}::BATCH_SIZE", 2)
# Create links between projects
- fork_network_members.create(fork_network_id: fork_network.id, project_id: source_project.id, forked_from_project_id: nil)
- fork_network_members.create(fork_network_id: fork_network.id, project_id: project.id, forked_from_project_id: source_project.id)
- fork_network_members.create(fork_network_id: another_fork_network.id, project_id: another_source_project.id, forked_from_project_id: nil)
- fork_network_members.create(fork_network_id: another_fork_network.id, project_id: another_project.id, forked_from_project_id: another_fork_network.root_project_id)
+ fork_network_members.create!(fork_network_id: fork_network.id, project_id: source_project.id, forked_from_project_id: nil)
+ fork_network_members.create!(fork_network_id: fork_network.id, project_id: project.id, forked_from_project_id: source_project.id)
+ fork_network_members.create!(fork_network_id: another_fork_network.id, project_id: another_source_project.id, forked_from_project_id: nil)
+ fork_network_members.create!(fork_network_id: another_fork_network.id, project_id: another_project.id, forked_from_project_id: another_fork_network.root_project_id)
end
it 'schedules background migration to link LFS objects' do
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 93185b330c7..1f44df82ad0 100644
--- a/spec/migrations/schedule_populate_merge_request_assignees_table_spec.rb
+++ b/spec/migrations/schedule_populate_merge_request_assignees_table_spec.rb
@@ -6,8 +6,8 @@ require Rails.root.join('db', 'post_migrate', '20190322132835_schedule_populate_
RSpec.describe SchedulePopulateMergeRequestAssigneesTable do
let(:namespaces) { table(:namespaces) }
let(:projects) { table(:projects) }
- let(:namespace) { namespaces.create(name: 'gitlab', path: 'gitlab-org') }
- let(:project) { projects.create(namespace_id: namespace.id, name: 'foo') }
+ let(:namespace) { namespaces.create!(name: 'gitlab', path: 'gitlab-org') }
+ let(:project) { projects.create!(namespace_id: namespace.id, name: 'foo') }
let(:merge_requests) { table(:merge_requests) }
def create_merge_request(id)
diff --git a/spec/migrations/schedule_repopulate_historical_vulnerability_statistics_spec.rb b/spec/migrations/schedule_repopulate_historical_vulnerability_statistics_spec.rb
new file mode 100644
index 00000000000..a65c94cf60e
--- /dev/null
+++ b/spec/migrations/schedule_repopulate_historical_vulnerability_statistics_spec.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require_migration!
+
+RSpec.describe ScheduleRepopulateHistoricalVulnerabilityStatistics do
+ let(:namespaces) { table(:namespaces) }
+ let(:projects) { table(:projects) }
+ let(:project_settings) { table(:project_settings) }
+
+ let(:namespace) { namespaces.create!(name: 'gitlab', path: 'gitlab-org') }
+ let!(:project_1) { projects.create!(namespace_id: namespace.id, name: 'foo_1') }
+ let!(:project_2) { projects.create!(namespace_id: namespace.id, name: 'foo_2') }
+ let!(:project_3) { projects.create!(namespace_id: namespace.id, name: 'foo_3') }
+ let!(:project_4) { projects.create!(namespace_id: namespace.id, name: 'foo_4') }
+
+ around do |example|
+ freeze_time { Sidekiq::Testing.fake! { example.run } }
+ end
+
+ before do
+ stub_const("#{described_class.name}::BATCH_SIZE", 1)
+
+ project_settings.create!(project_id: project_1.id, has_vulnerabilities: true)
+ project_settings.create!(project_id: project_2.id, has_vulnerabilities: false)
+ project_settings.create!(project_id: project_4.id, has_vulnerabilities: true)
+ end
+
+ it 'schedules the background jobs', :aggregate_failures do
+ migrate!
+
+ expect(BackgroundMigrationWorker.jobs.size).to be(2)
+ expect(described_class::MIGRATION_CLASS).to be_scheduled_delayed_migration(described_class::DELAY_INTERVAL, [project_1.id], described_class::DAY_COUNT)
+ expect(described_class::MIGRATION_CLASS).to be_scheduled_delayed_migration(2 * described_class::DELAY_INTERVAL, [project_4.id], described_class::DAY_COUNT)
+ end
+end
diff --git a/spec/migrations/schedule_update_existing_users_that_require_two_factor_auth_spec.rb b/spec/migrations/schedule_update_existing_users_that_require_two_factor_auth_spec.rb
new file mode 100644
index 00000000000..74f24906e41
--- /dev/null
+++ b/spec/migrations/schedule_update_existing_users_that_require_two_factor_auth_spec.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require Rails.root.join('db', 'post_migrate', '20201030121314_schedule_update_existing_users_that_require_two_factor_auth.rb')
+
+RSpec.describe ScheduleUpdateExistingUsersThatRequireTwoFactorAuth do
+ let(:users) { table(:users) }
+ let!(:user_1) { users.create!(require_two_factor_authentication_from_group: true, name: "user1", email: "user1@example.com", projects_limit: 1) }
+ let!(:user_2) { users.create!(require_two_factor_authentication_from_group: false, name: "user2", email: "user2@example.com", projects_limit: 1) }
+ let!(:user_3) { users.create!(require_two_factor_authentication_from_group: true, name: "user3", email: "user3@example.com", projects_limit: 1) }
+
+ before do
+ stub_const("#{described_class.name}::BATCH_SIZE", 1)
+ end
+
+ it 'schedules jobs for users that require two factor authentication' do
+ Sidekiq::Testing.fake! do
+ freeze_time do
+ migrate!
+
+ expect(described_class::MIGRATION).to be_scheduled_delayed_migration(
+ 2.minutes, user_1.id, user_1.id)
+ expect(described_class::MIGRATION).to be_scheduled_delayed_migration(
+ 4.minutes, user_3.id, user_3.id)
+ expect(BackgroundMigrationWorker.jobs.size).to eq(2)
+ end
+ end
+ end
+end
diff --git a/spec/migrations/seed_repository_storages_weighted_spec.rb b/spec/migrations/seed_repository_storages_weighted_spec.rb
index fb077a3e345..d2fb1f7a014 100644
--- a/spec/migrations/seed_repository_storages_weighted_spec.rb
+++ b/spec/migrations/seed_repository_storages_weighted_spec.rb
@@ -17,7 +17,7 @@ RSpec.describe SeedRepositoryStoragesWeighted do
allow(Gitlab.config.repositories).to receive(:storages).and_return(storages)
end
- let(:application_setting) { application_settings.create }
+ let(:application_setting) { application_settings.create! }
let(:repository_storages) { ["foo"] }
it 'correctly schedules background migrations' do
diff --git a/spec/migrations/update_internal_ids_last_value_for_epics_renamed_spec.rb b/spec/migrations/update_internal_ids_last_value_for_epics_renamed_spec.rb
new file mode 100644
index 00000000000..71dd3a53bcd
--- /dev/null
+++ b/spec/migrations/update_internal_ids_last_value_for_epics_renamed_spec.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require Rails.root.join('db', 'migrate', '20201208081429_update_internal_ids_last_value_for_epics_renamed.rb')
+
+RSpec.describe UpdateInternalIdsLastValueForEpicsRenamed, :migration, schema: 20201124185639 do
+ let(:namespaces) { table(:namespaces) }
+ let(:users) { table(:users) }
+ let(:epics) { table(:epics) }
+ let(:internal_ids) { table(:internal_ids) }
+
+ let!(:author) { users.create!(name: 'test', email: 'test@example.com', projects_limit: 0) }
+ let!(:group1) { namespaces.create!(type: 'Group', name: 'group1', path: 'group1') }
+ let!(:group2) { namespaces.create!(type: 'Group', name: 'group2', path: 'group2') }
+ let!(:group3) { namespaces.create!(type: 'Group', name: 'group3', path: 'group3') }
+ let!(:epic_last_value1) { internal_ids.create!(usage: 4, last_value: 5, namespace_id: group1.id) }
+ let!(:epic_last_value2) { internal_ids.create!(usage: 4, last_value: 5, namespace_id: group2.id) }
+ let!(:epic_last_value3) { internal_ids.create!(usage: 4, last_value: 5, namespace_id: group3.id) }
+ let!(:epic_1) { epics.create!(iid: 110, title: 'from epic 1', group_id: group1.id, author_id: author.id, title_html: 'any') }
+ let!(:epic_2) { epics.create!(iid: 5, title: 'from epic 1', group_id: group2.id, author_id: author.id, title_html: 'any') }
+ let!(:epic_3) { epics.create!(iid: 3, title: 'from epic 1', group_id: group3.id, author_id: author.id, title_html: 'any') }
+
+ it 'updates out of sync internal_ids last_value' do
+ migrate!
+
+ expect(internal_ids.find_by(usage: 4, namespace_id: group1.id).last_value).to eq(110)
+ expect(internal_ids.find_by(usage: 4, namespace_id: group2.id).last_value).to eq(5)
+ expect(internal_ids.find_by(usage: 4, namespace_id: group3.id).last_value).to eq(5)
+ end
+end