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

56 lines
1.5 KiB
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
require 'spec_helper'
require 'rubocop'
require 'rubocop/rspec/support'
require_relative '../../../../rubocop/cop/migration/hash_index'
describe RuboCop::Cop::Migration::HashIndex 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 creating a hash index' do
2018-03-17 18:26:18 +05:30
inspect_source('def change; add_index :table, :column, using: :hash; end')
2017-09-10 17:25:29 +05:30
aggregate_failures do
expect(cop.offenses.size).to eq(1)
expect(cop.offenses.map(&:line)).to eq([1])
end
end
it 'registers an offense when creating a concurrent hash index' do
2018-03-17 18:26:18 +05:30
inspect_source('def change; add_concurrent_index :table, :column, using: :hash; end')
2017-09-10 17:25:29 +05:30
aggregate_failures do
expect(cop.offenses.size).to eq(1)
expect(cop.offenses.map(&:line)).to eq([1])
end
end
it 'registers an offense when creating a hash index using t.index' do
2018-03-17 18:26:18 +05:30
inspect_source('def change; t.index :table, :column, using: :hash; end')
2017-09-10 17:25:29 +05:30
aggregate_failures do
expect(cop.offenses.size).to eq(1)
expect(cop.offenses.map(&:line)).to eq([1])
end
end
end
context 'outside of migration' do
it 'registers no offense' do
2018-03-17 18:26:18 +05:30
inspect_source('def change; index :table, :column, using: :hash; end')
2017-09-10 17:25:29 +05:30
expect(cop.offenses.size).to eq(0)
end
end
end