debian-mirror-gitlab/spec/rubocop/cop/migration/add_index_spec.rb

34 lines
803 B
Ruby
Raw Normal View History

2020-01-01 13:55:28 +05:30
# frozen_string_literal: true
2020-07-28 23:09:34 +05:30
require 'fast_spec_helper'
2020-01-01 13:55:28 +05:30
require_relative '../../../../rubocop/cop/migration/add_index'
2021-03-08 18:12:59 +05:30
RSpec.describe RuboCop::Cop::Migration::AddIndex do
2020-01-01 13:55:28 +05:30
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-06-23 00:09:42 +05:30
expect_offense(<<~PATTERN)
2020-01-01 13:55:28 +05:30
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-06-23 00:09:42 +05:30
expect_no_offenses(<<~PATTERN)
2020-01-01 13:55:28 +05:30
def change
add_index :table, :column
end
PATTERN
end
end
end