summaryrefslogtreecommitdiff
path: root/spec/rubocop/cop/migration/refer_to_index_by_name_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/rubocop/cop/migration/refer_to_index_by_name_spec.rb')
-rw-r--r--spec/rubocop/cop/migration/refer_to_index_by_name_spec.rb21
1 files changed, 8 insertions, 13 deletions
diff --git a/spec/rubocop/cop/migration/refer_to_index_by_name_spec.rb b/spec/rubocop/cop/migration/refer_to_index_by_name_spec.rb
index a25328a56a8..b3e66492d83 100644
--- a/spec/rubocop/cop/migration/refer_to_index_by_name_spec.rb
+++ b/spec/rubocop/cop/migration/refer_to_index_by_name_spec.rb
@@ -1,22 +1,19 @@
# frozen_string_literal: true
#
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/migration/refer_to_index_by_name'
RSpec.describe RuboCop::Cop::Migration::ReferToIndexByName do
- include CopHelper
-
subject(:cop) { described_class.new }
- context 'in migration' do
+ context 'when in migration' do
before do
allow(cop).to receive(:in_migration?).and_return(true)
end
context 'when existing indexes are referred to without an explicit name' do
it 'registers an offense' do
- expect_offense(<<~RUBY)
+ expect_offense(<<~RUBY, msg: 'migration methods that refer to existing indexes must do so by name')
class TestReferToIndexByName < ActiveRecord::Migration[6.0]
DOWNTIME = false
@@ -30,22 +27,22 @@ RSpec.describe RuboCop::Cop::Migration::ReferToIndexByName do
end
if index_exists? :test_indexes, :column2
- ^^^^^^^^^^^^^ #{described_class::MSG}
+ ^^^^^^^^^^^^^ %{msg}
remove_index :test_indexes, :column2
- ^^^^^^^^^^^^ #{described_class::MSG}
+ ^^^^^^^^^^^^ %{msg}
end
remove_index :test_indexes, column: column3
- ^^^^^^^^^^^^ #{described_class::MSG}
+ ^^^^^^^^^^^^ %{msg}
remove_index :test_indexes, name: 'index_name_4'
end
def down
if index_exists? :test_indexes, :column4, using: :gin, opclass: :gin_trgm_ops
- ^^^^^^^^^^^^^ #{described_class::MSG}
+ ^^^^^^^^^^^^^ %{msg}
remove_concurrent_index :test_indexes, :column4, using: :gin, opclass: :gin_trgm_ops
- ^^^^^^^^^^^^^^^^^^^^^^^ #{described_class::MSG}
+ ^^^^^^^^^^^^^^^^^^^^^^^ %{msg}
end
if index_exists? :test_indexes, :column3, unique: true, name: 'index_name_3', where: 'column3 = 10'
@@ -54,13 +51,11 @@ RSpec.describe RuboCop::Cop::Migration::ReferToIndexByName do
end
end
RUBY
-
- expect(cop.offenses.map(&:cop_name)).to all(eq("Migration/#{described_class.name.demodulize}"))
end
end
end
- context 'outside migration' do
+ context 'when outside migration' do
before do
allow(cop).to receive(:in_migration?).and_return(false)
end