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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

32 lines
765 B
Ruby
Raw Permalink Normal View History

2020-01-01 13:55:28 +05:30
# frozen_string_literal: true
2022-10-11 01:57:18 +05:30
require 'rubocop_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
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