diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-20 12:40:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-20 12:40:42 +0300 |
commit | ee664acb356f8123f4f6b00b73c1e1cf0866c7fb (patch) | |
tree | f8479f94a28f66654c6a4f6fb99bad6b4e86a40e /spec/migrations | |
parent | 62f7d5c5b69180e82ae8196b7b429eeffc8e7b4f (diff) |
Add latest changes from gitlab-org/gitlab@15-5-stable-eev15.5.0-rc42
Diffstat (limited to 'spec/migrations')
17 files changed, 602 insertions, 46 deletions
diff --git a/spec/migrations/20220901035725_schedule_destroy_invalid_project_members_spec.rb b/spec/migrations/20220920124709_backfill_internal_on_notes_spec.rb index ed9f7e3cd44..f4ac6e6fc8e 100644 --- a/spec/migrations/20220901035725_schedule_destroy_invalid_project_members_spec.rb +++ b/spec/migrations/20220920124709_backfill_internal_on_notes_spec.rb @@ -3,19 +3,19 @@ require 'spec_helper' require_migration! -RSpec.describe ScheduleDestroyInvalidProjectMembers, :migration do - let_it_be(:migration) { described_class::MIGRATION } +RSpec.describe BackfillInternalOnNotes, :migration do + let(:migration) { described_class::MIGRATION } describe '#up' do - it 'schedules background jobs for each batch of members' do + it 'schedules background jobs for each batch of issues' do migrate! expect(migration).to have_scheduled_batched_migration( - table_name: :members, + table_name: :notes, column_name: :id, interval: described_class::DELAY_INTERVAL, batch_size: described_class::BATCH_SIZE, - max_batch_size: described_class::MAX_BATCH_SIZE + sub_batch_size: described_class::SUB_BATCH_SIZE ) end end diff --git a/spec/migrations/20220921093355_schedule_backfill_namespace_details_spec.rb b/spec/migrations/20220921093355_schedule_backfill_namespace_details_spec.rb new file mode 100644 index 00000000000..61e4af3d10c --- /dev/null +++ b/spec/migrations/20220921093355_schedule_backfill_namespace_details_spec.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +require 'spec_helper' +require_migration! + +RSpec.describe ScheduleBackfillNamespaceDetails, schema: 20220921093355 do + context 'when on gitlab.com' do + let(:background_migration) { described_class::MIGRATION } + let(:migration) { described_class.new } + + before do + migration.up + end + + describe '#up' do + it 'schedules background jobs for each batch of projects' do + expect(background_migration).to( + have_scheduled_batched_migration( + table_name: :namespaces, + column_name: :id, + interval: described_class::INTERVAL, + batch_size: described_class::BATCH_SIZE, + sub_batch_size: described_class::SUB_BATCH_SIZE + ) + ) + end + end + + describe '#down' do + it 'deletes all batched migration records' do + migration.down + + expect(described_class::MIGRATION).not_to have_scheduled_batched_migration + end + end + end +end diff --git a/spec/migrations/20220921144258_remove_orphan_group_token_users_spec.rb b/spec/migrations/20220921144258_remove_orphan_group_token_users_spec.rb new file mode 100644 index 00000000000..614044657ec --- /dev/null +++ b/spec/migrations/20220921144258_remove_orphan_group_token_users_spec.rb @@ -0,0 +1,74 @@ +# frozen_string_literal: true + +require 'spec_helper' + +require_migration! + +RSpec.describe RemoveOrphanGroupTokenUsers, :migration, :sidekiq_inline do + subject(:migration) { described_class.new } + + let(:users) { table(:users) } + let!(:orphan_bot) do + create_bot(username: 'orphan_bot', email: 'orphan_bot@bot.com').tap do |bot| + namespaces.create!(type: 'User', path: 'n1', name: 'n1', owner_id: bot.id) + end + end + + let!(:valid_used_bot) do + create_bot(username: 'used_bot', email: 'used_bot@bot.com').tap do |bot| + group = namespaces.create!(type: 'Group', path: 'used_bot_group', name: 'used_bot_group') + members.create!(user_id: bot.id, + source_id: group.id, + member_namespace_id: group.id, + source_type: 'Group', + access_level: 10, + notification_level: 0) + end + end + + let!(:different_bot) do + create_bot(username: 'other_bot', email: 'other_bot@bot.com', user_type: 5) + end + + let(:personal_access_tokens) { table(:personal_access_tokens) } + let(:members) { table(:members) } + let(:namespaces) { table(:namespaces) } + + before do + stub_feature_flags(user_destroy_with_limited_execution_time_worker: false) + end + + it 'removes orphan project bot and its tokens', :aggregate_failures do + expect(DeleteUserWorker) + .to receive(:perform_async) + .with(orphan_bot.id, orphan_bot.id, skip_authorization: true) + .and_call_original + + migrate! + + expect(users.count).to eq 2 + expect(personal_access_tokens.count).to eq 2 + expect(personal_access_tokens.find_by(user_id: orphan_bot.id)).to eq nil + end + + context "when DeleteUserWorker doesn't fit anymore" do + it 'removes project bot tokens only', :aggregate_failures do + allow(DeleteUserWorker).to receive(:respond_to?).and_call_original + allow(DeleteUserWorker).to receive(:respond_to?).with(:perform_async).and_return(false) + + migrate! + + expect(users.count).to eq 3 + expect(personal_access_tokens.count).to eq 2 + expect(personal_access_tokens.find_by(user_id: orphan_bot.id)).to eq nil + end + end + + private + + def create_bot(**params) + users.create!({ projects_limit: 0, state: 'active', user_type: 6 }.merge(params)).tap do |bot| + personal_access_tokens.create!(user_id: bot.id, name: "BOT##{bot.id}") + end + end +end diff --git a/spec/migrations/20220922143143_schedule_reset_duplicate_ci_runners_token_values_spec.rb b/spec/migrations/20220922143143_schedule_reset_duplicate_ci_runners_token_values_spec.rb new file mode 100644 index 00000000000..409f7d544ee --- /dev/null +++ b/spec/migrations/20220922143143_schedule_reset_duplicate_ci_runners_token_values_spec.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'spec_helper' +require_migration! + +RSpec.describe ScheduleResetDuplicateCiRunnersTokenValues, migration: :gitlab_ci do + let(:migration) { described_class::MIGRATION } + + describe '#up' do + it 'schedules background jobs for each batch of runners' do + migrate! + + expect(migration).to( + have_scheduled_batched_migration( + gitlab_schema: :gitlab_ci, + table_name: :ci_runners, + column_name: :id, + interval: described_class::DELAY_INTERVAL, + batch_size: described_class::BATCH_SIZE, + max_batch_size: described_class::MAX_BATCH_SIZE, + sub_batch_size: described_class::SUB_BATCH_SIZE + ) + ) + end + end + + describe '#down' do + it 'deletes all batched migration records' do + migrate! + schema_migrate_down! + + expect(migration).not_to have_scheduled_batched_migration + end + end +end diff --git a/spec/migrations/20220922143634_schedule_reset_duplicate_ci_runners_token_encrypted_values_spec.rb b/spec/migrations/20220922143634_schedule_reset_duplicate_ci_runners_token_encrypted_values_spec.rb new file mode 100644 index 00000000000..4f3103927d5 --- /dev/null +++ b/spec/migrations/20220922143634_schedule_reset_duplicate_ci_runners_token_encrypted_values_spec.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'spec_helper' +require_migration! + +RSpec.describe ScheduleResetDuplicateCiRunnersTokenEncryptedValues, migration: :gitlab_ci do + let(:migration) { described_class::MIGRATION } + + describe '#up' do + it 'schedules background jobs for each batch of runners' do + migrate! + + expect(migration).to( + have_scheduled_batched_migration( + gitlab_schema: :gitlab_ci, + table_name: :ci_runners, + column_name: :id, + interval: described_class::DELAY_INTERVAL, + batch_size: described_class::BATCH_SIZE, + max_batch_size: described_class::MAX_BATCH_SIZE, + sub_batch_size: described_class::SUB_BATCH_SIZE + ) + ) + end + end + + describe '#down' do + it 'deletes all batched migration records' do + migrate! + schema_migrate_down! + + expect(migration).not_to have_scheduled_batched_migration + end + end +end diff --git a/spec/migrations/20220928225711_schedule_update_ci_pipeline_artifacts_locked_status_spec.rb b/spec/migrations/20220928225711_schedule_update_ci_pipeline_artifacts_locked_status_spec.rb new file mode 100644 index 00000000000..7e3f8caa966 --- /dev/null +++ b/spec/migrations/20220928225711_schedule_update_ci_pipeline_artifacts_locked_status_spec.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require 'spec_helper' +require_migration! + +RSpec.describe ScheduleUpdateCiPipelineArtifactsLockedStatus, migration: :gitlab_ci do + let_it_be(:migration) { described_class::MIGRATION } + + describe '#up' do + it 'schedules background jobs for each batch of ci_pipeline_artifacts' do + migrate! + + expect(migration).to have_scheduled_batched_migration( + gitlab_schema: :gitlab_ci, + table_name: :ci_pipeline_artifacts, + column_name: :id, + batch_size: described_class::BATCH_SIZE, + sub_batch_size: described_class::SUB_BATCH_SIZE + ) + end + end + + describe '#down' do + it 'deletes all batched migration records' do + migrate! + schema_migrate_down! + + expect(migration).not_to have_scheduled_batched_migration + end + end +end diff --git a/spec/migrations/20220929213730_schedule_delete_orphaned_operational_vulnerabilities_spec.rb b/spec/migrations/20220929213730_schedule_delete_orphaned_operational_vulnerabilities_spec.rb new file mode 100644 index 00000000000..9220b5e8a95 --- /dev/null +++ b/spec/migrations/20220929213730_schedule_delete_orphaned_operational_vulnerabilities_spec.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +require 'spec_helper' +require_migration! + +RSpec.describe ScheduleDeleteOrphanedOperationalVulnerabilities do + let_it_be(:migration) { described_class.new } + let_it_be(:post_migration) { described_class::MIGRATION } + + describe '#up' do + it 'schedules background jobs for each batch of vulnerabilities' do + migration.up + + expect(post_migration).to( + have_scheduled_batched_migration( + table_name: :vulnerabilities, + column_name: :id, + interval: described_class::INTERVAL, + batch_size: described_class::BATCH_SIZE + ) + ) + end + end + + describe '#down' do + it 'deletes all batched migration records' do + migration.down + + expect(post_migration).not_to have_scheduled_batched_migration + end + end +end diff --git a/spec/migrations/20220809002011_schedule_destroy_invalid_group_members_spec.rb b/spec/migrations/20221004094814_schedule_destroy_invalid_members_spec.rb index 31dd4344d9f..73fdfa78eb4 100644 --- a/spec/migrations/20220809002011_schedule_destroy_invalid_group_members_spec.rb +++ b/spec/migrations/20221004094814_schedule_destroy_invalid_members_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require_migration! -RSpec.describe ScheduleDestroyInvalidGroupMembers, :migration do +RSpec.describe ScheduleDestroyInvalidMembers, :migration do let_it_be(:migration) { described_class::MIGRATION } describe '#up' do diff --git a/spec/migrations/20221008032350_add_password_expiration_migration_spec.rb b/spec/migrations/20221008032350_add_password_expiration_migration_spec.rb new file mode 100644 index 00000000000..05e557f1f52 --- /dev/null +++ b/spec/migrations/20221008032350_add_password_expiration_migration_spec.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +require 'spec_helper' + +require_migration! + +RSpec.describe AddPasswordExpirationMigration do + let(:application_setting) { table(:application_settings).create! } + + describe "#up" do + it 'allows to read password expiration fields' do + migrate! + + expect(application_setting.password_expiration_enabled).to eq false + expect(application_setting.password_expires_in_days).to eq 90 + expect(application_setting.password_expires_notice_before_days).to eq 7 + end + end +end diff --git a/spec/migrations/20221012033107_add_password_last_changed_at_to_user_details_spec.rb b/spec/migrations/20221012033107_add_password_last_changed_at_to_user_details_spec.rb new file mode 100644 index 00000000000..46a7b097d02 --- /dev/null +++ b/spec/migrations/20221012033107_add_password_last_changed_at_to_user_details_spec.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +require 'spec_helper' + +require_migration! + +RSpec.describe AddPasswordLastChangedAtToUserDetails do + let_it_be(:namespace) { table(:namespaces).create!(name: 'user', path: 'user') } + let_it_be(:users) { table(:users) } + let_it_be(:user) { create_user! } + let(:user_detail) { table(:user_details).create!(user_id: user.id, provisioned_by_group_id: namespace.id) } + + describe "#up" do + it 'allows to read password_last_changed_at' do + migrate! + + expect(user_detail.password_last_changed_at).to eq nil + end + end + + private + + def create_user!(name: "Example User", email: "user@example.com", user_type: nil) + users.create!( + name: name, + email: email, + username: name, + projects_limit: 0, + user_type: user_type, + confirmed_at: Time.current + ) + end +end diff --git a/spec/migrations/20221013154159_update_invalid_dormant_user_setting_spec.rb b/spec/migrations/20221013154159_update_invalid_dormant_user_setting_spec.rb new file mode 100644 index 00000000000..eac71e428be --- /dev/null +++ b/spec/migrations/20221013154159_update_invalid_dormant_user_setting_spec.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +require 'spec_helper' +require_migration! + +RSpec.describe UpdateInvalidDormantUserSetting, :migration do + let(:settings) { table(:application_settings) } + + context 'with no rows in the application_settings table' do + it 'does not insert a row' do + expect { migrate! }.to not_change { settings.count } + end + end + + context 'with a row in the application_settings table' do + before do + settings.create!(deactivate_dormant_users_period: days) + end + + context 'with deactivate_dormant_users_period set to a value greater than or equal to 90' do + let(:days) { 90 } + + it 'does not update the row' do + expect { migrate! } + .to not_change { settings.count } + .and not_change { settings.first.deactivate_dormant_users_period } + end + end + + context 'with deactivate_dormant_users_period set to a value less than or equal to 90' do + let(:days) { 1 } + + it 'updates the existing row' do + expect { migrate! } + .to not_change { settings.count } + .and change { settings.first.deactivate_dormant_users_period } + end + end + end +end diff --git a/spec/migrations/add_premium_and_ultimate_plan_limits_spec.rb b/spec/migrations/add_premium_and_ultimate_plan_limits_spec.rb index fb62fc3ca02..0ae4559ca9f 100644 --- a/spec/migrations/add_premium_and_ultimate_plan_limits_spec.rb +++ b/spec/migrations/add_premium_and_ultimate_plan_limits_spec.rb @@ -72,12 +72,14 @@ RSpec.describe AddPremiumAndUltimatePlanLimits, :migration do it 'creates plan limits from the source plan' do migrate! - expect(AddPremiumAndUltimatePlanLimits::PlanLimits.pluck(:plan_id, :storage_size_limit)).to match_array([ - [silver.id, silver_limits.storage_size_limit], - [gold.id, gold_limits.storage_size_limit], - [premium.id, silver_limits.storage_size_limit], - [ultimate.id, gold_limits.storage_size_limit] - ]) + expect(AddPremiumAndUltimatePlanLimits::PlanLimits.pluck(:plan_id, :storage_size_limit)) + .to match_array( + [ + [silver.id, silver_limits.storage_size_limit], + [gold.id, gold_limits.storage_size_limit], + [premium.id, silver_limits.storage_size_limit], + [ultimate.id, gold_limits.storage_size_limit] + ]) end end end diff --git a/spec/migrations/adjust_task_note_rename_background_migration_values_spec.rb b/spec/migrations/adjust_task_note_rename_background_migration_values_spec.rb new file mode 100644 index 00000000000..422d0655e36 --- /dev/null +++ b/spec/migrations/adjust_task_note_rename_background_migration_values_spec.rb @@ -0,0 +1,143 @@ +# frozen_string_literal: true + +require 'spec_helper' +require_migration! + +RSpec.describe AdjustTaskNoteRenameBackgroundMigrationValues, :migration do + let(:finished_status) { 3 } + let(:failed_status) { described_class::MIGRATION_FAILED_STATUS } + let(:active_status) { described_class::MIGRATION_ACTIVE_STATUS } + + shared_examples 'task note migration with failing batches' do + it 'updates batch sizes and resets failed batches' do + migration = create_background_migration(status: initial_status) + batches = [] + + batches << create_failed_batched_job(migration) + batches << create_failed_batched_job(migration) + + migrate! + + expect(described_class::JOB_CLASS_NAME).to have_scheduled_batched_migration( + table_name: :system_note_metadata, + column_name: :id, + interval: 2.minutes, + batch_size: described_class::NEW_BATCH_SIZE, + max_batch_size: 20_000, + sub_batch_size: described_class::NEW_SUB_BATCH_SIZE + ) + expect(migration.reload.status).to eq(active_status) + + updated_batches = batches.map { |b| b.reload.attributes.slice('attempts', 'sub_batch_size') } + expect(updated_batches).to all(eq("attempts" => 0, "sub_batch_size" => 10)) + end + end + + describe '#up' do + context 'when migration was already finished' do + it 'does not update batch sizes' do + create_background_migration(status: finished_status) + + migrate! + + expect(described_class::JOB_CLASS_NAME).to have_scheduled_batched_migration( + table_name: :system_note_metadata, + column_name: :id, + interval: 2.minutes, + batch_size: described_class::OLD_BATCH_SIZE, + max_batch_size: 20_000, + sub_batch_size: described_class::OLD_SUB_BATCH_SIZE + ) + end + end + + context 'when the migration had failing batches' do + context 'when migration had a failed status' do + it_behaves_like 'task note migration with failing batches' do + let(:initial_status) { failed_status } + end + + it 'updates started_at timestamp' do + migration = create_background_migration(status: failed_status) + now = Time.zone.now + + travel_to now do + migrate! + migration.reload + end + + expect(migration.started_at).to be_like_time(now) + end + end + + context 'when migration had an active status' do + it_behaves_like 'task note migration with failing batches' do + let(:initial_status) { active_status } + end + + it 'does not update started_at timestamp' do + migration = create_background_migration(status: active_status) + original_time = migration.started_at + + migrate! + migration.reload + + expect(migration.started_at).to be_like_time(original_time) + end + end + end + end + + describe '#down' do + it 'reverts to old batch sizes' do + create_background_migration(status: finished_status) + + migrate! + schema_migrate_down! + + expect(described_class::JOB_CLASS_NAME).to have_scheduled_batched_migration( + table_name: :system_note_metadata, + column_name: :id, + interval: 2.minutes, + batch_size: described_class::OLD_BATCH_SIZE, + max_batch_size: 20_000, + sub_batch_size: described_class::OLD_SUB_BATCH_SIZE + ) + end + end + + def create_failed_batched_job(migration) + table(:batched_background_migration_jobs).create!( + batched_background_migration_id: migration.id, + status: described_class::JOB_FAILED_STATUS, + min_value: 1, + max_value: 10, + attempts: 3, + batch_size: described_class::OLD_BATCH_SIZE, + sub_batch_size: described_class::OLD_SUB_BATCH_SIZE + ) + end + + def create_background_migration(status:) + migrations_table = table(:batched_background_migrations) + # make sure we only have on migration with that job class name in the specs + migrations_table.where(job_class_name: described_class::JOB_CLASS_NAME).delete_all + + migrations_table.create!( + job_class_name: described_class::JOB_CLASS_NAME, + status: status, + max_value: 10, + max_batch_size: 20_000, + batch_size: described_class::OLD_BATCH_SIZE, + sub_batch_size: described_class::OLD_SUB_BATCH_SIZE, + interval: 2.minutes, + table_name: :system_note_metadata, + column_name: :id, + total_tuple_count: 100_000, + pause_ms: 100, + gitlab_schema: :gitlab_main, + job_arguments: [], + started_at: 2.days.ago + ) + end +end diff --git a/spec/migrations/backfill_epic_cache_counts_spec.rb b/spec/migrations/backfill_epic_cache_counts_spec.rb new file mode 100644 index 00000000000..6084fdad0a6 --- /dev/null +++ b/spec/migrations/backfill_epic_cache_counts_spec.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +require 'spec_helper' +require_migration! + +RSpec.describe BackfillEpicCacheCounts, :migration do + let(:migration) { described_class::MIGRATION } + + describe '#up' do + it 'schedules a batched background migration' do + migrate! + + expect(migration).to have_scheduled_batched_migration( + table_name: :epics, + column_name: :id, + interval: described_class::DELAY_INTERVAL, + batch_size: described_class::BATCH_SIZE, + max_batch_size: described_class::MAX_BATCH_SIZE, + sub_batch_size: described_class::SUB_BATCH_SIZE + ) + end + end + + describe '#down' do + it 'deletes all batched migration records' do + migrate! + schema_migrate_down! + + expect(migration).not_to have_scheduled_batched_migration + end + end +end diff --git a/spec/migrations/backfill_escalation_policies_for_oncall_schedules_spec.rb b/spec/migrations/backfill_escalation_policies_for_oncall_schedules_spec.rb index da32e92ebb0..87855285203 100644 --- a/spec/migrations/backfill_escalation_policies_for_oncall_schedules_spec.rb +++ b/spec/migrations/backfill_escalation_policies_for_oncall_schedules_spec.rb @@ -57,36 +57,39 @@ RSpec.describe BackfillEscalationPoliciesForOncallSchedules do expect(new_polices).to all have_attributes(name: 'On-call Escalation Policy') expect(new_policy_b1.description).to eq('Immediately notify Schedule B1') expect(new_policy_c1.description).to eq('Immediately notify Schedule C1') - expect(policies.pluck(:project_id)).to eq([ - project_d.id, - project_e.id, - project_f.id, - project_f.id, - project_b.id, - project_c.id - ]) + expect(policies.pluck(:project_id)).to eq( + [ + project_d.id, + project_e.id, + project_f.id, + project_f.id, + project_b.id, + project_c.id + ]) expect(new_rules).to all have_attributes(status: 1, elapsed_time_seconds: 0) - expect(rules.pluck(:policy_id)).to eq([ - rule_d1.policy_id, - rule_e1.policy_id, - rule_f1.policy_id, - rule_f2.policy_id, - rule_f3.policy_id, - new_policy_b1.id, - new_policy_c1.id, - new_policy_c1.id - ]) - expect(rules.pluck(:oncall_schedule_id)).to eq([ - rule_d1.oncall_schedule_id, - rule_e1.oncall_schedule_id, - rule_f1.oncall_schedule_id, - rule_f2.oncall_schedule_id, - rule_f3.oncall_schedule_id, - schedule_b1.id, - schedule_c1.id, - schedule_c2.id - ]) + expect(rules.pluck(:policy_id)).to eq( + [ + rule_d1.policy_id, + rule_e1.policy_id, + rule_f1.policy_id, + rule_f2.policy_id, + rule_f3.policy_id, + new_policy_b1.id, + new_policy_c1.id, + new_policy_c1.id + ]) + expect(rules.pluck(:oncall_schedule_id)).to eq( + [ + rule_d1.oncall_schedule_id, + rule_e1.oncall_schedule_id, + rule_f1.oncall_schedule_id, + rule_f2.oncall_schedule_id, + rule_f3.oncall_schedule_id, + schedule_b1.id, + schedule_c1.id, + schedule_c2.id + ]) end end diff --git a/spec/migrations/populate_releases_access_level_from_repository_spec.rb b/spec/migrations/populate_releases_access_level_from_repository_spec.rb new file mode 100644 index 00000000000..2bb97662923 --- /dev/null +++ b/spec/migrations/populate_releases_access_level_from_repository_spec.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +require 'spec_helper' + +require_migration! + +RSpec.describe PopulateReleasesAccessLevelFromRepository, :migration do + let(:projects) { table(:projects) } + let(:groups) { table(:namespaces) } + let(:project_features) { table(:project_features) } + + let(:group) { groups.create!(name: 'test-group', path: 'test-group') } + let(:project) { projects.create!(namespace_id: group.id, project_namespace_id: group.id) } + let(:project_feature) do + project_features.create!(project_id: project.id, pages_access_level: 20, **project_feature_attributes) + end + + # repository_access_level and releases_access_level default to ENABLED + describe '#up' do + context 'when releases_access_level is greater than repository_access_level' do + let(:project_feature_attributes) { { repository_access_level: ProjectFeature::PRIVATE } } + + it 'reduces releases_access_level to match repository_access_level' do + expect { migrate! }.to change { project_feature.reload.releases_access_level } + .from(ProjectFeature::ENABLED) + .to(ProjectFeature::PRIVATE) + end + end + + context 'when releases_access_level is less than repository_access_level' do + let(:project_feature_attributes) { { releases_access_level: ProjectFeature::DISABLED } } + + it 'does not change releases_access_level' do + expect { migrate! }.not_to change { project_feature.reload.releases_access_level } + .from(ProjectFeature::DISABLED) + end + end + end +end diff --git a/spec/migrations/slice_merge_request_diff_commit_migrations_spec.rb b/spec/migrations/slice_merge_request_diff_commit_migrations_spec.rb index e03dd73ec8b..b03a5c41a11 100644 --- a/spec/migrations/slice_merge_request_diff_commit_migrations_spec.rb +++ b/spec/migrations/slice_merge_request_diff_commit_migrations_spec.rb @@ -49,12 +49,13 @@ RSpec.describe SliceMergeRequestDiffCommitMigrations, :migration do .pending .to_a - expect(new_jobs.map(&:arguments)).to eq([ - [1, 5_001], - [5_001, 10_001], - [10_001, 15_001], - [15_001, 20_001] - ]) + expect(new_jobs.map(&:arguments)).to eq( + [ + [1, 5_001], + [5_001, 10_001], + [10_001, 15_001], + [15_001, 20_001] + ]) end it 'schedules a background migration for the first job' do |