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:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-09-13 21:06:03 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-09-13 21:06:03 +0300
commit40d3d574132d2849646c20eb9d8742b159d9bfc8 (patch)
tree431dee6675639da4421dbb1d6f50b7734a3190c3 /spec/rubocop/cop/migration
parent5939b09fd3db37ec98dfce0345162617d9d1d313 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/rubocop/cop/migration')
-rw-r--r--spec/rubocop/cop/migration/add_reference_spec.rb84
1 files changed, 66 insertions, 18 deletions
diff --git a/spec/rubocop/cop/migration/add_reference_spec.rb b/spec/rubocop/cop/migration/add_reference_spec.rb
index c348fc0efac..0b56fe8ed83 100644
--- a/spec/rubocop/cop/migration/add_reference_spec.rb
+++ b/spec/rubocop/cop/migration/add_reference_spec.rb
@@ -25,38 +25,86 @@ describe RuboCop::Cop::Migration::AddReference do
allow(cop).to receive(:in_migration?).and_return(true)
end
- it 'registers an offense when using add_reference without index' do
- expect_offense(<<~RUBY)
- call do
- add_reference(:projects, :users)
- ^^^^^^^^^^^^^ `add_reference` requires `index: true` or `index: { options... }`
+ let(:offense) { '`add_reference` requires downtime for existing tables, use `add_concurrent_foreign_key` instead. When used for new tables, `index: true` or `index: { options... } is required.`' }
+
+ context 'when the table existed before' do
+ it 'registers an offense when using add_reference' do
+ expect_offense(<<~RUBY)
+ def up
+ add_reference(:projects, :users)
+ ^^^^^^^^^^^^^ #{offense}
+ end
+ RUBY
+ end
+
+ it 'registers an offense when using add_reference with index enabled' do
+ expect_offense(<<~RUBY)
+ def up
+ add_reference(:projects, :users, index: true)
+ ^^^^^^^^^^^^^ #{offense}
end
- RUBY
+ RUBY
+ end
+
+ it 'registers an offense if only a different table was created' do
+ expect_offense(<<~RUBY)
+ def up
+ create_table(:foo) do |t|
+ t.string :name
+ end
+ add_reference(:projects, :users, index: true)
+ ^^^^^^^^^^^^^ #{offense}
+ end
+ RUBY
+ end
end
- it 'registers an offense when using add_reference index disabled' do
- expect_offense(<<~RUBY)
+ context 'when creating the table at the same time' do
+ let(:create_table_statement) do
+ <<~RUBY
+ create_table(:projects) do |t|
+ t.string :name
+ end
+ RUBY
+ end
+
+ it 'registers an offense when using add_reference without index' do
+ expect_offense(<<~RUBY)
def up
+ #{create_table_statement}
+ add_reference(:projects, :users)
+ ^^^^^^^^^^^^^ #{offense}
+ end
+ RUBY
+ end
+
+ it 'registers an offense when using add_reference index disabled' do
+ expect_offense(<<~RUBY)
+ def up
+ #{create_table_statement}
add_reference(:projects, :users, index: false)
- ^^^^^^^^^^^^^ `add_reference` requires `index: true` or `index: { options... }`
+ ^^^^^^^^^^^^^ #{offense}
end
- RUBY
- end
+ RUBY
+ end
- it 'does not register an offense when using add_reference with index enabled' do
- expect_no_offenses(<<~RUBY)
+ it 'does not register an offense when using add_reference with index enabled' do
+ expect_no_offenses(<<~RUBY)
def up
+ #{create_table_statement}
add_reference(:projects, :users, index: true)
end
- RUBY
- end
+ RUBY
+ end
- it 'does not register an offense when the index is unique' do
- expect_no_offenses(<<~RUBY)
+ it 'does not register an offense when the index is unique' do
+ expect_no_offenses(<<~RUBY)
def up
+ #{create_table_statement}
add_reference(:projects, :users, index: { unique: true } )
end
- RUBY
+ RUBY
+ end
end
end
end