Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/rubocop/cop/migration/prevent_index_creation_spec.rb')
-rw-r--r--spec/rubocop/cop/migration/prevent_index_creation_spec.rb50
1 files changed, 50 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