diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-06 15:11:09 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-06 15:11:09 +0300 |
commit | e9aabbc4b5c80a569ce7e5909bd9d8def11b7a1b (patch) | |
tree | 2bc9ed254deba51c4041c1ee2fb8dcc7bd3dfaad /spec/rubocop | |
parent | 08608c8e9e9821858dd2f452a3c9ebfb945ab69f (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/rubocop')
-rw-r--r-- | spec/rubocop/cop/background_migration/dictionary_file_spec.rb | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/spec/rubocop/cop/background_migration/dictionary_file_spec.rb b/spec/rubocop/cop/background_migration/dictionary_file_spec.rb index 4fa7dede093..9b4adc87f78 100644 --- a/spec/rubocop/cop/background_migration/dictionary_file_spec.rb +++ b/spec/rubocop/cop/background_migration/dictionary_file_spec.rb @@ -136,14 +136,18 @@ RSpec.describe RuboCop::Cop::BackgroundMigration::DictionaryFile, feature_catego context 'with dictionary file' do let(:introduced_by_url) { 'https://gitlab.com/gitlab-org/gitlab/-/merge_requests/132639' } let(:finalize_after) { '20230507160251' } + let(:milestone) { '16.1' } before do + allow(File).to receive(:exist?).and_call_original allow(File).to receive(:exist?).with(dictionary_file_path).and_return(true) - - allow_next_instance_of(RuboCop::BatchedBackgroundMigrationsDictionary) do |dictionary| - allow(dictionary).to receive(:finalize_after).and_return(finalize_after) - allow(dictionary).to receive(:introduced_by_url).and_return(introduced_by_url) - end + allow(::RuboCop::BatchedBackgroundMigrationsDictionary).to receive(:dictionary_data).and_return({ + '20231118100907' => { + finalize_after: finalize_after, + introduced_by_url: introduced_by_url, + milestone: milestone + } + }) end context 'without introduced_by_url' do @@ -177,6 +181,31 @@ RSpec.describe RuboCop::Cop::BackgroundMigration::DictionaryFile, feature_catego end end + context 'without milestone' do + it_behaves_like 'migration with missing dictionary keys offense', :milestone do + let(:milestone) { nil } + end + end + + context 'when milestone is a number' do + let(:milestone) { 16.1 } + + it 'throws offense on having an invalid milestone' do + expect_offense(<<~RUBY) + class QueueMyMigration < Gitlab::Database::Migration[2.1] + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{format('Invalid `milestone` for the dictionary. It must be a string. Please ensure it is quoted.')} + def up + queue_batched_background_migration( + 'MyMigration', + :users, + :id + ) + end + end + RUBY + end + end + context 'with required dictionary keys' do it 'does not throw offense with appropriate dictionary file' do expect_no_offenses(<<~RUBY) |