From 48aff82709769b098321c738f3444b9bdaa694c6 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Wed, 21 Oct 2020 07:08:36 +0000 Subject: Add latest changes from gitlab-org/gitlab@13-5-stable-ee --- .../migration/add_concurrent_foreign_key_spec.rb | 10 ++++++++++ .../migration/add_limit_to_text_columns_spec.rb | 22 ++++++++++++++++++++++ .../create_table_with_foreign_keys_spec.rb | 2 +- .../with_lock_retries_disallowed_method_spec.rb | 16 ++++++++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) (limited to 'spec/rubocop/cop/migration') diff --git a/spec/rubocop/cop/migration/add_concurrent_foreign_key_spec.rb b/spec/rubocop/cop/migration/add_concurrent_foreign_key_spec.rb index b43d44dba65..aaf191a1b6b 100644 --- a/spec/rubocop/cop/migration/add_concurrent_foreign_key_spec.rb +++ b/spec/rubocop/cop/migration/add_concurrent_foreign_key_spec.rb @@ -36,5 +36,15 @@ RSpec.describe RuboCop::Cop::Migration::AddConcurrentForeignKey, type: :rubocop expect(cop.offenses).to be_empty end + + it 'does not register an offense when `add_foreign_key` is within `with_lock_retries`' do + inspect_source <<~RUBY + with_lock_retries do + add_foreign_key :key, :projects, column: :project_id, on_delete: :cascade + end + RUBY + + expect(cop.offenses).to be_empty + end end end diff --git a/spec/rubocop/cop/migration/add_limit_to_text_columns_spec.rb b/spec/rubocop/cop/migration/add_limit_to_text_columns_spec.rb index 5f0ca419548..0bea7bd7a0c 100644 --- a/spec/rubocop/cop/migration/add_limit_to_text_columns_spec.rb +++ b/spec/rubocop/cop/migration/add_limit_to_text_columns_spec.rb @@ -129,6 +129,28 @@ RSpec.describe RuboCop::Cop::Migration::AddLimitToTextColumns, type: :rubocop do end end + context 'when text columns are used for encryption' do + it 'registers no offenses' do + expect_no_offenses(<<~RUBY) + class TestTextLimits < ActiveRecord::Migration[6.0] + DOWNTIME = false + disable_ddl_transaction! + + def up + create_table :test_text_limits, id: false do |t| + t.integer :test_id, null: false + t.text :encrypted_name + end + + add_column :encrypted_test_text_limits, :encrypted_email, :text + add_column_with_default :encrypted_test_text_limits, :encrypted_role, :text, default: 'default' + change_column_type_concurrently :encrypted_test_text_limits, :encrypted_test_id, :text + end + end + RUBY + end + end + context 'on down' do it 'registers no offense' do expect_no_offenses(<<~RUBY) diff --git a/spec/rubocop/cop/migration/create_table_with_foreign_keys_spec.rb b/spec/rubocop/cop/migration/create_table_with_foreign_keys_spec.rb index fa4acc62226..93f43b0feb0 100644 --- a/spec/rubocop/cop/migration/create_table_with_foreign_keys_spec.rb +++ b/spec/rubocop/cop/migration/create_table_with_foreign_keys_spec.rb @@ -83,7 +83,7 @@ RSpec.describe RuboCop::Cop::Migration::CreateTableWithForeignKeys, type: :ruboc context 'with more than one foreign keys' do let(:offense) do 'Creating a table with more than one foreign key at once violates our migration style guide. ' \ - 'For more details check the https://docs.gitlab.com/ce/development/migration_style_guide.html#examples' + 'For more details check the https://docs.gitlab.com/ee/development/migration_style_guide.html#examples' end shared_examples 'target to high traffic table' do |dsl_method, table_name| diff --git a/spec/rubocop/cop/migration/with_lock_retries_disallowed_method_spec.rb b/spec/rubocop/cop/migration/with_lock_retries_disallowed_method_spec.rb index 11e4d784617..607daf0c9f0 100644 --- a/spec/rubocop/cop/migration/with_lock_retries_disallowed_method_spec.rb +++ b/spec/rubocop/cop/migration/with_lock_retries_disallowed_method_spec.rb @@ -53,6 +53,22 @@ RSpec.describe RuboCop::Cop::Migration::WithLockRetriesDisallowedMethod, type: : expect(cop.offenses.size).to eq(0) end + + describe 'for `add_foreign_key`' do + it 'registers an offense when more than two FKs are added' do + message = described_class::MSG_ONLY_ONE_FK_ALLOWED + + expect_offense <<~RUBY + with_lock_retries do + add_foreign_key :imports, :projects, column: :project_id, on_delete: :cascade + ^^^^^^^^^^^^^^^ #{message} + add_column :projects, :name, :text + add_foreign_key :imports, :users, column: :user_id, on_delete: :cascade + ^^^^^^^^^^^^^^^ #{message} + end + RUBY + end + end end context 'outside of migration' do -- cgit v1.2.1