BigW Consortium Gitlab

add_concurrent_foreign_key_spec.rb 916 Bytes
Newer Older
1
require 'spec_helper'
Rémy Coutable committed
2

3 4
require 'rubocop'
require 'rubocop/rspec/support'
Rémy Coutable committed
5

6 7 8 9 10 11 12 13 14
require_relative '../../../../rubocop/cop/migration/add_concurrent_foreign_key'

describe RuboCop::Cop::Migration::AddConcurrentForeignKey do
  include CopHelper

  let(:cop) { described_class.new }

  context 'outside of a migration' do
    it 'does not register any offenses' do
Rémy Coutable committed
15
      inspect_source('def up; add_foreign_key(:projects, :users, column: :user_id); end')
16 17 18 19 20 21 22 23 24 25 26

      expect(cop.offenses).to be_empty
    end
  end

  context 'in a migration' do
    before do
      allow(cop).to receive(:in_migration?).and_return(true)
    end

    it 'registers an offense when using add_foreign_key' do
Rémy Coutable committed
27
      inspect_source('def up; add_foreign_key(:projects, :users, column: :user_id); end')
28 29 30 31 32 33 34 35

      aggregate_failures do
        expect(cop.offenses.size).to eq(1)
        expect(cop.offenses.map(&:line)).to eq([1])
      end
    end
  end
end