diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-24 06:07:44 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-24 06:07:44 +0300 |
commit | f41ba400eb6320979eccaec747bc1a80c14fbe15 (patch) | |
tree | 590b37197246762cececd1ad4e0107f88507fe0f /spec | |
parent | 1dd92924325105bb04d8900ac2577e59eb39f603 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
7 files changed, 110 insertions, 30 deletions
diff --git a/spec/db/migration_spec.rb b/spec/db/migration_spec.rb index b7a4a302290..784f8753893 100644 --- a/spec/db/migration_spec.rb +++ b/spec/db/migration_spec.rb @@ -8,7 +8,8 @@ RSpec.describe 'Migrations Validation', feature_category: :database do # The range describes the timestamps that given migration helper can be used let(:all_migration_classes) do { - 2022_12_01_02_15_00.. => Gitlab::Database::Migration[2.1], + 2023_10_10_02_15_00.. => Gitlab::Database::Migration[2.2], + 2022_12_01_02_15_00..2023_11_01_02_15_00 => Gitlab::Database::Migration[2.1], 2022_01_26_21_06_58..2023_01_11_12_45_12 => Gitlab::Database::Migration[2.0], 2021_09_01_15_33_24..2022_04_25_12_06_03 => Gitlab::Database::Migration[1.0], 2021_05_31_05_39_16..2021_09_01_15_33_24 => ActiveRecord::Migration[6.1], diff --git a/spec/lib/generators/batched_background_migration/expected_files/queue_my_batched_migration.txt b/spec/lib/generators/batched_background_migration/expected_files/queue_my_batched_migration.txt index aa79062422b..84a3593b4e3 100644 --- a/spec/lib/generators/batched_background_migration/expected_files/queue_my_batched_migration.txt +++ b/spec/lib/generators/batched_background_migration/expected_files/queue_my_batched_migration.txt @@ -5,7 +5,7 @@ # Update below commented lines with appropriate values. -class QueueMyBatchedMigration < Gitlab::Database::Migration[2.1] +class QueueMyBatchedMigration < Gitlab::Database::Migration[2.2] MIGRATION = "MyBatchedMigration" # DELAY_INTERVAL = 2.minutes # BATCH_SIZE = 1000 diff --git a/spec/lib/generators/model/mocks/migration_file.txt b/spec/lib/generators/model/mocks/migration_file.txt index c9e51e51863..d0a5c71ffc3 100644 --- a/spec/lib/generators/model/mocks/migration_file.txt +++ b/spec/lib/generators/model/mocks/migration_file.txt @@ -3,7 +3,7 @@ # See https://docs.gitlab.com/ee/development/migration_style_guide.html # for more information on how to write migrations for GitLab. -class CreateModelGeneratorTestFoos < Gitlab::Database::Migration[2.1] +class CreateModelGeneratorTestFoos < Gitlab::Database::Migration[2.2] # When using the methods "add_concurrent_index" or "remove_concurrent_index" # you must disable the use of transactions # as these methods can not run in an existing transaction. @@ -16,6 +16,7 @@ class CreateModelGeneratorTestFoos < Gitlab::Database::Migration[2.1] # To disable transactions uncomment the following line and remove these # comments: # disable_ddl_transaction! + milestone '16.5' # Add dependent 'batched_background_migrations.queued_migration_version' values. # DEPENDENT_BATCHED_BACKGROUND_MIGRATIONS = [] diff --git a/spec/lib/generators/model/model_generator_spec.rb b/spec/lib/generators/model/model_generator_spec.rb index 0e770190d25..7284fc8b28a 100644 --- a/spec/lib/generators/model/model_generator_spec.rb +++ b/spec/lib/generators/model/model_generator_spec.rb @@ -17,6 +17,10 @@ RSpec.describe Model::ModelGenerator do FileUtils.rm_rf(temp_dir) end + before do + allow(Gitlab).to receive(:current_milestone).and_return('16.5') + end + it 'creates the model file with the right content' do subject.invoke_all diff --git a/spec/lib/gitlab/database/migrations/milestone_mixin_spec.rb b/spec/lib/gitlab/database/migrations/milestone_mixin_spec.rb index e375af494a2..87a04329f79 100644 --- a/spec/lib/gitlab/database/migrations/milestone_mixin_spec.rb +++ b/spec/lib/gitlab/database/migrations/milestone_mixin_spec.rb @@ -12,14 +12,11 @@ RSpec.describe Gitlab::Database::Migrations::MilestoneMixin, feature_category: : end let(:migration_mixin) do - Class.new(Gitlab::Database::Migration[2.1]) do - include Gitlab::Database::Migrations::MilestoneMixin - end + Class.new(Gitlab::Database::Migration[2.2]) end let(:migration_mixin_version) do - Class.new(Gitlab::Database::Migration[2.1]) do - include Gitlab::Database::Migrations::MilestoneMixin + Class.new(Gitlab::Database::Migration[2.2]) do milestone '16.4' end end diff --git a/spec/rubocop/cop/migration/migration_with_milestone_spec.rb b/spec/rubocop/cop/migration/migration_with_milestone_spec.rb new file mode 100644 index 00000000000..dd603cad2f8 --- /dev/null +++ b/spec/rubocop/cop/migration/migration_with_milestone_spec.rb @@ -0,0 +1,99 @@ +# frozen_string_literal: true + +require 'rubocop_spec_helper' +require_relative '../../../../rubocop/cop/migration/migration_with_milestone' + +RSpec.describe RuboCop::Cop::Migration::MigrationWithMilestone, feature_category: :database do + context 'when we\'re not a Gitlab migration' do + it 'does not register an offense at all' do + expect_no_offenses <<~CODE + class CreateProducts < ActiveRecord::Migration[7.0] + def change + add_column :users, :foo, :integer + end + end + CODE + end + end + + context 'when we\'re a Gitlab migration' do + it 'does not register an offense if we\'re a version before 2.2' do + expect_no_offenses <<~CODE + class TestFoo < Gitlab::Database::Migration[2.1] + def change + add_column :users, :foo, :integer + end + end + CODE + end + + context 'when we\'re version 2.2' do + it 'expects no offense if we call `milestone` with a string' do + expect_no_offenses <<~CODE + class TestFoo < Gitlab::Database::Migration[2.2] + milestone '16.7' + + def change + add_column :users, :foo, :integer + end + end + CODE + end + + it 'expects an offense if we don\'t call `milestone`' do + expect_offense <<~CODE + class TestFoo < Gitlab::Database::Migration[2.2] + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{described_class::MSG} + def change + add_column :users, :foo, :integer + end + end + CODE + end + + it 'does not matter if include a mixin' do + expect_no_offenses <<~CODE + class TestFoo < Gitlab::Database::Migration[2.2] + include Gitlab::Test::Mixin + + milestone '16.7' + + def change + add_column :users, :foo, :integer + end + end + CODE + end + + it 'does not matter if we call a helper method' do + expect_no_offenses <<~CODE + class TestFoo < Gitlab::Database::Migration[2.2] + disable_ddl_transaction! + + milestone '16.7' + + def change + add_column :users, :foo, :integer + end + end + CODE + end + + it 'does not matter if we include a mixin and call a helper method' do + expect_no_offenses <<~CODE + class TestFoo < Gitlab::Database::Migration[2.2] + include Gitlab::Test::Mixin + + disable_ddl_transaction! + + milestone '16.7' + + def change + add_column :users, :foo, :integer + end + end + CODE + end + end + end +end diff --git a/spec/workers/tasks_to_be_done/create_worker_spec.rb b/spec/workers/tasks_to_be_done/create_worker_spec.rb deleted file mode 100644 index 3a4e10b6a6f..00000000000 --- a/spec/workers/tasks_to_be_done/create_worker_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe TasksToBeDone::CreateWorker, feature_category: :onboarding do - let_it_be(:current_user) { create(:user) } - - let(:assignee_ids) { [1, 2] } - let(:job_args) { [123, current_user.id, assignee_ids] } - - describe '.perform' do - it 'executes the task services for all tasks to be done', :aggregate_failures do - expect { described_class.new.perform(*job_args) }.not_to change { Issue.count } - end - end - - include_examples 'an idempotent worker' do - it 'creates 3 task issues' do - expect { subject }.not_to change { Issue.count } - end - end -end |