diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
commit | e8d2c2579383897a1dd7f9debd359abe8ae8373d (patch) | |
tree | c42be41678c2586d49a75cabce89322082698334 /spec/rubocop/cop/migration | |
parent | fc845b37ec3a90aaa719975f607740c22ba6a113 (diff) |
Add latest changes from gitlab-org/gitlab@14-1-stable-eev14.1.0-rc42
Diffstat (limited to 'spec/rubocop/cop/migration')
-rw-r--r-- | spec/rubocop/cop/migration/prevent_index_creation_spec.rb | 50 | ||||
-rw-r--r-- | spec/rubocop/cop/migration/sidekiq_queue_migrate_spec.rb | 47 |
2 files changed, 97 insertions, 0 deletions
diff --git a/spec/rubocop/cop/migration/prevent_index_creation_spec.rb b/spec/rubocop/cop/migration/prevent_index_creation_spec.rb new file mode 100644 index 00000000000..a3965f54bbd --- /dev/null +++ b/spec/rubocop/cop/migration/prevent_index_creation_spec.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +require 'fast_spec_helper' +require_relative '../../../../rubocop/cop/migration/prevent_index_creation' + +RSpec.describe RuboCop::Cop::Migration::PreventIndexCreation do + subject(:cop) { described_class.new } + + context 'when in migration' do + before do + allow(cop).to receive(:in_migration?).and_return(true) + end + + context 'when adding an index to a forbidden table' do + it 'registers an offense when add_index is used' do + expect_offense(<<~RUBY) + def change + add_index :ci_builds, :protected + ^^^^^^^^^ Adding new index to ci_builds is forbidden, see https://gitlab.com/gitlab-org/gitlab/-/issues/332886 + end + RUBY + end + + it 'registers an offense when add_concurrent_index is used' do + expect_offense(<<~RUBY) + def change + add_concurrent_index :ci_builds, :protected + ^^^^^^^^^^^^^^^^^^^^ Adding new index to ci_builds is forbidden, see https://gitlab.com/gitlab-org/gitlab/-/issues/332886 + end + RUBY + end + end + + context 'when adding an index to a regular table' do + it 'does not register an offense' do + expect_no_offenses(<<~RUBY) + def change + add_index :ci_pipelines, :locked + end + RUBY + end + end + end + + context 'when outside of migration' do + it 'does not register an offense' do + expect_no_offenses('def change; add_index :table, :column; end') + end + end +end diff --git a/spec/rubocop/cop/migration/sidekiq_queue_migrate_spec.rb b/spec/rubocop/cop/migration/sidekiq_queue_migrate_spec.rb new file mode 100644 index 00000000000..499351b3585 --- /dev/null +++ b/spec/rubocop/cop/migration/sidekiq_queue_migrate_spec.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +require 'fast_spec_helper' +require_relative '../../../../rubocop/cop/migration/sidekiq_queue_migrate' + +RSpec.describe RuboCop::Cop::Migration::SidekiqQueueMigrate do + subject(:cop) { described_class.new } + + def source(meth = 'change') + "def #{meth}; sidekiq_queue_migrate 'queue', to: 'new_queue'; end" + end + + context 'when in a regular migration' do + before do + allow(cop).to receive(:in_migration?).and_return(true) + allow(cop).to receive(:in_post_deployment_migration?).and_return(false) + end + + %w(up down change any_other_method).each do |method_name| + it "registers an offense when sidekiq_queue_migrate is used in ##{method_name}" do + expect_offense(<<~RUBY) + def #{method_name} + sidekiq_queue_migrate 'queue', to: 'new_queue' + ^^^^^^^^^^^^^^^^^^^^^ `sidekiq_queue_migrate` must only be used in post-deployment migrations + end + RUBY + end + end + end + + context 'when in a post-deployment migration' do + before do + allow(cop).to receive(:in_migration?).and_return(true) + allow(cop).to receive(:in_post_deployment_migration?).and_return(true) + end + + it 'registers no offense' do + expect_no_offenses(source) + end + end + + context 'when outside of a migration' do + it 'registers no offense' do + expect_no_offenses(source) + end + end +end |