Commit 90298c13 authored by Peter Leitzen's avatar Peter Leitzen

Merge branch 'rubocop-disable-save-bang-in-migration-specs' into 'master'

Fix Rails/SaveBang violations in migration specs [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!49564
parents 5f296783 0fb57d31
...@@ -55,7 +55,6 @@ Rails/SaveBang: ...@@ -55,7 +55,6 @@ Rails/SaveBang:
- 'ee/spec/lib/gitlab/auth/ldap/access_spec.rb' - 'ee/spec/lib/gitlab/auth/ldap/access_spec.rb'
- 'ee/spec/lib/gitlab/auth/o_auth/user_spec.rb' - 'ee/spec/lib/gitlab/auth/o_auth/user_spec.rb'
- 'ee/spec/lib/gitlab/auth/saml/user_spec.rb' - 'ee/spec/lib/gitlab/auth/saml/user_spec.rb'
- 'ee/spec/lib/gitlab/background_migration/fix_orphan_promoted_issues_spec.rb'
- 'ee/spec/lib/gitlab/elastic/search_results_spec.rb' - 'ee/spec/lib/gitlab/elastic/search_results_spec.rb'
- 'ee/spec/lib/gitlab/email/handler/ee/service_desk_handler_spec.rb' - 'ee/spec/lib/gitlab/email/handler/ee/service_desk_handler_spec.rb'
- 'ee/spec/lib/gitlab/geo_spec.rb' - 'ee/spec/lib/gitlab/geo_spec.rb'
...@@ -63,11 +62,6 @@ Rails/SaveBang: ...@@ -63,11 +62,6 @@ Rails/SaveBang:
- 'ee/spec/lib/gitlab/import_export/group/relation_factory_spec.rb' - 'ee/spec/lib/gitlab/import_export/group/relation_factory_spec.rb'
- 'ee/spec/lib/gitlab/mirror_spec.rb' - 'ee/spec/lib/gitlab/mirror_spec.rb'
- 'ee/spec/mailers/notify_spec.rb' - 'ee/spec/mailers/notify_spec.rb'
- 'ee/spec/migrations/fix_any_approver_rule_for_projects_spec.rb'
- 'ee/spec/migrations/geo/migrate_ci_job_artifacts_to_separate_registry_spec.rb'
- 'ee/spec/migrations/geo/migrate_lfs_objects_to_separate_registry_spec.rb'
- 'ee/spec/migrations/schedule_merge_request_any_approval_rule_migration_spec.rb'
- 'ee/spec/migrations/schedule_project_any_approval_rule_migration_spec.rb'
- 'ee/spec/models/application_setting_spec.rb' - 'ee/spec/models/application_setting_spec.rb'
- 'ee/spec/models/approval_merge_request_rule_spec.rb' - 'ee/spec/models/approval_merge_request_rule_spec.rb'
- 'ee/spec/models/approval_project_rule_spec.rb' - 'ee/spec/models/approval_project_rule_spec.rb'
...@@ -287,32 +281,6 @@ Rails/SaveBang: ...@@ -287,32 +281,6 @@ Rails/SaveBang:
- 'spec/lib/gitlab/auth/saml/user_spec.rb' - 'spec/lib/gitlab/auth/saml/user_spec.rb'
- 'spec/lib/gitlab/auth_spec.rb' - 'spec/lib/gitlab/auth_spec.rb'
- 'spec/lib/gitlab/authorized_keys_spec.rb' - 'spec/lib/gitlab/authorized_keys_spec.rb'
- 'spec/lib/gitlab/background_migration/backfill_deployment_clusters_from_deployments_spec.rb'
- 'spec/lib/gitlab/background_migration/backfill_project_repositories_spec.rb'
- 'spec/lib/gitlab/background_migration/backfill_project_settings_spec.rb'
- 'spec/lib/gitlab/background_migration/backfill_push_rules_id_in_projects_spec.rb'
- 'spec/lib/gitlab/background_migration/backfill_snippet_repositories_spec.rb'
- 'spec/lib/gitlab/background_migration/digest_column_spec.rb'
- 'spec/lib/gitlab/background_migration/encrypt_columns_spec.rb'
- 'spec/lib/gitlab/background_migration/fix_cross_project_label_links_spec.rb'
- 'spec/lib/gitlab/background_migration/fix_projects_without_project_feature_spec.rb'
- 'spec/lib/gitlab/background_migration/fix_projects_without_prometheus_service_spec.rb'
- 'spec/lib/gitlab/background_migration/fix_user_namespace_names_spec.rb'
- 'spec/lib/gitlab/background_migration/fix_user_project_route_names_spec.rb'
- 'spec/lib/gitlab/background_migration/legacy_upload_mover_spec.rb'
- 'spec/lib/gitlab/background_migration/legacy_uploads_migrator_spec.rb'
- 'spec/lib/gitlab/background_migration/link_lfs_objects_projects_spec.rb'
- 'spec/lib/gitlab/background_migration/migrate_issue_trackers_sensitive_data_spec.rb'
- 'spec/lib/gitlab/background_migration/migrate_stage_index_spec.rb'
- 'spec/lib/gitlab/background_migration/migrate_users_bio_to_user_details_spec.rb'
- 'spec/lib/gitlab/background_migration/populate_canonical_emails_spec.rb'
- 'spec/lib/gitlab/background_migration/populate_merge_request_assignees_table_spec.rb'
- 'spec/lib/gitlab/background_migration/populate_user_highest_roles_table_spec.rb'
- 'spec/lib/gitlab/background_migration/recalculate_project_authorizations_spec.rb'
- 'spec/lib/gitlab/background_migration/remove_restricted_todos_spec.rb'
- 'spec/lib/gitlab/background_migration/reset_merge_status_spec.rb'
- 'spec/lib/gitlab/background_migration/set_confidential_note_events_on_services_spec.rb'
- 'spec/lib/gitlab/background_migration/set_confidential_note_events_on_webhooks_spec.rb'
- 'spec/lib/gitlab/bitbucket_server_import/importer_spec.rb' - 'spec/lib/gitlab/bitbucket_server_import/importer_spec.rb'
- 'spec/lib/gitlab/ci/ansi2json/style_spec.rb' - 'spec/lib/gitlab/ci/ansi2json/style_spec.rb'
- 'spec/lib/gitlab/ci/status/build/common_spec.rb' - 'spec/lib/gitlab/ci/status/build/common_spec.rb'
...@@ -363,38 +331,6 @@ Rails/SaveBang: ...@@ -363,38 +331,6 @@ Rails/SaveBang:
- 'spec/lib/mattermost/session_spec.rb' - 'spec/lib/mattermost/session_spec.rb'
- 'spec/lib/mattermost/team_spec.rb' - 'spec/lib/mattermost/team_spec.rb'
- 'spec/mailers/notify_spec.rb' - 'spec/mailers/notify_spec.rb'
- 'spec/migrations/20190924152703_migrate_issue_trackers_data_spec.rb'
- 'spec/migrations/20200122123016_backfill_project_settings_spec.rb'
- 'spec/migrations/20200123155929_remove_invalid_jira_data_spec.rb'
- 'spec/migrations/20200127090233_remove_invalid_issue_tracker_data_spec.rb'
- 'spec/migrations/20200130145430_reschedule_migrate_issue_trackers_data_spec.rb'
- 'spec/migrations/20200313203550_remove_orphaned_chat_names_spec.rb'
- 'spec/migrations/20200406102120_backfill_deployment_clusters_from_deployments_spec.rb'
- 'spec/migrations/20200526115436_dedup_mr_metrics_spec.rb'
- 'spec/migrations/add_deploy_token_type_to_deploy_tokens_spec.rb'
- 'spec/migrations/add_incident_settings_to_all_existing_projects_spec.rb'
- 'spec/migrations/add_unique_constraint_to_approvals_user_id_and_merge_request_id_spec.rb'
- 'spec/migrations/backfill_and_add_not_null_constraint_to_released_at_column_on_releases_table_spec.rb'
- 'spec/migrations/backfill_imported_snippet_repositories_spec.rb'
- 'spec/migrations/backfill_releases_table_updated_at_and_add_not_null_constraints_to_timestamps_spec.rb'
- 'spec/migrations/backfill_snippet_repositories_spec.rb'
- 'spec/migrations/encrypt_plaintext_attributes_on_application_settings_spec.rb'
- 'spec/migrations/enqueue_reset_merge_status_second_run_spec.rb'
- 'spec/migrations/enqueue_reset_merge_status_spec.rb'
- 'spec/migrations/fill_file_store_lfs_objects_spec.rb'
- 'spec/migrations/fill_store_uploads_spec.rb'
- 'spec/migrations/fix_null_type_labels_spec.rb'
- 'spec/migrations/fix_pool_repository_source_project_id_spec.rb'
- 'spec/migrations/fix_projects_without_project_feature_spec.rb'
- 'spec/migrations/fix_projects_without_prometheus_services_spec.rb'
- 'spec/migrations/fix_wrong_pages_access_level_spec.rb'
- 'spec/migrations/insert_project_hooks_plan_limits_spec.rb'
- 'spec/migrations/migrate_auto_dev_ops_domain_to_cluster_domain_spec.rb'
- 'spec/migrations/move_limits_from_plans_spec.rb'
- 'spec/migrations/populate_project_statistics_packages_size_spec.rb'
- 'spec/migrations/schedule_link_lfs_objects_projects_spec.rb'
- 'spec/migrations/schedule_populate_merge_request_assignees_table_spec.rb'
- 'spec/migrations/seed_repository_storages_weighted_spec.rb'
- 'spec/models/appearance_spec.rb' - 'spec/models/appearance_spec.rb'
- 'spec/models/application_record_spec.rb' - 'spec/models/application_record_spec.rb'
- 'spec/models/application_setting_spec.rb' - 'spec/models/application_setting_spec.rb'
......
...@@ -14,9 +14,9 @@ RSpec.describe Gitlab::BackgroundMigration::FixOrphanPromotedIssues, schema: 202 ...@@ -14,9 +14,9 @@ RSpec.describe Gitlab::BackgroundMigration::FixOrphanPromotedIssues, schema: 202
let(:project1) { projects.create!(namespace_id: group1.id) } let(:project1) { projects.create!(namespace_id: group1.id) }
let(:group2) { namespaces.create!(name: 'other', path: 'other') } let(:group2) { namespaces.create!(name: 'other', path: 'other') }
let(:project2) { projects.create!(namespace_id: group2.id) } let(:project2) { projects.create!(namespace_id: group2.id) }
let(:user) { users.create(name: 'any', email: 'user@example.com', projects_limit: 9) } let(:user) { users.create!(name: 'any', email: 'user@example.com', projects_limit: 9) }
let!(:epic_from_issue_1) { epics.create(iid: 14532, title: 'from issue 1', group_id: group1.id, author_id: user.id, created_at: Time.now, updated_at: Time.now, title_html: 'any') } let!(:epic_from_issue_1) { epics.create!(iid: 14532, title: 'from issue 1', group_id: group1.id, author_id: user.id, created_at: Time.now, updated_at: Time.now, title_html: 'any') }
let!(:epic_from_issue_2) { epics.create(iid: 209, title: 'from issue 2', group_id: group2.id, author_id: user.id, created_at: Time.now, updated_at: Time.now, title_html: 'any') } let!(:epic_from_issue_2) { epics.create!(iid: 209, title: 'from issue 2', group_id: group2.id, author_id: user.id, created_at: Time.now, updated_at: Time.now, title_html: 'any') }
let!(:promoted_orphan) { issues.create!(description: 'promoted 1', state_id: 1, project_id: project1.id) } let!(:promoted_orphan) { issues.create!(description: 'promoted 1', state_id: 1, project_id: project1.id) }
let!(:promoted) { issues.create!(description: 'promoted 3', state_id: 2, project_id: project2.id, promoted_to_epic_id: epic_from_issue_2.id) } let!(:promoted) { issues.create!(description: 'promoted 3', state_id: 2, project_id: project2.id, promoted_to_epic_id: epic_from_issue_2.id) }
let!(:promotion_note_1) { notes.create!(project_id: project1.id, noteable_id: promoted_orphan.id, noteable_type: "Issue", note: "promoted to epic &14532", system: true) } let!(:promotion_note_1) { notes.create!(project_id: project1.id, noteable_id: promoted_orphan.id, noteable_type: "Issue", note: "promoted to epic &14532", system: true) }
......
...@@ -5,16 +5,16 @@ require_migration! ...@@ -5,16 +5,16 @@ require_migration!
RSpec.describe FixAnyApproverRuleForProjects do RSpec.describe FixAnyApproverRuleForProjects do
let(:namespaces) { table(:namespaces) } let(:namespaces) { table(:namespaces) }
let(:namespace) { namespaces.create(name: 'gitlab', path: 'gitlab-org') } let(:namespace) { namespaces.create!(name: 'gitlab', path: 'gitlab-org') }
let(:projects) { table(:projects) } let(:projects) { table(:projects) }
let(:approval_project_rules) { table(:approval_project_rules) } let(:approval_project_rules) { table(:approval_project_rules) }
def create_project(id) def create_project(id)
projects.create(id: id, namespace_id: namespace.id) projects.create!(id: id, namespace_id: namespace.id)
end end
def create_rule(id, project_id:, rule_type:) def create_rule(id, project_id:, rule_type:)
approval_project_rules.create( approval_project_rules.create!(
id: id, project_id: project_id, rule_type: rule_type, id: id, project_id: project_id, rule_type: rule_type,
approvals_required: 3, name: ApprovalRuleLike::ALL_MEMBERS) approvals_required: 3, name: ApprovalRuleLike::ALL_MEMBERS)
end end
......
...@@ -46,7 +46,7 @@ RSpec.describe MigrateCiJobArtifactsToSeparateRegistry, :geo do ...@@ -46,7 +46,7 @@ RSpec.describe MigrateCiJobArtifactsToSeparateRegistry, :geo do
expect(job_artifact_registry.all.count).to eq(3) expect(job_artifact_registry.all.count).to eq(3)
entry = file_registry.find_by(file_id: 1) entry = file_registry.find_by(file_id: 1)
entry.update(success: false, bytes: 10240, sha256: '10' * 64) entry.update!(success: false, bytes: 10240, sha256: '10' * 64)
expect(job_artifact_registry.where(artifact_id: 1, success: false, bytes: 10240, sha256: '10' * 64).count).to eq(1) expect(job_artifact_registry.where(artifact_id: 1, success: false, bytes: 10240, sha256: '10' * 64).count).to eq(1)
# Ensure that *only* the correct job artifact is updated # Ensure that *only* the correct job artifact is updated
......
...@@ -46,7 +46,7 @@ RSpec.describe MigrateLfsObjectsToSeparateRegistry, :geo do ...@@ -46,7 +46,7 @@ RSpec.describe MigrateLfsObjectsToSeparateRegistry, :geo do
expect(lfs_object_registry.all.count).to eq(3) expect(lfs_object_registry.all.count).to eq(3)
entry = file_registry.find_by(file_id: 1) entry = file_registry.find_by(file_id: 1)
entry.update(success: false, bytes: 10240, sha256: '10' * 64) entry.update!(success: false, bytes: 10240, sha256: '10' * 64)
expect(lfs_object_registry.where(lfs_object_id: 1, success: false, bytes: 10240, sha256: '10' * 64).count).to eq(1) expect(lfs_object_registry.where(lfs_object_id: 1, success: false, bytes: 10240, sha256: '10' * 64).count).to eq(1)
# Ensure that *only* the correct lfs object is updated # Ensure that *only* the correct lfs object is updated
......
...@@ -6,8 +6,8 @@ require_migration! ...@@ -6,8 +6,8 @@ require_migration!
RSpec.describe ScheduleMergeRequestAnyApprovalRuleMigration do RSpec.describe ScheduleMergeRequestAnyApprovalRuleMigration do
let(:namespaces) { table(:namespaces) } let(:namespaces) { table(:namespaces) }
let(:projects) { table(:projects) } let(:projects) { table(:projects) }
let(:namespace) { namespaces.create(name: 'gitlab', path: 'gitlab-org') } let(:namespace) { namespaces.create!(name: 'gitlab', path: 'gitlab-org') }
let(:project) { projects.create(namespace_id: namespace.id, name: 'foo') } let(:project) { projects.create!(namespace_id: namespace.id, name: 'foo') }
let(:merge_requests) { table(:merge_requests) } let(:merge_requests) { table(:merge_requests) }
def create_merge_request(id, options = {}) def create_merge_request(id, options = {})
......
...@@ -6,7 +6,7 @@ require_migration! ...@@ -6,7 +6,7 @@ require_migration!
RSpec.describe ScheduleProjectAnyApprovalRuleMigration do RSpec.describe ScheduleProjectAnyApprovalRuleMigration do
let(:namespaces) { table(:namespaces) } let(:namespaces) { table(:namespaces) }
let(:projects) { table(:projects) } let(:projects) { table(:projects) }
let(:namespace) { namespaces.create(name: 'gitlab', path: 'gitlab-org') } let(:namespace) { namespaces.create!(name: 'gitlab', path: 'gitlab-org') }
def create_project(id, options = {}) def create_project(id, options = {})
default_options = { default_options = {
...@@ -16,7 +16,7 @@ RSpec.describe ScheduleProjectAnyApprovalRuleMigration do ...@@ -16,7 +16,7 @@ RSpec.describe ScheduleProjectAnyApprovalRuleMigration do
approvals_before_merge: 2 approvals_before_merge: 2
} }
projects.create(default_options.merge(options)) projects.create!(default_options.merge(options))
end end
it 'correctly schedules background migrations' do it 'correctly schedules background migrations' do
......
...@@ -9,10 +9,10 @@ RSpec.describe Gitlab::BackgroundMigration::BackfillDeploymentClustersFromDeploy ...@@ -9,10 +9,10 @@ RSpec.describe Gitlab::BackgroundMigration::BackfillDeploymentClustersFromDeploy
it 'backfills deployment_cluster for all deployments in the given range with a non-null cluster_id' do it 'backfills deployment_cluster for all deployments in the given range with a non-null cluster_id' do
deployment_clusters = table(:deployment_clusters) deployment_clusters = table(:deployment_clusters)
namespace = table(:namespaces).create(name: 'the-namespace', path: 'the-path') namespace = table(:namespaces).create!(name: 'the-namespace', path: 'the-path')
project = table(:projects).create(name: 'the-project', namespace_id: namespace.id) project = table(:projects).create!(name: 'the-project', namespace_id: namespace.id)
environment = table(:environments).create(name: 'the-environment', project_id: project.id, slug: 'slug') environment = table(:environments).create!(name: 'the-environment', project_id: project.id, slug: 'slug')
cluster = table(:clusters).create(name: 'the-cluster') 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 } deployment_data = { cluster_id: cluster.id, project_id: project.id, environment_id: environment.id, ref: 'abc', tag: false, sha: 'sha', status: 1 }
expected_deployment_1 = create_deployment(**deployment_data) expected_deployment_1 = create_deployment(**deployment_data)
...@@ -21,7 +21,7 @@ RSpec.describe Gitlab::BackgroundMigration::BackfillDeploymentClustersFromDeploy ...@@ -21,7 +21,7 @@ RSpec.describe Gitlab::BackgroundMigration::BackfillDeploymentClustersFromDeploy
out_of_range_deployment = create_deployment(**deployment_data, cluster_id: cluster.id) # expected to be out of range out_of_range_deployment = create_deployment(**deployment_data, cluster_id: cluster.id) # expected to be out of range
# to test "ON CONFLICT DO NOTHING" # to test "ON CONFLICT DO NOTHING"
existing_record_for_deployment_2 = deployment_clusters.create( existing_record_for_deployment_2 = deployment_clusters.create!(
deployment_id: expected_deployment_2.id, deployment_id: expected_deployment_2.id,
cluster_id: expected_deployment_2.cluster_id, cluster_id: expected_deployment_2.cluster_id,
kubernetes_namespace: 'production' kubernetes_namespace: 'production'
...@@ -38,7 +38,7 @@ RSpec.describe Gitlab::BackgroundMigration::BackfillDeploymentClustersFromDeploy ...@@ -38,7 +38,7 @@ RSpec.describe Gitlab::BackgroundMigration::BackfillDeploymentClustersFromDeploy
def create_deployment(**data) def create_deployment(**data)
@iid ||= 0 @iid ||= 0
@iid += 1 @iid += 1
table(:deployments).create(iid: @iid, **data) table(:deployments).create!(iid: @iid, **data)
end end
end end
end end
...@@ -81,7 +81,7 @@ RSpec.describe Gitlab::BackgroundMigration::BackfillProjectRepositories do ...@@ -81,7 +81,7 @@ RSpec.describe Gitlab::BackgroundMigration::BackfillProjectRepositories do
end end
it 'returns the correct disk_path using the route entry' do it 'returns the correct disk_path using the route entry' do
project_legacy_storage_5.route.update(path: 'zoo/new-test') project_legacy_storage_5.route.update!(path: 'zoo/new-test')
project = described_class.find(project_legacy_storage_5.id) project = described_class.find(project_legacy_storage_5.id)
expect(project.disk_path).to eq('zoo/new-test') expect(project.disk_path).to eq('zoo/new-test')
...@@ -93,8 +93,8 @@ RSpec.describe Gitlab::BackgroundMigration::BackfillProjectRepositories do ...@@ -93,8 +93,8 @@ RSpec.describe Gitlab::BackgroundMigration::BackfillProjectRepositories do
subgroup.update_column(:parent_id, non_existing_record_id) subgroup.update_column(:parent_id, non_existing_record_id)
project = described_class.find(project_orphaned_namespace.id) project = described_class.find(project_orphaned_namespace.id)
project.route.destroy project.route.destroy!
subgroup.route.destroy subgroup.route.destroy!
expect { project.reload.disk_path } expect { project.reload.disk_path }
.to raise_error(Gitlab::BackgroundMigration::BackfillProjectRepositories::OrphanedNamespaceError) .to raise_error(Gitlab::BackgroundMigration::BackfillProjectRepositories::OrphanedNamespaceError)
......
...@@ -5,16 +5,16 @@ require 'spec_helper' ...@@ -5,16 +5,16 @@ require 'spec_helper'
RSpec.describe Gitlab::BackgroundMigration::BackfillProjectSettings, schema: 20200114113341 do RSpec.describe Gitlab::BackgroundMigration::BackfillProjectSettings, schema: 20200114113341 do
let(:projects) { table(:projects) } let(:projects) { table(:projects) }
let(:project_settings) { table(:project_settings) } let(:project_settings) { table(:project_settings) }
let(:namespace) { table(:namespaces).create(name: 'user', path: 'user') } let(:namespace) { table(:namespaces).create!(name: 'user', path: 'user') }
let(:project) { projects.create(namespace_id: namespace.id) } let(:project) { projects.create!(namespace_id: namespace.id) }
subject { described_class.new } subject { described_class.new }
describe '#perform' do describe '#perform' do
it 'creates settings for all projects in range' do it 'creates settings for all projects in range' do
projects.create(id: 5, namespace_id: namespace.id) projects.create!(id: 5, namespace_id: namespace.id)
projects.create(id: 7, namespace_id: namespace.id) projects.create!(id: 7, namespace_id: namespace.id)
projects.create(id: 8, namespace_id: namespace.id) projects.create!(id: 8, namespace_id: namespace.id)
subject.perform(5, 7) subject.perform(5, 7)
......
...@@ -6,21 +6,21 @@ RSpec.describe Gitlab::BackgroundMigration::BackfillPushRulesIdInProjects, :migr ...@@ -6,21 +6,21 @@ RSpec.describe Gitlab::BackgroundMigration::BackfillPushRulesIdInProjects, :migr
let(:push_rules) { table(:push_rules) } let(:push_rules) { table(:push_rules) }
let(:projects) { table(:projects) } let(:projects) { table(:projects) }
let(:project_settings) { table(:project_settings) } let(:project_settings) { table(:project_settings) }
let(:namespace) { table(:namespaces).create(name: 'user', path: 'user') } let(:namespace) { table(:namespaces).create!(name: 'user', path: 'user') }
subject { described_class.new } subject { described_class.new }
describe '#perform' do describe '#perform' do
it 'creates new project push_rules for all push rules in the range' do it 'creates new project push_rules for all push rules in the range' do
project_1 = projects.create(id: 1, namespace_id: namespace.id) project_1 = projects.create!(id: 1, namespace_id: namespace.id)
project_2 = projects.create(id: 2, namespace_id: namespace.id) project_2 = projects.create!(id: 2, namespace_id: namespace.id)
project_3 = projects.create(id: 3, namespace_id: namespace.id) project_3 = projects.create!(id: 3, namespace_id: namespace.id)
project_settings_1 = project_settings.create(project_id: project_1.id) project_settings_1 = project_settings.create!(project_id: project_1.id)
project_settings_2 = project_settings.create(project_id: project_2.id) project_settings_2 = project_settings.create!(project_id: project_2.id)
project_settings_3 = project_settings.create(project_id: project_3.id) project_settings_3 = project_settings.create!(project_id: project_3.id)
push_rule_1 = push_rules.create(id: 5, is_sample: false, project_id: project_1.id) push_rule_1 = push_rules.create!(id: 5, is_sample: false, project_id: project_1.id)
push_rule_2 = push_rules.create(id: 6, is_sample: false, project_id: project_2.id) push_rule_2 = push_rules.create!(id: 6, is_sample: false, project_id: project_2.id)
push_rules.create(id: 8, is_sample: false, project_id: 3) push_rules.create!(id: 8, is_sample: false, project_id: 3)
subject.perform(5, 7) subject.perform(5, 7)
......
...@@ -13,7 +13,7 @@ RSpec.describe Gitlab::BackgroundMigration::BackfillSnippetRepositories, :migrat ...@@ -13,7 +13,7 @@ RSpec.describe Gitlab::BackgroundMigration::BackfillSnippetRepositories, :migrat
let(:user_name) { 'Test' } let(:user_name) { 'Test' }
let!(:user) do let!(:user) do
users.create(id: 1, users.create!(id: 1,
email: 'user@example.com', email: 'user@example.com',
projects_limit: 10, projects_limit: 10,
username: 'test', username: 'test',
...@@ -25,7 +25,7 @@ RSpec.describe Gitlab::BackgroundMigration::BackfillSnippetRepositories, :migrat ...@@ -25,7 +25,7 @@ RSpec.describe Gitlab::BackgroundMigration::BackfillSnippetRepositories, :migrat
end end
let!(:migration_bot) do let!(:migration_bot) do
users.create(id: 100, users.create!(id: 100,
email: "noreply+gitlab-migration-bot%s@#{Settings.gitlab.host}", email: "noreply+gitlab-migration-bot%s@#{Settings.gitlab.host}",
user_type: HasUserType::USER_TYPES[:migration_bot], user_type: HasUserType::USER_TYPES[:migration_bot],
name: 'GitLab Migration Bot', name: 'GitLab Migration Bot',
...@@ -33,9 +33,9 @@ RSpec.describe Gitlab::BackgroundMigration::BackfillSnippetRepositories, :migrat ...@@ -33,9 +33,9 @@ RSpec.describe Gitlab::BackgroundMigration::BackfillSnippetRepositories, :migrat
username: 'bot') username: 'bot')
end end
let!(:snippet_with_repo) { snippets.create(id: 1, type: 'PersonalSnippet', author_id: user.id, file_name: file_name, content: content) } let!(:snippet_with_repo) { snippets.create!(id: 1, type: 'PersonalSnippet', author_id: user.id, file_name: file_name, content: content) }
let!(:snippet_with_empty_repo) { snippets.create(id: 2, type: 'PersonalSnippet', author_id: user.id, file_name: file_name, content: content) } let!(:snippet_with_empty_repo) { snippets.create!(id: 2, type: 'PersonalSnippet', author_id: user.id, file_name: file_name, content: content) }
let!(:snippet_without_repo) { snippets.create(id: 3, type: 'PersonalSnippet', author_id: user.id, file_name: file_name, content: content) } let!(:snippet_without_repo) { snippets.create!(id: 3, type: 'PersonalSnippet', author_id: user.id, file_name: file_name, content: content) }
let(:file_name) { 'file_name.rb' } let(:file_name) { 'file_name.rb' }
let(:content) { 'content' } let(:content) { 'content' }
...@@ -197,8 +197,8 @@ RSpec.describe Gitlab::BackgroundMigration::BackfillSnippetRepositories, :migrat ...@@ -197,8 +197,8 @@ RSpec.describe Gitlab::BackgroundMigration::BackfillSnippetRepositories, :migrat
end end
with_them do with_them do
let!(:snippet_with_invalid_path) { snippets.create(id: 4, type: 'PersonalSnippet', author_id: user.id, file_name: invalid_file_name, content: content) } let!(:snippet_with_invalid_path) { snippets.create!(id: 4, type: 'PersonalSnippet', author_id: user.id, file_name: invalid_file_name, content: content) }
let!(:snippet_with_valid_path) { snippets.create(id: 5, type: 'PersonalSnippet', author_id: user.id, file_name: file_name, content: content) } let!(:snippet_with_valid_path) { snippets.create!(id: 5, type: 'PersonalSnippet', author_id: user.id, file_name: file_name, content: content) }
let(:ids) { [4, 5] } let(:ids) { [4, 5] }
after do after do
...@@ -241,7 +241,7 @@ RSpec.describe Gitlab::BackgroundMigration::BackfillSnippetRepositories, :migrat ...@@ -241,7 +241,7 @@ RSpec.describe Gitlab::BackgroundMigration::BackfillSnippetRepositories, :migrat
context 'when user name is invalid' do context 'when user name is invalid' do
let(:user_name) { '.' } let(:user_name) { '.' }
let!(:snippet) { snippets.create(id: 4, type: 'PersonalSnippet', author_id: user.id, file_name: file_name, content: content) } let!(:snippet) { snippets.create!(id: 4, type: 'PersonalSnippet', author_id: user.id, file_name: file_name, content: content) }
let(:ids) { [4, 4] } let(:ids) { [4, 4] }
after do after do
...@@ -254,7 +254,7 @@ RSpec.describe Gitlab::BackgroundMigration::BackfillSnippetRepositories, :migrat ...@@ -254,7 +254,7 @@ RSpec.describe Gitlab::BackgroundMigration::BackfillSnippetRepositories, :migrat
context 'when both user name and snippet file_name are invalid' do context 'when both user name and snippet file_name are invalid' do
let(:user_name) { '.' } let(:user_name) { '.' }
let!(:other_user) do let!(:other_user) do
users.create(id: 2, users.create!(id: 2,
email: 'user2@example.com', email: 'user2@example.com',
projects_limit: 10, projects_limit: 10,
username: 'test2', username: 'test2',
...@@ -265,8 +265,8 @@ RSpec.describe Gitlab::BackgroundMigration::BackfillSnippetRepositories, :migrat ...@@ -265,8 +265,8 @@ RSpec.describe Gitlab::BackgroundMigration::BackfillSnippetRepositories, :migrat
confirmed_at: 1.day.ago) confirmed_at: 1.day.ago)
end end
let!(:invalid_snippet) { snippets.create(id: 4, type: 'PersonalSnippet', author_id: user.id, file_name: '.', content: content) } let!(:invalid_snippet) { snippets.create!(id: 4, type: 'PersonalSnippet', author_id: user.id, file_name: '.', content: content) }
let!(:snippet) { snippets.create(id: 5, type: 'PersonalSnippet', author_id: other_user.id, file_name: file_name, content: content) } let!(:snippet) { snippets.create!(id: 5, type: 'PersonalSnippet', author_id: other_user.id, file_name: file_name, content: content) }
let(:ids) { [4, 5] } let(:ids) { [4, 5] }
after do after do
......
...@@ -7,7 +7,7 @@ RSpec.describe Gitlab::BackgroundMigration::FixProjectsWithoutProjectFeature, sc ...@@ -7,7 +7,7 @@ RSpec.describe Gitlab::BackgroundMigration::FixProjectsWithoutProjectFeature, sc
let(:projects) { table(:projects) } let(:projects) { table(:projects) }
let(:project_features) { table(:project_features) } let(:project_features) { table(:project_features) }
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!(:project) { projects.create!(namespace_id: namespace.id) }
let(:private_project_without_feature) { projects.create!(namespace_id: namespace.id, visibility_level: 0) } let(:private_project_without_feature) { projects.create!(namespace_id: namespace.id, visibility_level: 0) }
...@@ -15,7 +15,7 @@ RSpec.describe Gitlab::BackgroundMigration::FixProjectsWithoutProjectFeature, sc ...@@ -15,7 +15,7 @@ RSpec.describe Gitlab::BackgroundMigration::FixProjectsWithoutProjectFeature, sc
let!(:projects_without_feature) { [private_project_without_feature, public_project_without_feature] } let!(:projects_without_feature) { [private_project_without_feature, public_project_without_feature] }
before do before do
project_features.create({ project_id: project.id, pages_access_level: 20 }) project_features.create!({ project_id: project.id, pages_access_level: 20 })
end end
subject { described_class.new.perform(Project.minimum(:id), Project.maximum(:id)) } subject { described_class.new.perform(Project.minimum(:id), Project.maximum(:id)) }
......
...@@ -33,8 +33,8 @@ RSpec.describe Gitlab::BackgroundMigration::FixProjectsWithoutPrometheusService, ...@@ -33,8 +33,8 @@ RSpec.describe Gitlab::BackgroundMigration::FixProjectsWithoutPrometheusService,
let(:clusters) { table(:clusters) } let(:clusters) { table(:clusters) }
let(:cluster_groups) { table(:cluster_groups) } let(:cluster_groups) { table(:cluster_groups) }
let(:clusters_applications_prometheus) { table(:clusters_applications_prometheus) } let(:clusters_applications_prometheus) { table(:clusters_applications_prometheus) }
let(:namespace) { namespaces.create(name: 'user', path: 'user') } let(:namespace) { namespaces.create!(name: 'user', path: 'user') }
let(:project) { projects.create(namespace_id: namespace.id) } let(:project) { projects.create!(namespace_id: namespace.id) }
let(:application_statuses) do let(:application_statuses) do
{ {
...@@ -71,7 +71,7 @@ RSpec.describe Gitlab::BackgroundMigration::FixProjectsWithoutPrometheusService, ...@@ -71,7 +71,7 @@ RSpec.describe Gitlab::BackgroundMigration::FixProjectsWithoutPrometheusService,
context 'non prometheus services' do context 'non prometheus services' do
it 'does not change them' do it 'does not change them' do
other_type = 'SomeOtherService' other_type = 'SomeOtherService'
services.create(service_params_for(project.id, active: true, type: other_type)) services.create!(service_params_for(project.id, active: true, type: other_type))
expect { subject.perform(project.id, project.id + 1) }.not_to change { services.where(type: other_type).order(:id).map { |row| row.attributes } } expect { subject.perform(project.id, project.id + 1) }.not_to change { services.where(type: other_type).order(:id).map { |row| row.attributes } }
end end
...@@ -85,7 +85,7 @@ RSpec.describe Gitlab::BackgroundMigration::FixProjectsWithoutPrometheusService, ...@@ -85,7 +85,7 @@ RSpec.describe Gitlab::BackgroundMigration::FixProjectsWithoutPrometheusService,
context 'template is present for prometheus services' do context 'template is present for prometheus services' do
it 'creates missing services entries', :aggregate_failures do it 'creates missing services entries', :aggregate_failures do
services.create(service_params_for(nil, template: true, properties: { 'from_template' => true }.to_json)) services.create!(service_params_for(nil, template: true, properties: { 'from_template' => true }.to_json))
expect { subject.perform(project.id, project.id + 1) }.to change { services.count }.by(1) expect { subject.perform(project.id, project.id + 1) }.to change { services.count }.by(1)
updated_rows = services.where(template: false).order(:id).map { |row| row.attributes.slice(*columns).symbolize_keys } updated_rows = services.where(template: false).order(:id).map { |row| row.attributes.slice(*columns).symbolize_keys }
...@@ -97,7 +97,7 @@ RSpec.describe Gitlab::BackgroundMigration::FixProjectsWithoutPrometheusService, ...@@ -97,7 +97,7 @@ RSpec.describe Gitlab::BackgroundMigration::FixProjectsWithoutPrometheusService,
context 'prometheus integration services exist' do context 'prometheus integration services exist' do
context 'in active state' do context 'in active state' do
it 'does not change them' do it 'does not change them' do
services.create(service_params_for(project.id, active: true)) services.create!(service_params_for(project.id, active: true))
expect { subject.perform(project.id, project.id + 1) }.not_to change { services.order(:id).map { |row| row.attributes } } expect { subject.perform(project.id, project.id + 1) }.not_to change { services.order(:id).map { |row| row.attributes } }
end end
...@@ -105,7 +105,7 @@ RSpec.describe Gitlab::BackgroundMigration::FixProjectsWithoutPrometheusService, ...@@ -105,7 +105,7 @@ RSpec.describe Gitlab::BackgroundMigration::FixProjectsWithoutPrometheusService,
context 'not in active state' do context 'not in active state' do
it 'sets active attribute to true' do it 'sets active attribute to true' do
service = services.create(service_params_for(project.id, active: false)) service = services.create!(service_params_for(project.id, active: false))
expect { subject.perform(project.id, project.id + 1) }.to change { service.reload.active? }.from(false).to(true) expect { subject.perform(project.id, project.id + 1) }.to change { service.reload.active? }.from(false).to(true)
end end
...@@ -113,7 +113,7 @@ RSpec.describe Gitlab::BackgroundMigration::FixProjectsWithoutPrometheusService, ...@@ -113,7 +113,7 @@ RSpec.describe Gitlab::BackgroundMigration::FixProjectsWithoutPrometheusService,
context 'prometheus services are configured manually ' do context 'prometheus services are configured manually ' do
it 'does not change them' do it 'does not change them' do
properties = '{"api_url":"http://test.dev","manual_configuration":"1"}' properties = '{"api_url":"http://test.dev","manual_configuration":"1"}'
services.create(service_params_for(project.id, properties: properties, active: false)) services.create!(service_params_for(project.id, properties: properties, active: false))
expect { subject.perform(project.id, project.id + 1) }.not_to change { services.order(:id).map { |row| row.attributes } } expect { subject.perform(project.id, project.id + 1) }.not_to change { services.order(:id).map { |row| row.attributes } }
end end
...@@ -123,11 +123,11 @@ RSpec.describe Gitlab::BackgroundMigration::FixProjectsWithoutPrometheusService, ...@@ -123,11 +123,11 @@ RSpec.describe Gitlab::BackgroundMigration::FixProjectsWithoutPrometheusService,
end end
context 'k8s cluster shared on instance level' do context 'k8s cluster shared on instance level' do
let(:cluster) { clusters.create(name: 'cluster', cluster_type: cluster_types[:instance_type]) } let(:cluster) { clusters.create!(name: 'cluster', cluster_type: cluster_types[:instance_type]) }
context 'with installed prometheus application' do context 'with installed prometheus application' do
before do before do
clusters_applications_prometheus.create(cluster_id: cluster.id, status: application_statuses[:installed], version: '123') clusters_applications_prometheus.create!(cluster_id: cluster.id, status: application_statuses[:installed], version: '123')
end end
it_behaves_like 'fix services entries state' it_behaves_like 'fix services entries state'
...@@ -135,7 +135,7 @@ RSpec.describe Gitlab::BackgroundMigration::FixProjectsWithoutPrometheusService, ...@@ -135,7 +135,7 @@ RSpec.describe Gitlab::BackgroundMigration::FixProjectsWithoutPrometheusService,
context 'with updated prometheus application' do context 'with updated prometheus application' do
before do before do
clusters_applications_prometheus.create(cluster_id: cluster.id, status: application_statuses[:updated], version: '123') clusters_applications_prometheus.create!(cluster_id: cluster.id, status: application_statuses[:updated], version: '123')
end end
it_behaves_like 'fix services entries state' it_behaves_like 'fix services entries state'
...@@ -143,7 +143,7 @@ RSpec.describe Gitlab::BackgroundMigration::FixProjectsWithoutPrometheusService, ...@@ -143,7 +143,7 @@ RSpec.describe Gitlab::BackgroundMigration::FixProjectsWithoutPrometheusService,
context 'with errored prometheus application' do context 'with errored prometheus application' do
before do before do
clusters_applications_prometheus.create(cluster_id: cluster.id, status: application_statuses[:errored], version: '123') clusters_applications_prometheus.create!(cluster_id: cluster.id, status: application_statuses[:errored], version: '123')
end end
it 'does not change services entries' do it 'does not change services entries' do
...@@ -153,26 +153,26 @@ RSpec.describe Gitlab::BackgroundMigration::FixProjectsWithoutPrometheusService, ...@@ -153,26 +153,26 @@ RSpec.describe Gitlab::BackgroundMigration::FixProjectsWithoutPrometheusService,
end end
context 'k8s cluster shared on group level' do context 'k8s cluster shared on group level' do
let(:cluster) { clusters.create(name: 'cluster', cluster_type: cluster_types[:group_type]) } let(:cluster) { clusters.create!(name: 'cluster', cluster_type: cluster_types[:group_type]) }
before do before do
cluster_groups.create(cluster_id: cluster.id, group_id: project.namespace_id) cluster_groups.create!(cluster_id: cluster.id, group_id: project.namespace_id)
end end
context 'with installed prometheus application' do context 'with installed prometheus application' do
before do before do
clusters_applications_prometheus.create(cluster_id: cluster.id, status: application_statuses[:installed], version: '123') clusters_applications_prometheus.create!(cluster_id: cluster.id, status: application_statuses[:installed], version: '123')
end end
it_behaves_like 'fix services entries state' it_behaves_like 'fix services entries state'
context 'second k8s cluster without application available' do context 'second k8s cluster without application available' do
let(:namespace_2) { namespaces.create(name: 'namespace2', path: 'namespace2') } let(:namespace_2) { namespaces.create!(name: 'namespace2', path: 'namespace2') }
let(:project_2) { projects.create(namespace_id: namespace_2.id) } let(:project_2) { projects.create!(namespace_id: namespace_2.id) }
before do before do
cluster_2 = clusters.create(name: 'cluster2', cluster_type: cluster_types[:group_type]) cluster_2 = clusters.create!(name: 'cluster2', cluster_type: cluster_types[:group_type])
cluster_groups.create(cluster_id: cluster_2.id, group_id: project_2.namespace_id) cluster_groups.create!(cluster_id: cluster_2.id, group_id: project_2.namespace_id)
end end
it 'changed only affected services entries' do it 'changed only affected services entries' do
...@@ -184,7 +184,7 @@ RSpec.describe Gitlab::BackgroundMigration::FixProjectsWithoutPrometheusService, ...@@ -184,7 +184,7 @@ RSpec.describe Gitlab::BackgroundMigration::FixProjectsWithoutPrometheusService,
context 'with updated prometheus application' do context 'with updated prometheus application' do
before do before do
clusters_applications_prometheus.create(cluster_id: cluster.id, status: application_statuses[:updated], version: '123') clusters_applications_prometheus.create!(cluster_id: cluster.id, status: application_statuses[:updated], version: '123')
end end
it_behaves_like 'fix services entries state' it_behaves_like 'fix services entries state'
...@@ -192,7 +192,7 @@ RSpec.describe Gitlab::BackgroundMigration::FixProjectsWithoutPrometheusService, ...@@ -192,7 +192,7 @@ RSpec.describe Gitlab::BackgroundMigration::FixProjectsWithoutPrometheusService,
context 'with errored prometheus application' do context 'with errored prometheus application' do
before do before do
clusters_applications_prometheus.create(cluster_id: cluster.id, status: application_statuses[:errored], version: '123') clusters_applications_prometheus.create!(cluster_id: cluster.id, status: application_statuses[:errored], version: '123')
end end
it 'does not change services entries' do it 'does not change services entries' do
...@@ -207,7 +207,7 @@ RSpec.describe Gitlab::BackgroundMigration::FixProjectsWithoutPrometheusService, ...@@ -207,7 +207,7 @@ RSpec.describe Gitlab::BackgroundMigration::FixProjectsWithoutPrometheusService,
context 'with inactive service' do context 'with inactive service' do
it 'does not change services entries' do it 'does not change services entries' do
services.create(service_params_for(project.id)) services.create!(service_params_for(project.id))
expect { subject.perform(project.id, project.id + 1) }.not_to change { services.order(:id).map { |row| row.attributes } } expect { subject.perform(project.id, project.id + 1) }.not_to change { services.order(:id).map { |row| row.attributes } }
end end
...@@ -216,13 +216,13 @@ RSpec.describe Gitlab::BackgroundMigration::FixProjectsWithoutPrometheusService, ...@@ -216,13 +216,13 @@ RSpec.describe Gitlab::BackgroundMigration::FixProjectsWithoutPrometheusService,
end end
context 'k8s cluster for single project' do context 'k8s cluster for single project' do
let(:cluster) { clusters.create(name: 'cluster', cluster_type: cluster_types[:project_type]) } let(:cluster) { clusters.create!(name: 'cluster', cluster_type: cluster_types[:project_type]) }
let(:cluster_projects) { table(:cluster_projects) } let(:cluster_projects) { table(:cluster_projects) }
context 'with installed prometheus application' do context 'with installed prometheus application' do
before do before do
cluster_projects.create(cluster_id: cluster.id, project_id: project.id) cluster_projects.create!(cluster_id: cluster.id, project_id: project.id)
clusters_applications_prometheus.create(cluster_id: cluster.id, status: application_statuses[:installed], version: '123') clusters_applications_prometheus.create!(cluster_id: cluster.id, status: application_statuses[:installed], version: '123')
end end
it 'does not change services entries' do it 'does not change services entries' do
......
...@@ -5,18 +5,18 @@ require 'spec_helper' ...@@ -5,18 +5,18 @@ require 'spec_helper'
RSpec.describe Gitlab::BackgroundMigration::FixUserNamespaceNames, schema: 20190620112608 do RSpec.describe Gitlab::BackgroundMigration::FixUserNamespaceNames, schema: 20190620112608 do
let(:namespaces) { table(:namespaces) } let(:namespaces) { table(:namespaces) }
let(:users) { table(:users) } let(:users) { table(:users) }
let(:user) { users.create(name: "The user's full name", projects_limit: 10, username: 'not-null', email: '1') } let(:user) { users.create!(name: "The user's full name", projects_limit: 10, username: 'not-null', email: '1') }
context 'updating the namespace names' do context 'updating the namespace names' do
it 'updates a user namespace within range' do it 'updates a user namespace within range' do
user2 = users.create(name: "Other user's full name", projects_limit: 10, username: 'also-not-null', email: '2') user2 = users.create!(name: "Other user's full name", projects_limit: 10, username: 'also-not-null', email: '2')
user_namespace1 = namespaces.create( user_namespace1 = namespaces.create!(
id: 2, id: 2,
owner_id: user.id, owner_id: user.id,
name: "Should be the user's name", name: "Should be the user's name",
path: user.username path: user.username
) )
user_namespace2 = namespaces.create( user_namespace2 = namespaces.create!(
id: 3, id: 3,
owner_id: user2.id, owner_id: user2.id,
name: "Should also be the user's name", name: "Should also be the user's name",
...@@ -30,7 +30,7 @@ RSpec.describe Gitlab::BackgroundMigration::FixUserNamespaceNames, schema: 20190 ...@@ -30,7 +30,7 @@ RSpec.describe Gitlab::BackgroundMigration::FixUserNamespaceNames, schema: 20190
end end
it 'does not update namespaces out of range' do it 'does not update namespaces out of range' do
user_namespace = namespaces.create( user_namespace = namespaces.create!(
id: 6, id: 6,
owner_id: user.id, owner_id: user.id,
name: "Should be the user's name", name: "Should be the user's name",
...@@ -42,7 +42,7 @@ RSpec.describe Gitlab::BackgroundMigration::FixUserNamespaceNames, schema: 20190 ...@@ -42,7 +42,7 @@ RSpec.describe Gitlab::BackgroundMigration::FixUserNamespaceNames, schema: 20190
end end
it 'does not update groups owned by the users' do it 'does not update groups owned by the users' do
user_group = namespaces.create( user_group = namespaces.create!(
id: 2, id: 2,
owner_id: user.id, owner_id: user.id,
name: 'A group name', name: 'A group name',
...@@ -58,7 +58,7 @@ RSpec.describe Gitlab::BackgroundMigration::FixUserNamespaceNames, schema: 20190 ...@@ -58,7 +58,7 @@ RSpec.describe Gitlab::BackgroundMigration::FixUserNamespaceNames, schema: 20190
context 'namespace route names' do context 'namespace route names' do
let(:routes) { table(:routes) } let(:routes) { table(:routes) }
let(:namespace) do let(:namespace) do
namespaces.create( namespaces.create!(
id: 2, id: 2,
owner_id: user.id, owner_id: user.id,
name: "Will be updated to the user's name", name: "Will be updated to the user's name",
...@@ -67,7 +67,7 @@ RSpec.describe Gitlab::BackgroundMigration::FixUserNamespaceNames, schema: 20190 ...@@ -67,7 +67,7 @@ RSpec.describe Gitlab::BackgroundMigration::FixUserNamespaceNames, schema: 20190
end end
it "updates the route name if it didn't match the namespace" do it "updates the route name if it didn't match the namespace" do
route = routes.create(path: namespace.path, name: 'Incorrect name', source_type: 'Namespace', source_id: namespace.id) route = routes.create!(path: namespace.path, name: 'Incorrect name', source_type: 'Namespace', source_id: namespace.id)
described_class.new.perform(1, 5) described_class.new.perform(1, 5)
...@@ -75,7 +75,7 @@ RSpec.describe Gitlab::BackgroundMigration::FixUserNamespaceNames, schema: 20190 ...@@ -75,7 +75,7 @@ RSpec.describe Gitlab::BackgroundMigration::FixUserNamespaceNames, schema: 20190
end end
it 'updates the route name if it was nil match the namespace' do it 'updates the route name if it was nil match the namespace' do
route = routes.create(path: namespace.path, name: nil, source_type: 'Namespace', source_id: namespace.id) route = routes.create!(path: namespace.path, name: nil, source_type: 'Namespace', source_id: namespace.id)
described_class.new.perform(1, 5) described_class.new.perform(1, 5)
...@@ -83,14 +83,14 @@ RSpec.describe Gitlab::BackgroundMigration::FixUserNamespaceNames, schema: 20190 ...@@ -83,14 +83,14 @@ RSpec.describe Gitlab::BackgroundMigration::FixUserNamespaceNames, schema: 20190
end end
it "doesn't update group routes" do it "doesn't update group routes" do
route = routes.create(path: 'group-path', name: 'Group name', source_type: 'Group', source_id: namespace.id) route = routes.create!(path: 'group-path', name: 'Group name', source_type: 'Group', source_id: namespace.id)
expect { described_class.new.perform(1, 5) } expect { described_class.new.perform(1, 5) }
.not_to change { route.reload.name } .not_to change { route.reload.name }
end end
it "doesn't touch routes for namespaces out of range" do it "doesn't touch routes for namespaces out of range" do
user_namespace = namespaces.create( user_namespace = namespaces.create!(
id: 6, id: 6,
owner_id: user.id, owner_id: user.id,
name: "Should be the user's name", name: "Should be the user's name",
......
...@@ -8,10 +8,10 @@ RSpec.describe Gitlab::BackgroundMigration::FixUserProjectRouteNames, schema: 20 ...@@ -8,10 +8,10 @@ RSpec.describe Gitlab::BackgroundMigration::FixUserProjectRouteNames, schema: 20
let(:routes) { table(:routes) } let(:routes) { table(:routes) }
let(:projects) { table(:projects) } let(:projects) { table(:projects) }
let(:user) { users.create(name: "The user's full name", projects_limit: 10, username: 'not-null', email: '1') } let(:user) { users.create!(name: "The user's full name", projects_limit: 10, username: 'not-null', email: '1') }
let(:namespace) do let(:namespace) do
namespaces.create( namespaces.create!(
owner_id: user.id, owner_id: user.id,
name: "Should eventually be the user's name", name: "Should eventually be the user's name",
path: user.username path: user.username
...@@ -19,11 +19,11 @@ RSpec.describe Gitlab::BackgroundMigration::FixUserProjectRouteNames, schema: 20 ...@@ -19,11 +19,11 @@ RSpec.describe Gitlab::BackgroundMigration::FixUserProjectRouteNames, schema: 20
end end
let(:project) do let(:project) do
projects.create(namespace_id: namespace.id, name: 'Project Name') projects.create!(namespace_id: namespace.id, name: 'Project Name')
end end
it "updates the route for a project if it did not match the user's name" do it "updates the route for a project if it did not match the user's name" do
route = routes.create( route = routes.create!(
id: 1, id: 1,
path: "#{user.username}/#{project.path}", path: "#{user.username}/#{project.path}",
source_id: project.id, source_id: project.id,
...@@ -37,7 +37,7 @@ RSpec.describe Gitlab::BackgroundMigration::FixUserProjectRouteNames, schema: 20 ...@@ -37,7 +37,7 @@ RSpec.describe Gitlab::BackgroundMigration::FixUserProjectRouteNames, schema: 20
end end
it 'updates the route for a project if the name was nil' do it 'updates the route for a project if the name was nil' do
route = routes.create( route = routes.create!(
id: 1, id: 1,
path: "#{user.username}/#{project.path}", path: "#{user.username}/#{project.path}",
source_id: project.id, source_id: project.id,
...@@ -51,7 +51,7 @@ RSpec.describe Gitlab::BackgroundMigration::FixUserProjectRouteNames, schema: 20 ...@@ -51,7 +51,7 @@ RSpec.describe Gitlab::BackgroundMigration::FixUserProjectRouteNames, schema: 20
end end
it 'does not update routes that were are out of the range' do it 'does not update routes that were are out of the range' do
route = routes.create( route = routes.create!(
id: 6, id: 6,
path: "#{user.username}/#{project.path}", path: "#{user.username}/#{project.path}",
source_id: project.id, source_id: project.id,
...@@ -64,14 +64,14 @@ RSpec.describe Gitlab::BackgroundMigration::FixUserProjectRouteNames, schema: 20 ...@@ -64,14 +64,14 @@ RSpec.describe Gitlab::BackgroundMigration::FixUserProjectRouteNames, schema: 20
end end
it 'does not update routes for projects in groups owned by the user' do it 'does not update routes for projects in groups owned by the user' do
group = namespaces.create( group = namespaces.create!(
owner_id: user.id, owner_id: user.id,
name: 'A group', name: 'A group',
path: 'a-path', path: 'a-path',
type: '' type: ''
) )
project = projects.create(namespace_id: group.id, name: 'Project Name') project = projects.create!(namespace_id: group.id, name: 'Project Name')
route = routes.create( route = routes.create!(
id: 1, id: 1,
path: "#{group.path}/#{project.path}", path: "#{group.path}/#{project.path}",
source_id: project.id, source_id: project.id,
...@@ -84,7 +84,7 @@ RSpec.describe Gitlab::BackgroundMigration::FixUserProjectRouteNames, schema: 20 ...@@ -84,7 +84,7 @@ RSpec.describe Gitlab::BackgroundMigration::FixUserProjectRouteNames, schema: 20
end end
it 'does not update routes for namespaces' do it 'does not update routes for namespaces' do
route = routes.create( route = routes.create!(
id: 1, id: 1,
path: namespace.path, path: namespace.path,
source_id: namespace.id, source_id: namespace.id,
......
...@@ -32,7 +32,7 @@ RSpec.describe Gitlab::BackgroundMigration::LegacyUploadMover, :aggregate_failur ...@@ -32,7 +32,7 @@ RSpec.describe Gitlab::BackgroundMigration::LegacyUploadMover, :aggregate_failur
if with_file if with_file
upload = create(:upload, :with_file, :attachment_upload, params) upload = create(:upload, :with_file, :attachment_upload, params)
model.update(attachment: upload.retrieve_uploader) model.update!(attachment: upload.retrieve_uploader)
model.attachment.upload model.attachment.upload
else else
create(:upload, :attachment_upload, params) create(:upload, :attachment_upload, params)
...@@ -245,7 +245,7 @@ RSpec.describe Gitlab::BackgroundMigration::LegacyUploadMover, :aggregate_failur ...@@ -245,7 +245,7 @@ RSpec.describe Gitlab::BackgroundMigration::LegacyUploadMover, :aggregate_failur
end end
let(:connection) { ::Fog::Storage.new(FileUploader.object_store_credentials) } let(:connection) { ::Fog::Storage.new(FileUploader.object_store_credentials) }
let(:bucket) { connection.directories.create(key: 'uploads') } let(:bucket) { connection.directories.create(key: 'uploads') } # rubocop:disable Rails/SaveBang
before do before do
stub_uploads_object_storage(FileUploader) stub_uploads_object_storage(FileUploader)
...@@ -257,7 +257,7 @@ RSpec.describe Gitlab::BackgroundMigration::LegacyUploadMover, :aggregate_failur ...@@ -257,7 +257,7 @@ RSpec.describe Gitlab::BackgroundMigration::LegacyUploadMover, :aggregate_failur
context 'when the file belongs to a legacy project' do context 'when the file belongs to a legacy project' do
before do before do
bucket.files.create(remote_file) bucket.files.create(remote_file) # rubocop:disable Rails/SaveBang
end end
let(:project) { legacy_project } let(:project) { legacy_project }
...@@ -267,7 +267,7 @@ RSpec.describe Gitlab::BackgroundMigration::LegacyUploadMover, :aggregate_failur ...@@ -267,7 +267,7 @@ RSpec.describe Gitlab::BackgroundMigration::LegacyUploadMover, :aggregate_failur
context 'when the file belongs to a hashed project' do context 'when the file belongs to a hashed project' do
before do before do
bucket.files.create(remote_file) bucket.files.create(remote_file) # rubocop:disable Rails/SaveBang
end end
let(:project) { hashed_project } let(:project) { hashed_project }
......
...@@ -24,7 +24,7 @@ RSpec.describe Gitlab::BackgroundMigration::LegacyUploadsMigrator do ...@@ -24,7 +24,7 @@ RSpec.describe Gitlab::BackgroundMigration::LegacyUploadsMigrator do
if with_file if with_file
upload = create(:upload, :with_file, :attachment_upload, params) upload = create(:upload, :with_file, :attachment_upload, params)
model.update(attachment: upload.retrieve_uploader) model.update!(attachment: upload.retrieve_uploader)
model.attachment.upload model.attachment.upload
else else
create(:upload, :attachment_upload, params) create(:upload, :attachment_upload, params)
......
...@@ -10,44 +10,44 @@ RSpec.describe Gitlab::BackgroundMigration::LinkLfsObjectsProjects, :migration, ...@@ -10,44 +10,44 @@ RSpec.describe Gitlab::BackgroundMigration::LinkLfsObjectsProjects, :migration,
let(:lfs_objects) { table(:lfs_objects) } let(:lfs_objects) { table(:lfs_objects) }
let(:lfs_objects_projects) { table(:lfs_objects_projects) } 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(: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(:another_fork_network) { fork_networks.create!(root_project_id: another_source_project.id) }
let(:source_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(:another_source_project) { projects.create!(namespace_id: namespace.id) }
let(: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(:another_project) { projects.create!(namespace_id: namespace.id) }
let(:partially_linked_project) { projects.create(namespace_id: namespace.id) } let(:partially_linked_project) { projects.create!(namespace_id: namespace.id) }
let(:fully_linked_project) { projects.create(namespace_id: namespace.id) } let(:fully_linked_project) { projects.create!(namespace_id: namespace.id) }
let(:lfs_object) { lfs_objects.create(oid: 'abc123', size: 100) } let(:lfs_object) { lfs_objects.create!(oid: 'abc123', size: 100) }
let(:another_lfs_object) { lfs_objects.create(oid: 'def456', size: 200) } let(:another_lfs_object) { lfs_objects.create!(oid: 'def456', size: 200) }
let!(:source_project_lop_1) do let!(:source_project_lop_1) do
lfs_objects_projects.create( lfs_objects_projects.create!(
lfs_object_id: lfs_object.id, lfs_object_id: lfs_object.id,
project_id: source_project.id project_id: source_project.id
) )
end end
let!(:source_project_lop_2) do let!(:source_project_lop_2) do
lfs_objects_projects.create( lfs_objects_projects.create!(
lfs_object_id: another_lfs_object.id, lfs_object_id: another_lfs_object.id,
project_id: source_project.id project_id: source_project.id
) )
end end
let!(:another_source_project_lop_1) do let!(:another_source_project_lop_1) do
lfs_objects_projects.create( lfs_objects_projects.create!(
lfs_object_id: lfs_object.id, lfs_object_id: lfs_object.id,
project_id: another_source_project.id project_id: another_source_project.id
) )
end end
let!(:another_source_project_lop_2) do let!(:another_source_project_lop_2) do
lfs_objects_projects.create( lfs_objects_projects.create!(
lfs_object_id: another_lfs_object.id, lfs_object_id: another_lfs_object.id,
project_id: another_source_project.id project_id: another_source_project.id
) )
...@@ -57,23 +57,23 @@ RSpec.describe Gitlab::BackgroundMigration::LinkLfsObjectsProjects, :migration, ...@@ -57,23 +57,23 @@ RSpec.describe Gitlab::BackgroundMigration::LinkLfsObjectsProjects, :migration,
stub_const("#{described_class}::BATCH_SIZE", 2) stub_const("#{described_class}::BATCH_SIZE", 2)
# Create links between projects # 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: source_project.id, forked_from_project_id: nil)
[project, partially_linked_project, fully_linked_project].each do |p| [project, partially_linked_project, fully_linked_project].each do |p|
fork_network_members.create( fork_network_members.create!(
fork_network_id: fork_network.id, fork_network_id: fork_network.id,
project_id: p.id, project_id: p.id,
forked_from_project_id: fork_network.root_project_id forked_from_project_id: fork_network.root_project_id
) )
end end
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_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: another_fork_network.id, project_id: another_project.id, forked_from_project_id: another_fork_network.root_project_id)
# Links LFS objects to some projects # Links LFS objects to some projects
lfs_objects_projects.create(lfs_object_id: lfs_object.id, project_id: fully_linked_project.id) lfs_objects_projects.create!(lfs_object_id: lfs_object.id, project_id: fully_linked_project.id)
lfs_objects_projects.create(lfs_object_id: another_lfs_object.id, project_id: fully_linked_project.id) lfs_objects_projects.create!(lfs_object_id: another_lfs_object.id, project_id: fully_linked_project.id)
lfs_objects_projects.create(lfs_object_id: lfs_object.id, project_id: partially_linked_project.id) lfs_objects_projects.create!(lfs_object_id: lfs_object.id, project_id: partially_linked_project.id)
end end
context 'when there are LFS objects to be linked' do context 'when there are LFS objects to be linked' do
...@@ -96,8 +96,8 @@ RSpec.describe Gitlab::BackgroundMigration::LinkLfsObjectsProjects, :migration, ...@@ -96,8 +96,8 @@ RSpec.describe Gitlab::BackgroundMigration::LinkLfsObjectsProjects, :migration,
before do before do
# Links LFS objects to all projects # Links LFS objects to all projects
projects.all.each do |p| projects.all.each do |p|
lfs_objects_projects.create(lfs_object_id: lfs_object.id, project_id: p.id) lfs_objects_projects.create!(lfs_object_id: lfs_object.id, project_id: p.id)
lfs_objects_projects.create(lfs_object_id: another_lfs_object.id, project_id: p.id) lfs_objects_projects.create!(lfs_object_id: another_lfs_object.id, project_id: p.id)
end end
end end
......
...@@ -97,7 +97,7 @@ RSpec.describe Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData, s ...@@ -97,7 +97,7 @@ RSpec.describe Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData, s
context 'with Jira service' do context 'with Jira service' do
let!(:service) do let!(:service) do
services.create(id: 10, type: 'JiraService', title: nil, properties: jira_properties.to_json, category: 'issue_tracker') services.create!(id: 10, type: 'JiraService', title: nil, properties: jira_properties.to_json, category: 'issue_tracker')
end end
it_behaves_like 'handle properties' it_behaves_like 'handle properties'
...@@ -119,7 +119,7 @@ RSpec.describe Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData, s ...@@ -119,7 +119,7 @@ RSpec.describe Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData, s
context 'with bugzilla service' do context 'with bugzilla service' do
let!(:service) do let!(:service) do
services.create(id: 11, type: 'BugzillaService', title: nil, properties: tracker_properties.to_json, category: 'issue_tracker') services.create!(id: 11, type: 'BugzillaService', title: nil, properties: tracker_properties.to_json, category: 'issue_tracker')
end end
it_behaves_like 'handle properties' it_behaves_like 'handle properties'
...@@ -140,7 +140,7 @@ RSpec.describe Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData, s ...@@ -140,7 +140,7 @@ RSpec.describe Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData, s
context 'with youtrack service' do context 'with youtrack service' do
let!(:service) do let!(:service) do
services.create(id: 12, type: 'YoutrackService', title: nil, properties: tracker_properties_no_url.to_json, category: 'issue_tracker') services.create!(id: 12, type: 'YoutrackService', title: nil, properties: tracker_properties_no_url.to_json, category: 'issue_tracker')
end end
it_behaves_like 'handle properties' it_behaves_like 'handle properties'
...@@ -161,7 +161,7 @@ RSpec.describe Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData, s ...@@ -161,7 +161,7 @@ RSpec.describe Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData, s
context 'with gitlab service with no properties' do context 'with gitlab service with no properties' do
let!(:service) do let!(:service) do
services.create(id: 13, type: 'GitlabIssueTrackerService', title: nil, properties: {}, category: 'issue_tracker') services.create!(id: 13, type: 'GitlabIssueTrackerService', title: nil, properties: {}, category: 'issue_tracker')
end end
it_behaves_like 'handle properties' it_behaves_like 'handle properties'
...@@ -173,7 +173,7 @@ RSpec.describe Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData, s ...@@ -173,7 +173,7 @@ RSpec.describe Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData, s
context 'with redmine service already with data fields' do context 'with redmine service already with data fields' do
let!(:service) do let!(:service) do
services.create(id: 14, type: 'RedmineService', title: nil, properties: tracker_properties_no_url.to_json, category: 'issue_tracker').tap do |service| services.create!(id: 14, type: 'RedmineService', title: nil, properties: tracker_properties_no_url.to_json, category: 'issue_tracker').tap do |service|
IssueTrackerData.create!(service_id: service.id, project_url: url, new_issue_url: new_issue_url, issues_url: issues_url) IssueTrackerData.create!(service_id: service.id, project_url: url, new_issue_url: new_issue_url, issues_url: issues_url)
end end
end end
...@@ -187,7 +187,7 @@ RSpec.describe Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData, s ...@@ -187,7 +187,7 @@ RSpec.describe Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData, s
context 'with custom issue tracker which has data fields record inconsistent with properties field' do context 'with custom issue tracker which has data fields record inconsistent with properties field' do
let!(:service) do let!(:service) do
services.create(id: 15, type: 'CustomIssueTrackerService', title: 'Existing title', properties: jira_properties.to_json, category: 'issue_tracker').tap do |service| services.create!(id: 15, type: 'CustomIssueTrackerService', title: 'Existing title', properties: jira_properties.to_json, category: 'issue_tracker').tap do |service|
IssueTrackerData.create!(service_id: service.id, project_url: 'http://other_url', new_issue_url: 'http://other_url/new_issue', issues_url: 'http://other_url/issues') IssueTrackerData.create!(service_id: service.id, project_url: 'http://other_url', new_issue_url: 'http://other_url/new_issue', issues_url: 'http://other_url/issues')
end end
end end
...@@ -209,7 +209,7 @@ RSpec.describe Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData, s ...@@ -209,7 +209,7 @@ RSpec.describe Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData, s
context 'with Jira service which has data fields record inconsistent with properties field' do context 'with Jira service which has data fields record inconsistent with properties field' do
let!(:service) do let!(:service) do
services.create(id: 16, type: 'CustomIssueTrackerService', description: 'Existing description', properties: jira_properties.to_json, category: 'issue_tracker').tap do |service| services.create!(id: 16, type: 'CustomIssueTrackerService', description: 'Existing description', properties: jira_properties.to_json, category: 'issue_tracker').tap do |service|
JiraTrackerData.create!(service_id: service.id, url: 'http://other_jira_url') JiraTrackerData.create!(service_id: service.id, url: 'http://other_jira_url')
end end
end end
...@@ -232,7 +232,7 @@ RSpec.describe Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData, s ...@@ -232,7 +232,7 @@ RSpec.describe Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData, s
context 'non issue tracker service' do context 'non issue tracker service' do
let!(:service) do let!(:service) do
services.create(id: 17, title: nil, description: nil, type: 'OtherService', properties: tracker_properties.to_json) services.create!(id: 17, title: nil, description: nil, type: 'OtherService', properties: tracker_properties.to_json)
end end
it_behaves_like 'handle properties' it_behaves_like 'handle properties'
...@@ -248,7 +248,7 @@ RSpec.describe Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData, s ...@@ -248,7 +248,7 @@ RSpec.describe Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData, s
context 'Jira service with empty properties' do context 'Jira service with empty properties' do
let!(:service) do let!(:service) do
services.create(id: 18, type: 'JiraService', properties: '', category: 'issue_tracker') services.create!(id: 18, type: 'JiraService', properties: '', category: 'issue_tracker')
end end
it_behaves_like 'handle properties' it_behaves_like 'handle properties'
...@@ -260,7 +260,7 @@ RSpec.describe Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData, s ...@@ -260,7 +260,7 @@ RSpec.describe Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData, s
context 'Jira service with nil properties' do context 'Jira service with nil properties' do
let!(:service) do let!(:service) do
services.create(id: 18, type: 'JiraService', properties: nil, category: 'issue_tracker') services.create!(id: 18, type: 'JiraService', properties: nil, category: 'issue_tracker')
end end
it_behaves_like 'handle properties' it_behaves_like 'handle properties'
...@@ -272,7 +272,7 @@ RSpec.describe Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData, s ...@@ -272,7 +272,7 @@ RSpec.describe Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData, s
context 'Jira service with invalid properties' do context 'Jira service with invalid properties' do
let!(:service) do let!(:service) do
services.create(id: 18, type: 'JiraService', properties: 'invalid data', category: 'issue_tracker') services.create!(id: 18, type: 'JiraService', properties: 'invalid data', category: 'issue_tracker')
end end
it_behaves_like 'handle properties' it_behaves_like 'handle properties'
...@@ -284,15 +284,15 @@ RSpec.describe Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData, s ...@@ -284,15 +284,15 @@ RSpec.describe Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData, s
context 'with Jira service with invalid properties, valid Jira service and valid bugzilla service' do context 'with Jira service with invalid properties, valid Jira service and valid bugzilla service' do
let!(:jira_service_invalid) do let!(:jira_service_invalid) do
services.create(id: 19, title: 'invalid - title', description: 'invalid - description', type: 'JiraService', properties: 'invalid data', category: 'issue_tracker') services.create!(id: 19, title: 'invalid - title', description: 'invalid - description', type: 'JiraService', properties: 'invalid data', category: 'issue_tracker')
end end
let!(:jira_service_valid) do let!(:jira_service_valid) do
services.create(id: 20, type: 'JiraService', properties: jira_properties.to_json, category: 'issue_tracker') services.create!(id: 20, type: 'JiraService', properties: jira_properties.to_json, category: 'issue_tracker')
end end
let!(:bugzilla_service_valid) do let!(:bugzilla_service_valid) do
services.create(id: 11, type: 'BugzillaService', title: nil, properties: tracker_properties.to_json, category: 'issue_tracker') services.create!(id: 11, type: 'BugzillaService', title: nil, properties: tracker_properties.to_json, category: 'issue_tracker')
end end
it 'migrates data for the valid service' do it 'migrates data for the valid service' do
......
...@@ -11,17 +11,17 @@ RSpec.describe Gitlab::BackgroundMigration::MigrateUsersBioToUserDetails, :migra ...@@ -11,17 +11,17 @@ RSpec.describe Gitlab::BackgroundMigration::MigrateUsersBioToUserDetails, :migra
klass klass
end end
let!(:user_needs_migration) { users.create(name: 'user1', email: 'test1@test.com', projects_limit: 1, bio: 'bio') } let!(:user_needs_migration) { users.create!(name: 'user1', email: 'test1@test.com', projects_limit: 1, bio: 'bio') }
let!(:user_needs_no_migration) { users.create(name: 'user2', email: 'test2@test.com', projects_limit: 1) } let!(:user_needs_no_migration) { users.create!(name: 'user2', email: 'test2@test.com', projects_limit: 1) }
let!(:user_also_needs_no_migration) { users.create(name: 'user3', email: 'test3@test.com', projects_limit: 1, bio: '') } let!(:user_also_needs_no_migration) { users.create!(name: 'user3', email: 'test3@test.com', projects_limit: 1, bio: '') }
let!(:user_with_long_bio) { users.create(name: 'user4', email: 'test4@test.com', projects_limit: 1, bio: 'a' * 256) } # 255 is the max let!(:user_with_long_bio) { users.create!(name: 'user4', email: 'test4@test.com', projects_limit: 1, bio: 'a' * 256) } # 255 is the max
let!(:user_already_has_details) { users.create(name: 'user5', email: 'test5@test.com', projects_limit: 1, bio: 'my bio') } let!(:user_already_has_details) { users.create!(name: 'user5', email: 'test5@test.com', projects_limit: 1, bio: 'my bio') }
let!(:existing_user_details) { user_details.find_or_create_by(user_id: user_already_has_details.id).update(bio: 'my bio') } let!(:existing_user_details) { user_details.find_or_create_by!(user_id: user_already_has_details.id).update!(bio: 'my bio') }
# unlikely scenario since we have triggers # unlikely scenario since we have triggers
let!(:user_has_different_details) { users.create(name: 'user6', email: 'test6@test.com', projects_limit: 1, bio: 'different') } let!(:user_has_different_details) { users.create!(name: 'user6', email: 'test6@test.com', projects_limit: 1, bio: 'different') }
let!(:different_existing_user_details) { user_details.find_or_create_by(user_id: user_has_different_details.id).update(bio: 'bio') } let!(:different_existing_user_details) { user_details.find_or_create_by!(user_id: user_has_different_details.id).update!(bio: 'bio') }
let(:user_ids) do let(:user_ids) do
[ [
......
...@@ -63,7 +63,7 @@ RSpec.describe Gitlab::BackgroundMigration::PopulateCanonicalEmails, :migration, ...@@ -63,7 +63,7 @@ RSpec.describe Gitlab::BackgroundMigration::PopulateCanonicalEmails, :migration,
describe 'gracefully handles existing records, some of which may have an already-existing identical canonical_email field' do describe 'gracefully handles existing records, some of which may have an already-existing identical canonical_email field' do
let_it_be(:user_one) { create_user(email: "example.user@gmail.com", id: 1) } let_it_be(:user_one) { create_user(email: "example.user@gmail.com", id: 1) }
let_it_be(:user_two) { create_user(email: "exampleuser@gmail.com", id: 2) } let_it_be(:user_two) { create_user(email: "exampleuser@gmail.com", id: 2) }
let_it_be(:user_email_one) { user_canonical_emails.create(canonical_email: "exampleuser@gmail.com", user_id: user_one.id) } let_it_be(:user_email_one) { user_canonical_emails.create!(canonical_email: "exampleuser@gmail.com", user_id: user_one.id) }
subject { migration.perform(1, 2) } subject { migration.perform(1, 2) }
...@@ -79,7 +79,7 @@ RSpec.describe Gitlab::BackgroundMigration::PopulateCanonicalEmails, :migration, ...@@ -79,7 +79,7 @@ RSpec.describe Gitlab::BackgroundMigration::PopulateCanonicalEmails, :migration,
projects_limit: 0 projects_limit: 0
} }
users.create(default_attributes.merge!(attributes)) users.create!(default_attributes.merge!(attributes))
end end
def canonical_emails(user_id: nil) def canonical_emails(user_id: nil)
......
...@@ -11,8 +11,8 @@ RSpec.describe Gitlab::BackgroundMigration::PopulateMergeRequestAssigneesTable, ...@@ -11,8 +11,8 @@ RSpec.describe Gitlab::BackgroundMigration::PopulateMergeRequestAssigneesTable,
let(:user_2) { users.create!(email: 'test2@example.com', projects_limit: 100, username: 'test') } let(:user_2) { users.create!(email: 'test2@example.com', projects_limit: 100, username: 'test') }
let(:user_3) { users.create!(email: 'test3@example.com', projects_limit: 100, username: 'test') } let(:user_3) { users.create!(email: 'test3@example.com', projects_limit: 100, username: 'test') }
let(:namespace) { namespaces.create(name: 'gitlab', path: 'gitlab-org') } let(:namespace) { namespaces.create!(name: 'gitlab', path: 'gitlab-org') }
let(:project) { projects.create(namespace_id: namespace.id, name: 'foo') } let(:project) { projects.create!(namespace_id: namespace.id, name: 'foo') }
let(:merge_requests) { table(:merge_requests) } let(:merge_requests) { table(:merge_requests) }
let(:merge_request_assignees) { table(:merge_request_assignees) } let(:merge_request_assignees) { table(:merge_request_assignees) }
...@@ -24,7 +24,7 @@ RSpec.describe Gitlab::BackgroundMigration::PopulateMergeRequestAssigneesTable, ...@@ -24,7 +24,7 @@ RSpec.describe Gitlab::BackgroundMigration::PopulateMergeRequestAssigneesTable,
source_branch: 'mr name', source_branch: 'mr name',
title: "mr name#{id}") title: "mr name#{id}")
merge_requests.create(params) merge_requests.create!(params)
end end
before do before do
......
...@@ -18,7 +18,7 @@ RSpec.describe Gitlab::BackgroundMigration::PopulateUserHighestRolesTable, schem ...@@ -18,7 +18,7 @@ RSpec.describe Gitlab::BackgroundMigration::PopulateUserHighestRolesTable, schem
projects_limit: 0 projects_limit: 0
}.merge(params) }.merge(params)
users.create(user_params) users.create!(user_params)
end end
def create_member(id, access_level, params = {}) def create_member(id, access_level, params = {})
...@@ -30,7 +30,7 @@ RSpec.describe Gitlab::BackgroundMigration::PopulateUserHighestRolesTable, schem ...@@ -30,7 +30,7 @@ RSpec.describe Gitlab::BackgroundMigration::PopulateUserHighestRolesTable, schem
notification_level: 0 notification_level: 0
}.merge(params) }.merge(params)
members.create(params) members.create!(params)
end end
before do before do
...@@ -47,7 +47,7 @@ RSpec.describe Gitlab::BackgroundMigration::PopulateUserHighestRolesTable, schem ...@@ -47,7 +47,7 @@ RSpec.describe Gitlab::BackgroundMigration::PopulateUserHighestRolesTable, schem
create_member(7, 30) create_member(7, 30)
create_member(8, 20, requested_at: Time.current) create_member(8, 20, requested_at: Time.current)
user_highest_roles.create(user_id: 1, highest_access_level: 50) user_highest_roles.create!(user_id: 1, highest_access_level: 50)
end end
describe '#perform' do describe '#perform' do
......
...@@ -91,7 +91,7 @@ RSpec.describe Gitlab::BackgroundMigration::RecalculateProjectAuthorizations, sc ...@@ -91,7 +91,7 @@ RSpec.describe Gitlab::BackgroundMigration::RecalculateProjectAuthorizations, sc
projects_table.create!(id: 1, name: 'project', path: 'project', visibility_level: 0, projects_table.create!(id: 1, name: 'project', path: 'project', visibility_level: 0,
namespace_id: shared_group.id) namespace_id: shared_group.id)
group_group_links.create(shared_group_id: shared_group.id, shared_with_group_id: group.id, group_group_links.create!(shared_group_id: shared_group.id, shared_with_group_id: group.id,
group_access: 20) group_access: 20)
end end
...@@ -111,7 +111,7 @@ RSpec.describe Gitlab::BackgroundMigration::RecalculateProjectAuthorizations, sc ...@@ -111,7 +111,7 @@ RSpec.describe Gitlab::BackgroundMigration::RecalculateProjectAuthorizations, sc
shared_project = projects_table.create!(id: 1, name: 'shared project', path: 'shared-project', shared_project = projects_table.create!(id: 1, name: 'shared project', path: 'shared-project',
visibility_level: 0, namespace_id: another_group.id) visibility_level: 0, namespace_id: another_group.id)
project_group_links.create(project_id: shared_project.id, group_id: group.id, group_access: 20) project_group_links.create!(project_id: shared_project.id, group_id: group.id, group_access: 20)
end end
it 'creates correct authorization' do it 'creates correct authorization' do
...@@ -174,7 +174,7 @@ RSpec.describe Gitlab::BackgroundMigration::RecalculateProjectAuthorizations, sc ...@@ -174,7 +174,7 @@ RSpec.describe Gitlab::BackgroundMigration::RecalculateProjectAuthorizations, sc
projects_table.create!(id: 1, name: 'project', path: 'project', visibility_level: 0, projects_table.create!(id: 1, name: 'project', path: 'project', visibility_level: 0,
namespace_id: shared_group.id) namespace_id: shared_group.id)
group_group_links.create(shared_group_id: shared_group.id, shared_with_group_id: group.id, group_group_links.create!(shared_group_id: shared_group.id, shared_with_group_id: group.id,
group_access: 20) group_access: 20)
end end
...@@ -192,7 +192,7 @@ RSpec.describe Gitlab::BackgroundMigration::RecalculateProjectAuthorizations, sc ...@@ -192,7 +192,7 @@ RSpec.describe Gitlab::BackgroundMigration::RecalculateProjectAuthorizations, sc
shared_project = projects_table.create!(id: 1, name: 'shared project', path: 'shared-project', shared_project = projects_table.create!(id: 1, name: 'shared project', path: 'shared-project',
visibility_level: 0, namespace_id: another_group.id) visibility_level: 0, namespace_id: another_group.id)
project_group_links.create(project_id: shared_project.id, group_id: group.id, group_access: 20) project_group_links.create!(project_id: shared_project.id, group_id: group.id, group_access: 20)
end end
it 'does not create authorization' do it 'does not create authorization' do
......
...@@ -5,8 +5,8 @@ require 'spec_helper' ...@@ -5,8 +5,8 @@ require 'spec_helper'
RSpec.describe Gitlab::BackgroundMigration::ResetMergeStatus do RSpec.describe Gitlab::BackgroundMigration::ResetMergeStatus do
let(:namespaces) { table(:namespaces) } let(:namespaces) { table(:namespaces) }
let(:projects) { table(:projects) } let(:projects) { table(:projects) }
let(:namespace) { namespaces.create(name: 'gitlab', path: 'gitlab-org') } let(:namespace) { namespaces.create!(name: 'gitlab', path: 'gitlab-org') }
let(:project) { projects.create(namespace_id: namespace.id, name: 'foo') } let(:project) { projects.create!(namespace_id: namespace.id, name: 'foo') }
let(:merge_requests) { table(:merge_requests) } let(:merge_requests) { table(:merge_requests) }
def create_merge_request(id, extra_params = {}) def create_merge_request(id, extra_params = {})
......
...@@ -15,35 +15,35 @@ RSpec.describe MigrateIssueTrackersData do ...@@ -15,35 +15,35 @@ RSpec.describe MigrateIssueTrackersData do
end end
let!(:jira_service) do let!(:jira_service) do
services.create(type: 'JiraService', properties: properties, category: 'issue_tracker') services.create!(type: 'JiraService', properties: properties, category: 'issue_tracker')
end end
let!(:jira_service_nil) do let!(:jira_service_nil) do
services.create(type: 'JiraService', properties: nil, category: 'issue_tracker') services.create!(type: 'JiraService', properties: nil, category: 'issue_tracker')
end end
let!(:bugzilla_service) do let!(:bugzilla_service) do
services.create(type: 'BugzillaService', properties: properties, category: 'issue_tracker') services.create!(type: 'BugzillaService', properties: properties, category: 'issue_tracker')
end end
let!(:youtrack_service) do let!(:youtrack_service) do
services.create(type: 'YoutrackService', properties: properties, category: 'issue_tracker') services.create!(type: 'YoutrackService', properties: properties, category: 'issue_tracker')
end end
let!(:youtrack_service_empty) do let!(:youtrack_service_empty) do
services.create(type: 'YoutrackService', properties: '', category: 'issue_tracker') services.create!(type: 'YoutrackService', properties: '', category: 'issue_tracker')
end end
let!(:gitlab_service) do let!(:gitlab_service) do
services.create(type: 'GitlabIssueTrackerService', properties: properties, category: 'issue_tracker') services.create!(type: 'GitlabIssueTrackerService', properties: properties, category: 'issue_tracker')
end end
let!(:gitlab_service_empty) do let!(:gitlab_service_empty) do
services.create(type: 'GitlabIssueTrackerService', properties: {}, category: 'issue_tracker') services.create!(type: 'GitlabIssueTrackerService', properties: {}, category: 'issue_tracker')
end end
let!(:other_service) do let!(:other_service) do
services.create(type: 'OtherService', properties: properties, category: 'other_category') services.create!(type: 'OtherService', properties: properties, category: 'other_category')
end end
before do before do
......
...@@ -5,16 +5,16 @@ require Rails.root.join('db', 'post_migrate', '20200122123016_backfill_project_s ...@@ -5,16 +5,16 @@ require Rails.root.join('db', 'post_migrate', '20200122123016_backfill_project_s
RSpec.describe BackfillProjectSettings, :sidekiq, schema: 20200114113341 do RSpec.describe BackfillProjectSettings, :sidekiq, schema: 20200114113341 do
let(:projects) { table(:projects) } let(:projects) { table(:projects) }
let(:namespace) { table(:namespaces).create(name: 'user', path: 'user') } let(:namespace) { table(:namespaces).create!(name: 'user', path: 'user') }
let(:project) { projects.create(namespace_id: namespace.id) } let(:project) { projects.create!(namespace_id: namespace.id) }
describe '#up' do describe '#up' do
before do before do
stub_const("#{described_class}::BATCH_SIZE", 2) stub_const("#{described_class}::BATCH_SIZE", 2)
projects.create(id: 1, namespace_id: namespace.id) projects.create!(id: 1, namespace_id: namespace.id)
projects.create(id: 2, namespace_id: namespace.id) projects.create!(id: 2, namespace_id: namespace.id)
projects.create(id: 3, namespace_id: namespace.id) projects.create!(id: 3, namespace_id: namespace.id)
end end
it 'schedules BackfillProjectSettings background jobs' do it 'schedules BackfillProjectSettings background jobs' do
......
...@@ -7,7 +7,7 @@ RSpec.describe RemoveInvalidJiraData do ...@@ -7,7 +7,7 @@ RSpec.describe RemoveInvalidJiraData do
let(:jira_tracker_data) { table(:jira_tracker_data) } let(:jira_tracker_data) { table(:jira_tracker_data) }
let(:services) { table(:services) } let(:services) { table(:services) }
let(:service) { services.create(id: 1) } let(:service) { services.create!(id: 1) }
let(:data) do let(:data) do
{ {
service_id: service.id, service_id: service.id,
...@@ -22,49 +22,49 @@ RSpec.describe RemoveInvalidJiraData do ...@@ -22,49 +22,49 @@ RSpec.describe RemoveInvalidJiraData do
} }
end end
let!(:valid_data) { jira_tracker_data.create(data) } let!(:valid_data) { jira_tracker_data.create!(data) }
let!(:empty_data) { jira_tracker_data.create(service_id: service.id) } let!(:empty_data) { jira_tracker_data.create!(service_id: service.id) }
let!(:invalid_api_url) do let!(:invalid_api_url) do
data[:encrypted_api_url_iv] = nil data[:encrypted_api_url_iv] = nil
jira_tracker_data.create(data) jira_tracker_data.create!(data)
end end
let!(:missing_api_url) do let!(:missing_api_url) do
data[:encrypted_api_url] = '' data[:encrypted_api_url] = ''
data[:encrypted_api_url_iv] = nil data[:encrypted_api_url_iv] = nil
jira_tracker_data.create(data) jira_tracker_data.create!(data)
end end
let!(:invalid_url) do let!(:invalid_url) do
data[:encrypted_url_iv] = nil data[:encrypted_url_iv] = nil
jira_tracker_data.create(data) jira_tracker_data.create!(data)
end end
let!(:missing_url) do let!(:missing_url) do
data[:encrypted_url] = '' data[:encrypted_url] = ''
jira_tracker_data.create(data) jira_tracker_data.create!(data)
end end
let!(:invalid_username) do let!(:invalid_username) do
data[:encrypted_username_iv] = nil data[:encrypted_username_iv] = nil
jira_tracker_data.create(data) jira_tracker_data.create!(data)
end end
let!(:missing_username) do let!(:missing_username) do
data[:encrypted_username] = nil data[:encrypted_username] = nil
data[:encrypted_username_iv] = nil data[:encrypted_username_iv] = nil
jira_tracker_data.create(data) jira_tracker_data.create!(data)
end end
let!(:invalid_password) do let!(:invalid_password) do
data[:encrypted_password_iv] = nil data[:encrypted_password_iv] = nil
jira_tracker_data.create(data) jira_tracker_data.create!(data)
end end
let!(:missing_password) do let!(:missing_password) do
data[:encrypted_password] = nil data[:encrypted_password] = nil
data[:encrypted_username_iv] = nil data[:encrypted_username_iv] = nil
jira_tracker_data.create(data) jira_tracker_data.create!(data)
end end
it 'removes the invalid data' do it 'removes the invalid data' do
......
...@@ -7,7 +7,7 @@ RSpec.describe RemoveInvalidIssueTrackerData do ...@@ -7,7 +7,7 @@ RSpec.describe RemoveInvalidIssueTrackerData do
let(:issue_tracker_data) { table(:issue_tracker_data) } let(:issue_tracker_data) { table(:issue_tracker_data) }
let(:services) { table(:services) } let(:services) { table(:services) }
let(:service) { services.create(id: 1) } let(:service) { services.create!(id: 1) }
let(:data) do let(:data) do
{ {
service_id: service.id, service_id: service.id,
...@@ -20,38 +20,38 @@ RSpec.describe RemoveInvalidIssueTrackerData do ...@@ -20,38 +20,38 @@ RSpec.describe RemoveInvalidIssueTrackerData do
} }
end end
let!(:valid_data) { issue_tracker_data.create(data) } let!(:valid_data) { issue_tracker_data.create!(data) }
let!(:empty_data) { issue_tracker_data.create(service_id: service.id) } let!(:empty_data) { issue_tracker_data.create!(service_id: service.id) }
let!(:invalid_issues_url) do let!(:invalid_issues_url) do
data[:encrypted_issues_url_iv] = nil data[:encrypted_issues_url_iv] = nil
issue_tracker_data.create(data) issue_tracker_data.create!(data)
end end
let!(:missing_issues_url) do let!(:missing_issues_url) do
data[:encrypted_issues_url] = '' data[:encrypted_issues_url] = ''
data[:encrypted_issues_url_iv] = nil data[:encrypted_issues_url_iv] = nil
issue_tracker_data.create(data) issue_tracker_data.create!(data)
end end
let!(:invalid_new_isue_url) do let!(:invalid_new_isue_url) do
data[:encrypted_new_issue_url_iv] = nil data[:encrypted_new_issue_url_iv] = nil
issue_tracker_data.create(data) issue_tracker_data.create!(data)
end end
let!(:missing_new_issue_url) do let!(:missing_new_issue_url) do
data[:encrypted_new_issue_url] = '' data[:encrypted_new_issue_url] = ''
issue_tracker_data.create(data) issue_tracker_data.create!(data)
end end
let!(:invalid_project_url) do let!(:invalid_project_url) do
data[:encrypted_project_url_iv] = nil data[:encrypted_project_url_iv] = nil
issue_tracker_data.create(data) issue_tracker_data.create!(data)
end end
let!(:missing_project_url) do let!(:missing_project_url) do
data[:encrypted_project_url] = nil data[:encrypted_project_url] = nil
data[:encrypted_project_url_iv] = nil data[:encrypted_project_url_iv] = nil
issue_tracker_data.create(data) issue_tracker_data.create!(data)
end end
it 'removes the invalid data' do it 'removes the invalid data' do
......
...@@ -15,35 +15,35 @@ RSpec.describe RescheduleMigrateIssueTrackersData do ...@@ -15,35 +15,35 @@ RSpec.describe RescheduleMigrateIssueTrackersData do
end end
let!(:jira_service) do 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 end
let!(:jira_service_nil) do 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 end
let!(:bugzilla_service) do 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 end
let!(:youtrack_service) do 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 end
let!(:youtrack_service_empty) do 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 end
let!(:gitlab_service) do 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 end
let!(:gitlab_service_empty) do 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 end
let!(:other_service) do 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 end
before do before do
...@@ -69,7 +69,7 @@ RSpec.describe RescheduleMigrateIssueTrackersData do ...@@ -69,7 +69,7 @@ RSpec.describe RescheduleMigrateIssueTrackersData do
let(:jira_tracker_data) { table(:jira_tracker_data) } let(:jira_tracker_data) { table(:jira_tracker_data) }
let!(:valid_issue_tracker_data) do let!(:valid_issue_tracker_data) do
issue_tracker_data.create( issue_tracker_data.create!(
service_id: bugzilla_service.id, service_id: bugzilla_service.id,
encrypted_issues_url: 'http://url.com', encrypted_issues_url: 'http://url.com',
encrypted_issues_url_iv: 'somevalue' encrypted_issues_url_iv: 'somevalue'
...@@ -77,7 +77,7 @@ RSpec.describe RescheduleMigrateIssueTrackersData do ...@@ -77,7 +77,7 @@ RSpec.describe RescheduleMigrateIssueTrackersData do
end end
let!(:invalid_issue_tracker_data) do let!(:invalid_issue_tracker_data) do
issue_tracker_data.create( issue_tracker_data.create!(
service_id: bugzilla_service.id, service_id: bugzilla_service.id,
encrypted_issues_url: 'http:url.com', encrypted_issues_url: 'http:url.com',
encrypted_issues_url_iv: nil encrypted_issues_url_iv: nil
...@@ -85,7 +85,7 @@ RSpec.describe RescheduleMigrateIssueTrackersData do ...@@ -85,7 +85,7 @@ RSpec.describe RescheduleMigrateIssueTrackersData do
end end
let!(:valid_jira_tracker_data) do let!(:valid_jira_tracker_data) do
jira_tracker_data.create( jira_tracker_data.create!(
service_id: bugzilla_service.id, service_id: bugzilla_service.id,
encrypted_url: 'http://url.com', encrypted_url: 'http://url.com',
encrypted_url_iv: 'somevalue' encrypted_url_iv: 'somevalue'
...@@ -93,7 +93,7 @@ RSpec.describe RescheduleMigrateIssueTrackersData do ...@@ -93,7 +93,7 @@ RSpec.describe RescheduleMigrateIssueTrackersData do
end end
let!(:invalid_jira_tracker_data) do let!(:invalid_jira_tracker_data) do
jira_tracker_data.create( jira_tracker_data.create!(
service_id: bugzilla_service.id, service_id: bugzilla_service.id,
encrypted_url: 'http://url.com', encrypted_url: 'http://url.com',
encrypted_url_iv: nil encrypted_url_iv: nil
......
...@@ -9,9 +9,9 @@ RSpec.describe RemoveOrphanedChatNames, schema: 20200313202430 do ...@@ -9,9 +9,9 @@ RSpec.describe RemoveOrphanedChatNames, schema: 20200313202430 do
let(:services) { table(:services) } let(:services) { table(:services) }
let(:chat_names) { table(:chat_names) } let(:chat_names) { table(:chat_names) }
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(:project) { projects.create!(namespace_id: namespace.id) }
let(:service) { services.create(project_id: project.id, type: 'chat') } 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(: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) } let(:orphaned_chat_name) { chat_names.create!(team_id: 'TEAM', service_id: 0, user_id: 12345, chat_id: 12345) }
......
...@@ -8,10 +8,10 @@ RSpec.describe BackfillDeploymentClustersFromDeployments, :migration, :sidekiq, ...@@ -8,10 +8,10 @@ RSpec.describe BackfillDeploymentClustersFromDeployments, :migration, :sidekiq,
it 'schedules BackfillDeploymentClustersFromDeployments background jobs' do it 'schedules BackfillDeploymentClustersFromDeployments background jobs' do
stub_const("#{described_class}::BATCH_SIZE", 2) stub_const("#{described_class}::BATCH_SIZE", 2)
namespace = table(:namespaces).create(name: 'the-namespace', path: 'the-path') namespace = table(:namespaces).create!(name: 'the-namespace', path: 'the-path')
project = table(:projects).create(name: 'the-project', namespace_id: namespace.id) project = table(:projects).create!(name: 'the-project', namespace_id: namespace.id)
environment = table(:environments).create(name: 'the-environment', project_id: project.id, slug: 'slug') environment = table(:environments).create!(name: 'the-environment', project_id: project.id, slug: 'slug')
cluster = table(:clusters).create(name: 'the-cluster') 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 } 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, ...@@ -44,7 +44,7 @@ RSpec.describe BackfillDeploymentClustersFromDeployments, :migration, :sidekiq,
def create_deployment(**data) def create_deployment(**data)
@iid ||= 0 @iid ||= 0
@iid += 1 @iid += 1
table(:deployments).create(iid: @iid, **data) table(:deployments).create!(iid: @iid, **data)
end end
end end
end end
...@@ -10,19 +10,19 @@ RSpec.describe DedupMrMetrics, :migration, schema: 20200526013844 do ...@@ -10,19 +10,19 @@ RSpec.describe DedupMrMetrics, :migration, schema: 20200526013844 do
let(:metrics) { table(:merge_request_metrics) } let(:metrics) { table(:merge_request_metrics) }
let(:merge_request_params) { { source_branch: 'x', target_branch: 'y', target_project_id: project.id } } 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!(:project) { projects.create!(namespace_id: namespace.id) }
let!(:merge_request_1) { merge_requests.create!(merge_request_params) } let!(:merge_request_1) { merge_requests.create!(merge_request_params) }
let!(:merge_request_2) { 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!(: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_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_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_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_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 it 'deduplicates merge_request_metrics table' do
expect { migrate! }.to change { metrics.count }.from(5).to(3) expect { migrate! }.to change { metrics.count }.from(5).to(3)
......
...@@ -6,7 +6,7 @@ require Rails.root.join('db', 'migrate', '20200122161638_add_deploy_token_type_t ...@@ -6,7 +6,7 @@ require Rails.root.join('db', 'migrate', '20200122161638_add_deploy_token_type_t
RSpec.describe AddDeployTokenTypeToDeployTokens do RSpec.describe AddDeployTokenTypeToDeployTokens do
let(:deploy_tokens) { table(:deploy_tokens) } let(:deploy_tokens) { table(:deploy_tokens) }
let(:deploy_token) do let(:deploy_token) do
deploy_tokens.create(name: 'token_test', deploy_tokens.create!(name: 'token_test',
username: 'gitlab+deploy-token-1', username: 'gitlab+deploy-token-1',
token_encrypted: 'dr8rPXwM+Mbs2p3Bg1+gpnXqrnH/wu6vaHdcc7A3isPR67WB', token_encrypted: 'dr8rPXwM+Mbs2p3Bg1+gpnXqrnH/wu6vaHdcc7A3isPR67WB',
read_repository: true, read_repository: true,
......
...@@ -38,7 +38,7 @@ RSpec.describe AddIncidentSettingsToAllExistingProjects, :migration do ...@@ -38,7 +38,7 @@ RSpec.describe AddIncidentSettingsToAllExistingProjects, :migration do
RSpec.shared_context 'with incident settings' do RSpec.shared_context 'with incident settings' do
let(:existing_create_issue) { false } let(:existing_create_issue) { false }
before do before do
project_incident_management_settings.create( project_incident_management_settings.create!(
project_id: project.id, project_id: project.id,
create_issue: existing_create_issue create_issue: existing_create_issue
) )
......
...@@ -12,15 +12,15 @@ RSpec.describe AddUniqueConstraintToApprovalsUserIdAndMergeRequestId do ...@@ -12,15 +12,15 @@ RSpec.describe AddUniqueConstraintToApprovalsUserIdAndMergeRequestId do
describe '#up' do describe '#up' do
before do before do
namespaces.create(id: 1, name: 'ns', path: 'ns') namespaces.create!(id: 1, name: 'ns', path: 'ns')
projects.create(id: 1, namespace_id: 1) 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: 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) merge_requests.create!(id: 2, target_branch: 'master', source_branch: 'feature-2', target_project_id: 1)
end end
it 'deletes duplicate records and keeps the first one' do it 'deletes duplicate records and keeps the first one' do
first_approval = approvals.create(id: 1, 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) approvals.create!(id: 2, merge_request_id: 1, user_id: 1)
migration.up migration.up
......
...@@ -13,7 +13,7 @@ RSpec.describe BackfillAndAddNotNullConstraintToReleasedAtColumnOnReleasesTable ...@@ -13,7 +13,7 @@ RSpec.describe BackfillAndAddNotNullConstraintToReleasedAtColumnOnReleasesTable
it 'fills released_at with the value of created_at' do it 'fills released_at with the value of created_at' do
created_at_a = Time.zone.parse('2019-02-10T08:00:00Z') created_at_a = Time.zone.parse('2019-02-10T08:00:00Z')
created_at_b = Time.zone.parse('2019-03-10T18: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) project = projects.create!(namespace_id: namespace.id)
release_a = releases.create!(project_id: project.id, created_at: created_at_a) 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) release_b = releases.create!(project_id: project.id, created_at: created_at_b)
......
...@@ -6,7 +6,7 @@ require Rails.root.join('db', 'post_migrate', '20200608072931_backfill_imported_ ...@@ -6,7 +6,7 @@ require Rails.root.join('db', 'post_migrate', '20200608072931_backfill_imported_
RSpec.describe BackfillImportedSnippetRepositories do RSpec.describe BackfillImportedSnippetRepositories do
let(:users) { table(:users) } let(:users) { table(:users) }
let(:snippets) { table(:snippets) } 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) def create_snippet(id)
params = { params = {
......
...@@ -13,7 +13,7 @@ RSpec.describe BackfillReleasesTableUpdatedAtAndAddNotNullConstraintsToTimestamp ...@@ -13,7 +13,7 @@ RSpec.describe BackfillReleasesTableUpdatedAtAndAddNotNullConstraintsToTimestamp
it 'fills null updated_at rows with the value of created_at' do 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_a = Time.zone.parse('2014-03-11T04:30:00Z')
created_at_b = Time.zone.parse('2019-09-10T12: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) project = projects.create!(namespace_id: namespace.id)
release_a = releases.create!(project_id: project.id, release_a = releases.create!(project_id: project.id,
released_at: Time.zone.parse('2014-12-10T06:00:00Z'), released_at: Time.zone.parse('2014-12-10T06:00:00Z'),
...@@ -36,7 +36,7 @@ RSpec.describe BackfillReleasesTableUpdatedAtAndAddNotNullConstraintsToTimestamp ...@@ -36,7 +36,7 @@ RSpec.describe BackfillReleasesTableUpdatedAtAndAddNotNullConstraintsToTimestamp
created_at_a = Time.zone.parse('2014-03-11T04:30:00Z') created_at_a = Time.zone.parse('2014-03-11T04:30:00Z')
updated_at_a = Time.zone.parse('2015-01-16T10:00:00Z') updated_at_a = Time.zone.parse('2015-01-16T10:00:00Z')
created_at_b = Time.zone.parse('2019-09-10T12: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) project = projects.create!(namespace_id: namespace.id)
release_a = releases.create!(project_id: project.id, release_a = releases.create!(project_id: project.id,
released_at: Time.zone.parse('2014-12-10T06:00:00Z'), released_at: Time.zone.parse('2014-12-10T06:00:00Z'),
......
...@@ -6,7 +6,7 @@ require Rails.root.join('db', 'post_migrate', '20200420094444_backfill_snippet_r ...@@ -6,7 +6,7 @@ require Rails.root.join('db', 'post_migrate', '20200420094444_backfill_snippet_r
RSpec.describe BackfillSnippetRepositories do RSpec.describe BackfillSnippetRepositories do
let(:users) { table(:users) } let(:users) { table(:users) }
let(:snippets) { table(:snippets) } 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) def create_snippet(id)
params = { params = {
......
...@@ -19,7 +19,7 @@ RSpec.describe EncryptPlaintextAttributesOnApplicationSettings do ...@@ -19,7 +19,7 @@ RSpec.describe EncryptPlaintextAttributesOnApplicationSettings do
describe '#up' do describe '#up' do
it 'encrypts token and saves it' do it 'encrypts token and saves it' do
application_setting = application_settings.create application_setting = application_settings.create!
application_setting.update_columns( application_setting.update_columns(
plaintext_attributes.each_with_object({}) do |plaintext_attribute, attributes| plaintext_attributes.each_with_object({}) do |plaintext_attribute, attributes|
attributes[plaintext_attribute] = plaintext attributes[plaintext_attribute] = plaintext
...@@ -39,7 +39,7 @@ RSpec.describe EncryptPlaintextAttributesOnApplicationSettings do ...@@ -39,7 +39,7 @@ RSpec.describe EncryptPlaintextAttributesOnApplicationSettings do
describe '#down' do describe '#down' do
it 'decrypts encrypted token and saves it' 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| plaintext_attributes.each_with_object({}) do |plaintext_attribute, attributes|
attributes[plaintext_attribute] = plaintext attributes[plaintext_attribute] = plaintext
end end
......
...@@ -6,8 +6,8 @@ require Rails.root.join('db', 'post_migrate', '20190620112608_enqueue_reset_merg ...@@ -6,8 +6,8 @@ require Rails.root.join('db', 'post_migrate', '20190620112608_enqueue_reset_merg
RSpec.describe EnqueueResetMergeStatusSecondRun do RSpec.describe EnqueueResetMergeStatusSecondRun do
let(:namespaces) { table(:namespaces) } let(:namespaces) { table(:namespaces) }
let(:projects) { table(:projects) } let(:projects) { table(:projects) }
let(:namespace) { namespaces.create(name: 'gitlab', path: 'gitlab-org') } let(:namespace) { namespaces.create!(name: 'gitlab', path: 'gitlab-org') }
let(:project) { projects.create(namespace_id: namespace.id, name: 'foo') } let(:project) { projects.create!(namespace_id: namespace.id, name: 'foo') }
let(:merge_requests) { table(:merge_requests) } let(:merge_requests) { table(:merge_requests) }
def create_merge_request(id, extra_params = {}) def create_merge_request(id, extra_params = {})
......
...@@ -6,8 +6,8 @@ require Rails.root.join('db', 'post_migrate', '20190528180441_enqueue_reset_merg ...@@ -6,8 +6,8 @@ require Rails.root.join('db', 'post_migrate', '20190528180441_enqueue_reset_merg
RSpec.describe EnqueueResetMergeStatus do RSpec.describe EnqueueResetMergeStatus do
let(:namespaces) { table(:namespaces) } let(:namespaces) { table(:namespaces) }
let(:projects) { table(:projects) } let(:projects) { table(:projects) }
let(:namespace) { namespaces.create(name: 'gitlab', path: 'gitlab-org') } let(:namespace) { namespaces.create!(name: 'gitlab', path: 'gitlab-org') }
let(:project) { projects.create(namespace_id: namespace.id, name: 'foo') } let(:project) { projects.create!(namespace_id: namespace.id, name: 'foo') }
let(:merge_requests) { table(:merge_requests) } let(:merge_requests) { table(:merge_requests) }
def create_merge_request(id, extra_params = {}) def create_merge_request(id, extra_params = {})
......
...@@ -9,7 +9,7 @@ RSpec.describe FillFileStoreLfsObjects do ...@@ -9,7 +9,7 @@ RSpec.describe FillFileStoreLfsObjects do
context 'when file_store is nil' do context 'when file_store is nil' do
it 'updates file_store to local' 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) lfs_object = lfs_objects.find_by(oid: oid)
expect { migrate! }.to change { lfs_object.reload.file_store }.from(nil).to(1) expect { migrate! }.to change { lfs_object.reload.file_store }.from(nil).to(1)
...@@ -18,7 +18,7 @@ RSpec.describe FillFileStoreLfsObjects do ...@@ -18,7 +18,7 @@ RSpec.describe FillFileStoreLfsObjects do
context 'when file_store is set to local' do context 'when file_store is set to local' do
it 'does not update file_store' 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) lfs_object = lfs_objects.find_by(oid: oid)
expect { migrate! }.not_to change { lfs_object.reload.file_store } expect { migrate! }.not_to change { lfs_object.reload.file_store }
...@@ -27,7 +27,7 @@ RSpec.describe FillFileStoreLfsObjects do ...@@ -27,7 +27,7 @@ RSpec.describe FillFileStoreLfsObjects do
context 'when file_store is set to object storage' do context 'when file_store is set to object storage' do
it 'does not update file_store' 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) lfs_object = lfs_objects.find_by(oid: oid)
expect { migrate! }.not_to change { lfs_object.reload.file_store } expect { migrate! }.not_to change { lfs_object.reload.file_store }
......
...@@ -9,7 +9,7 @@ RSpec.describe FillStoreUploads do ...@@ -9,7 +9,7 @@ RSpec.describe FillStoreUploads do
context 'when store is nil' do context 'when store is nil' do
it 'updates store to local' do it 'updates store to local' do
uploads.create(size: 100.kilobytes, uploads.create!(size: 100.kilobytes,
uploader: 'AvatarUploader', uploader: 'AvatarUploader',
path: path, path: path,
store: nil) store: nil)
...@@ -22,7 +22,7 @@ RSpec.describe FillStoreUploads do ...@@ -22,7 +22,7 @@ RSpec.describe FillStoreUploads do
context 'when store is set to local' do context 'when store is set to local' do
it 'does not update store' do it 'does not update store' do
uploads.create(size: 100.kilobytes, uploads.create!(size: 100.kilobytes,
uploader: 'AvatarUploader', uploader: 'AvatarUploader',
path: path, path: path,
store: 1) store: 1)
...@@ -35,7 +35,7 @@ RSpec.describe FillStoreUploads do ...@@ -35,7 +35,7 @@ RSpec.describe FillStoreUploads do
context 'when store is set to object storage' do context 'when store is set to object storage' do
it 'does not update store' do it 'does not update store' do
uploads.create(size: 100.kilobytes, uploads.create!(size: 100.kilobytes,
uploader: 'AvatarUploader', uploader: 'AvatarUploader',
path: path, path: path,
store: 2) store: 2)
......
...@@ -10,14 +10,14 @@ RSpec.describe FixNullTypeLabels do ...@@ -10,14 +10,14 @@ RSpec.describe FixNullTypeLabels do
let(:labels) { table(:labels) } let(:labels) { table(:labels) }
before do 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') project = projects.create!(namespace_id: group.id, name: 'labels-test-group', path: 'labels-test-group')
@template_label = labels.create(title: 'template', template: true) @template_label = labels.create!(title: 'template', template: true)
@project_label = labels.create(title: 'project label', project_id: project.id, type: 'ProjectLabel') @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') @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_1 = labels.create!(title: 'broken 1', project_id: project.id)
@broken_label_2 = labels.create(title: 'broken 2', project_id: project.id) @broken_label_2 = labels.create!(title: 'broken 2', project_id: project.id)
end end
describe '#up' do describe '#up' do
......
...@@ -13,11 +13,11 @@ RSpec.describe FixPoolRepositorySourceProjectId do ...@@ -13,11 +13,11 @@ RSpec.describe FixPoolRepositorySourceProjectId do
# gitaly is a project with a pool repository that has a source_project_id # 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) 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) gitaly.update_column(:pool_repository_id, pool_repository.id)
# gitlab is a project with a pool repository that's missing a source_project_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) 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) projects.create!(name: 'gitlab-fork-1', path: 'my-org-1/gitlab-ce', namespace_id: 1, pool_repository_id: pool_repository_without_source_project.id)
......
...@@ -4,13 +4,13 @@ require 'spec_helper' ...@@ -4,13 +4,13 @@ require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20200127111840_fix_projects_without_project_feature.rb') require Rails.root.join('db', 'post_migrate', '20200127111840_fix_projects_without_project_feature.rb')
RSpec.describe FixProjectsWithoutProjectFeature do 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 let!(:projects) do
[ [
table(:projects).create(namespace_id: namespace.id, name: 'foo 1'), 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 2'),
table(:projects).create(namespace_id: namespace.id, name: 'foo 3') table(:projects).create!(namespace_id: namespace.id, name: 'foo 3')
] ]
end end
......
...@@ -4,13 +4,13 @@ require 'spec_helper' ...@@ -4,13 +4,13 @@ require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20200220115023_fix_projects_without_prometheus_service.rb') require Rails.root.join('db', 'post_migrate', '20200220115023_fix_projects_without_prometheus_service.rb')
RSpec.describe FixProjectsWithoutPrometheusService, :migration do 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 let!(:projects) do
[ [
table(:projects).create(namespace_id: namespace.id, name: 'foo 1'), 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 2'),
table(:projects).create(namespace_id: namespace.id, name: 'foo 3') table(:projects).create!(namespace_id: namespace.id, name: 'foo 3')
] ]
end end
......
...@@ -17,7 +17,7 @@ RSpec.describe FixWrongPagesAccessLevel, :sidekiq_might_not_need_inline, schema: ...@@ -17,7 +17,7 @@ RSpec.describe FixWrongPagesAccessLevel, :sidekiq_might_not_need_inline, schema:
let(:features_table) { table(:project_features) } let(:features_table) { table(:project_features) }
let(:subgroup) do 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) namespaces_table.create!(path: "subgroup", name: "group", parent_id: root_group.id)
end end
......
...@@ -9,11 +9,11 @@ RSpec.describe InsertProjectHooksPlanLimits do ...@@ -9,11 +9,11 @@ RSpec.describe InsertProjectHooksPlanLimits do
let(:plan_limits) { table(:plan_limits) } let(:plan_limits) { table(:plan_limits) }
before do before do
plans.create(id: 34, name: 'free') plans.create!(id: 34, name: 'free')
plans.create(id: 2, name: 'bronze') plans.create!(id: 2, name: 'bronze')
plans.create(id: 3, name: 'silver') plans.create!(id: 3, name: 'silver')
plans.create(id: 4, name: 'gold') plans.create!(id: 4, name: 'gold')
plan_limits.create(plan_id: 34, ci_active_jobs: 5) plan_limits.create!(plan_id: 34, ci_active_jobs: 5)
end end
context 'when on Gitlab.com' do context 'when on Gitlab.com' do
......
...@@ -80,7 +80,7 @@ RSpec.describe MigrateAutoDevOpsDomainToClusterDomain do ...@@ -80,7 +80,7 @@ RSpec.describe MigrateAutoDevOpsDomainToClusterDomain do
cluster_projects.each do |cluster_project| cluster_projects.each do |cluster_project|
specific_domain = "#{cluster_project.id}-#{domain}" if domain specific_domain = "#{cluster_project.id}-#{domain}" if domain
project_auto_devops_table.create( project_auto_devops_table.create!(
project_id: cluster_project.project_id, project_id: cluster_project.project_id,
enabled: true, enabled: true,
domain: specific_domain domain: specific_domain
......
...@@ -7,11 +7,11 @@ RSpec.describe MoveLimitsFromPlans do ...@@ -7,11 +7,11 @@ RSpec.describe MoveLimitsFromPlans do
let(:plans) { table(:plans) } let(:plans) { table(:plans) }
let(:plan_limits) { table(:plan_limits) } 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!(: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!(: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!(: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!(: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!(:other_plan) { plans.create!(name: 'other', title: 'Other', active_pipelines_limit: nil, pipeline_size_limit: nil, active_jobs_limit: 0) }
describe 'migrate' do describe 'migrate' do
it 'populates plan_limits from all the records in plans' do it 'populates plan_limits from all the records in plans' do
......
...@@ -16,7 +16,7 @@ RSpec.describe PopulateProjectStatisticsPackagesSize do ...@@ -16,7 +16,7 @@ RSpec.describe PopulateProjectStatisticsPackagesSize do
let(:artifacts_size) { 4.terabytes } let(:artifacts_size) { 4.terabytes }
let(:storage_size) { repo_size + lfs_size + artifacts_size } 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(:package) { packages.create!(project_id: project.id, name: 'a package', package_type: 1) }
let(:project) { projects.create!(namespace_id: namespace.id) } let(:project) { projects.create!(namespace_id: namespace.id) }
......
...@@ -11,42 +11,42 @@ RSpec.describe ScheduleLinkLfsObjectsProjects, :migration, :sidekiq do ...@@ -11,42 +11,42 @@ RSpec.describe ScheduleLinkLfsObjectsProjects, :migration, :sidekiq do
let(:lfs_objects) { table(:lfs_objects) } let(:lfs_objects) { table(:lfs_objects) }
let(:lfs_objects_projects) { table(:lfs_objects_projects) } 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(: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(:another_fork_network) { fork_networks.create!(root_project_id: another_source_project.id) }
let(:source_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(:another_source_project) { projects.create!(namespace_id: namespace.id) }
let(: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(:another_project) { projects.create!(namespace_id: namespace.id) }
let(:lfs_object) { lfs_objects.create(oid: 'abc123', size: 100) } let(:lfs_object) { lfs_objects.create!(oid: 'abc123', size: 100) }
let(:another_lfs_object) { lfs_objects.create(oid: 'def456', size: 200) } let(:another_lfs_object) { lfs_objects.create!(oid: 'def456', size: 200) }
let!(:source_project_lop_1) do let!(:source_project_lop_1) do
lfs_objects_projects.create( lfs_objects_projects.create!(
lfs_object_id: lfs_object.id, lfs_object_id: lfs_object.id,
project_id: source_project.id project_id: source_project.id
) )
end end
let!(:source_project_lop_2) do let!(:source_project_lop_2) do
lfs_objects_projects.create( lfs_objects_projects.create!(
lfs_object_id: another_lfs_object.id, lfs_object_id: another_lfs_object.id,
project_id: source_project.id project_id: source_project.id
) )
end end
let!(:another_source_project_lop_1) do let!(:another_source_project_lop_1) do
lfs_objects_projects.create( lfs_objects_projects.create!(
lfs_object_id: lfs_object.id, lfs_object_id: lfs_object.id,
project_id: another_source_project.id project_id: another_source_project.id
) )
end end
let!(:another_source_project_lop_2) do let!(:another_source_project_lop_2) do
lfs_objects_projects.create( lfs_objects_projects.create!(
lfs_object_id: another_lfs_object.id, lfs_object_id: another_lfs_object.id,
project_id: another_source_project.id project_id: another_source_project.id
) )
...@@ -56,10 +56,10 @@ RSpec.describe ScheduleLinkLfsObjectsProjects, :migration, :sidekiq do ...@@ -56,10 +56,10 @@ RSpec.describe ScheduleLinkLfsObjectsProjects, :migration, :sidekiq do
stub_const("#{described_class.name}::BATCH_SIZE", 2) stub_const("#{described_class.name}::BATCH_SIZE", 2)
# Create links between projects # 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: 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: 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_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: another_fork_network.id, project_id: another_project.id, forked_from_project_id: another_fork_network.root_project_id)
end end
it 'schedules background migration to link LFS objects' do it 'schedules background migration to link LFS objects' do
......
...@@ -6,8 +6,8 @@ require Rails.root.join('db', 'post_migrate', '20190322132835_schedule_populate_ ...@@ -6,8 +6,8 @@ require Rails.root.join('db', 'post_migrate', '20190322132835_schedule_populate_
RSpec.describe SchedulePopulateMergeRequestAssigneesTable do RSpec.describe SchedulePopulateMergeRequestAssigneesTable do
let(:namespaces) { table(:namespaces) } let(:namespaces) { table(:namespaces) }
let(:projects) { table(:projects) } let(:projects) { table(:projects) }
let(:namespace) { namespaces.create(name: 'gitlab', path: 'gitlab-org') } let(:namespace) { namespaces.create!(name: 'gitlab', path: 'gitlab-org') }
let(:project) { projects.create(namespace_id: namespace.id, name: 'foo') } let(:project) { projects.create!(namespace_id: namespace.id, name: 'foo') }
let(:merge_requests) { table(:merge_requests) } let(:merge_requests) { table(:merge_requests) }
def create_merge_request(id) def create_merge_request(id)
......
...@@ -17,7 +17,7 @@ RSpec.describe SeedRepositoryStoragesWeighted do ...@@ -17,7 +17,7 @@ RSpec.describe SeedRepositoryStoragesWeighted do
allow(Gitlab.config.repositories).to receive(:storages).and_return(storages) allow(Gitlab.config.repositories).to receive(:storages).and_return(storages)
end end
let(:application_setting) { application_settings.create } let(:application_setting) { application_settings.create! }
let(:repository_storages) { ["foo"] } let(:repository_storages) { ["foo"] }
it 'correctly schedules background migrations' do it 'correctly schedules background migrations' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment