diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2017-03-07 20:06:13 +0000 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2017-03-07 20:06:13 +0000 |
commit | e714d569f388bea4636e8e454a28ded502f080d1 (patch) | |
tree | e55dd77491d825f170e23302f5b901bb6947ca33 /spec | |
parent | 51cddc9639a4eec4d6ac58753400353f44e9494d (diff) | |
parent | e3ddd871027e2e9f4ceef658a5ba646d5ade7045 (diff) | |
download | gitlab-ce-e714d569f388bea4636e8e454a28ded502f080d1.tar.gz |
Merge branch 'dm-add-concurrent-index-cop' into 'master'
Add cop to ensure reversibility of add_concurrent_index
See merge request !9771
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 |