2019-11-20 16:06:38 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-06-22 17:08:42 -04:00
|
|
|
require 'fast_spec_helper'
|
2019-11-20 16:06:38 -05:00
|
|
|
require_relative '../../../../rubocop/cop/migration/add_index'
|
|
|
|
|
2021-01-07 13:10:38 -05:00
|
|
|
RSpec.describe RuboCop::Cop::Migration::AddIndex do
|
2019-11-20 16:06:38 -05:00
|
|
|
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
|
2020-05-28 17:08:22 -04:00
|
|
|
expect_offense(<<~PATTERN)
|
2019-11-20 16:06:38 -05:00
|
|
|
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
|
2020-05-28 17:08:22 -04:00
|
|
|
expect_no_offenses(<<~PATTERN)
|
2019-11-20 16:06:38 -05:00
|
|
|
def change
|
|
|
|
add_index :table, :column
|
|
|
|
end
|
|
|
|
PATTERN
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|