2017-02-09 15:52:43 +00:00
|
|
|
require 'spec_helper'
|
2017-09-19 15:25:42 +00:00
|
|
|
|
2017-02-09 15:52:43 +00:00
|
|
|
require 'rubocop'
|
|
|
|
require 'rubocop/rspec/support'
|
2017-09-19 15:25:42 +00:00
|
|
|
|
2017-02-09 15:52:43 +00:00
|
|
|
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
|
2017-09-19 15:25:42 +00:00
|
|
|
inspect_source('def up; add_foreign_key(:projects, :users, column: :user_id); end')
|
2017-02-09 15:52:43 +00:00
|
|
|
|
|
|
|
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
|
2017-09-19 15:25:42 +00:00
|
|
|
inspect_source('def up; add_foreign_key(:projects, :users, column: :user_id); end')
|
2017-02-09 15:52:43 +00:00
|
|
|
|
|
|
|
aggregate_failures do
|
|
|
|
expect(cop.offenses.size).to eq(1)
|
|
|
|
expect(cop.offenses.map(&:line)).to eq([1])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|