summaryrefslogtreecommitdiff
path: root/spec/rubocop/cop
diff options
context:
space:
mode:
authorAndreas Brandl <abrandl@gitlab.com>2018-08-01 17:52:54 +0200
committerAndreas Brandl <abrandl@gitlab.com>2018-08-08 23:30:48 +0200
commite3ff3909862d81036a64f3eab02d5e3e4802f5e6 (patch)
tree7a27eb67467652ebb2adf77fb2ef6cf57a8612ba /spec/rubocop/cop
parent3d2a3e5782aaff37c4b27dc9d3858031ab0c9059 (diff)
downloadgitlab-ce-e3ff3909862d81036a64f3eab02d5e3e4802f5e6.tar.gz
Add rubocop check for add_reference to require index.
Diffstat (limited to 'spec/rubocop/cop')
-rw-r--r--spec/rubocop/cop/migration/add_reference_spec.rb54
1 files changed, 54 insertions, 0 deletions
diff --git a/spec/rubocop/cop/migration/add_reference_spec.rb b/spec/rubocop/cop/migration/add_reference_spec.rb
new file mode 100644
index 00000000000..8f795bb561e
--- /dev/null
+++ b/spec/rubocop/cop/migration/add_reference_spec.rb
@@ -0,0 +1,54 @@
+require 'spec_helper'
+
+require 'rubocop'
+require 'rubocop/rspec/support'
+
+require_relative '../../../../rubocop/cop/migration/add_reference'
+
+describe RuboCop::Cop::Migration::AddReference do
+ include CopHelper
+
+ let(:cop) { described_class.new }
+
+ context 'outside of a migration' do
+ it 'does not register any offenses' do
+ expect_no_offenses(<<~RUBY)
+ def up
+ add_reference(:projects, :users)
+ end
+ RUBY
+ end
+ end
+
+ context 'in a migration' do
+ before 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`
+ end
+ RUBY
+ end
+
+ it 'registers an offense when using add_reference index disabled' do
+ expect_offense(<<~RUBY)
+ def up
+ add_reference(:projects, :users, index: false)
+ ^^^^^^^^^^^^^ `add_reference` requires `index: true`
+ end
+ RUBY
+ end
+
+ it 'does not register an offense when using add_reference with index enabled' do
+ expect_no_offenses(<<~RUBY)
+ def up
+ add_reference(:projects, :users, index: true)
+ end
+ RUBY
+ end
+ end
+end