diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 07:08:36 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 07:08:36 +0000 |
commit | 48aff82709769b098321c738f3444b9bdaa694c6 (patch) | |
tree | e00c7c43e2d9b603a5a6af576b1685e400410dee /spec/rubocop/cop/migration | |
parent | 879f5329ee916a948223f8f43d77fba4da6cd028 (diff) | |
download | gitlab-ce-48aff82709769b098321c738f3444b9bdaa694c6.tar.gz |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc42
Diffstat (limited to 'spec/rubocop/cop/migration')
4 files changed, 49 insertions, 1 deletions
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 |