From 588b7d39660011dd2a36b2d89d19ef739a6fe369 Mon Sep 17 00:00:00 2001 From: Eric Thomas Date: Tue, 19 Nov 2019 13:37:45 -0700 Subject: [PATCH 1/4] Add missing add_index rubocop spec --- spec/rubocop/cop/migration/add_index_spec.rb | 35 ++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 spec/rubocop/cop/migration/add_index_spec.rb diff --git a/spec/rubocop/cop/migration/add_index_spec.rb b/spec/rubocop/cop/migration/add_index_spec.rb new file mode 100644 index 00000000000000..40e04ca1b9e6c9 --- /dev/null +++ b/spec/rubocop/cop/migration/add_index_spec.rb @@ -0,0 +1,35 @@ +require 'spec_helper' + +require 'rubocop' +require 'rubocop/rspec/support' + +require_relative '../../../../rubocop/cop/migration/add_index' + +describe RuboCop::Cop::Migration::AddIndex do + include CopHelper + + subject(:cop) { described_class.new } + + context 'in migration' do + before do + allow(cop).to receive(:in_migration?).and_return(true) + end + + it 'registers an offense when add_index is used' do + inspect_source('def change; add_index :table, :column; end') + + aggregate_failures do + expect(cop.offenses.size).to eq(1) + expect(cop.offenses.map(&:line)).to eq([1]) + end + end + end + + context 'outside of migration' do + it 'registers no offense' do + inspect_source('def change; add_index :table, :column; end') + + expect(cop.offenses.size).to eq(0) + end + end +end -- GitLab From 4b8cf4b2e2de9e840cd8fb046a84abdf6b3aca37 Mon Sep 17 00:00:00 2001 From: Eric Thomas Date: Tue, 19 Nov 2019 13:49:08 -0700 Subject: [PATCH 2/4] add frozen_string_literal --- spec/rubocop/cop/migration/add_index_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/rubocop/cop/migration/add_index_spec.rb b/spec/rubocop/cop/migration/add_index_spec.rb index 40e04ca1b9e6c9..974162a4cf0bfd 100644 --- a/spec/rubocop/cop/migration/add_index_spec.rb +++ b/spec/rubocop/cop/migration/add_index_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'rubocop' -- GitLab From bc16912a2e787c89c83802d6c5e4ef3468519627 Mon Sep 17 00:00:00 2001 From: Eric Thomas Date: Wed, 20 Nov 2019 07:40:15 -0700 Subject: [PATCH 3/4] add changelog --- changelogs/unreleased/add_missing_add_index_rubocop_spec.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelogs/unreleased/add_missing_add_index_rubocop_spec.yml diff --git a/changelogs/unreleased/add_missing_add_index_rubocop_spec.yml b/changelogs/unreleased/add_missing_add_index_rubocop_spec.yml new file mode 100644 index 00000000000000..b1ae864ae358a9 --- /dev/null +++ b/changelogs/unreleased/add_missing_add_index_rubocop_spec.yml @@ -0,0 +1,5 @@ +--- +title: add missing test for add_index rubocop rule +merge_request: 20464 +author: Eric Thomas +type: other -- GitLab From 57a5c94949583c3b7c354cbc07dab6d28317a242 Mon Sep 17 00:00:00 2001 From: Eric Thomas Date: Wed, 20 Nov 2019 09:24:01 -0700 Subject: [PATCH 4/4] use rubocop helpers for rspec --- spec/rubocop/cop/migration/add_index_spec.rb | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/spec/rubocop/cop/migration/add_index_spec.rb b/spec/rubocop/cop/migration/add_index_spec.rb index 974162a4cf0bfd..0c3f87e5bf86c6 100644 --- a/spec/rubocop/cop/migration/add_index_spec.rb +++ b/spec/rubocop/cop/migration/add_index_spec.rb @@ -18,20 +18,22 @@ end it 'registers an offense when add_index is used' do - inspect_source('def change; add_index :table, :column; end') - - aggregate_failures do - expect(cop.offenses.size).to eq(1) - expect(cop.offenses.map(&:line)).to eq([1]) - end + expect_offense(<<~PATTERN.strip_indent) + def change + add_index :table, :column + ^^^^^^^^^ `add_index` requires downtime, use `add_concurrent_index` instead + end + PATTERN end end context 'outside of migration' do it 'registers no offense' do - inspect_source('def change; add_index :table, :column; end') - - expect(cop.offenses.size).to eq(0) + expect_no_offenses(<<~PATTERN.strip_indent) + def change + add_index :table, :column + end + PATTERN end end end -- GitLab