diff options
author | Douwe Maan <douwe@selenight.nl> | 2017-03-07 10:08:53 -0600 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2017-03-07 10:09:01 -0600 |
commit | 5d9762b3b5ace3da397b83f501d103a5152f0dd3 (patch) | |
tree | bed282cc9a07e165842c6b28e18746c8558c0c21 /spec | |
parent | 6a52cda31da4becc3e342530a2bdf0868d8921cc (diff) | |
download | gitlab-ce-5d9762b3b5ace3da397b83f501d103a5152f0dd3.tar.gz |
Add cop to ensure reversibility of add_concurrent_index
Diffstat (limited to 'spec')
-rw-r--r-- | spec/rubocop/cop/migration/add_concurrent_index_spec.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/spec/rubocop/cop/migration/add_concurrent_index_spec.rb b/spec/rubocop/cop/migration/add_concurrent_index_spec.rb new file mode 100644 index 00000000000..19a5718b0b1 --- /dev/null +++ b/spec/rubocop/cop/migration/add_concurrent_index_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper' + +require 'rubocop' +require 'rubocop/rspec/support' + +require_relative '../../../../rubocop/cop/migration/add_concurrent_index' + +describe RuboCop::Cop::Migration::AddConcurrentIndex 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_concurrent_index is used inside a change method' do + inspect_source(cop, 'def change; add_concurrent_index :table, :column; end') + + aggregate_failures do + expect(cop.offenses.size).to eq(1) + expect(cop.offenses.map(&:line)).to eq([1]) + end + end + + it 'registers no offense when add_concurrent_index is used inside an up method' do + inspect_source(cop, 'def up; add_concurrent_index :table, :column; end') + + expect(cop.offenses.size).to eq(0) + end + end + + context 'outside of migration' do + it 'registers no offense' do + inspect_source(cop, 'def change; add_concurrent_index :table, :column; end') + + expect(cop.offenses.size).to eq(0) + end + end +end |