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

39 lines
1 KiB
Ruby
Raw Normal View History

2020-03-13 15:44:24 +05:30
# frozen_string_literal: true
2020-07-28 23:09:34 +05:30
require 'fast_spec_helper'
2020-03-13 15:44:24 +05:30
require 'rubocop'
require_relative '../../../../rubocop/cop/migration/add_column_with_default'
2020-07-28 23:09:34 +05:30
RSpec.describe RuboCop::Cop::Migration::AddColumnWithDefault, type: :rubocop do
2020-03-13 15:44:24 +05:30
include CopHelper
let(:cop) { described_class.new }
context 'outside of a migration' do
it 'does not register any offenses' do
expect_no_offenses(<<~RUBY)
def up
2020-04-08 14:13:33 +05:30
add_column_with_default(:merge_request_diff_files, :artifacts, :boolean, default: true, allow_null: false)
2020-03-13 15:44:24 +05:30
end
RUBY
end
end
context 'in a migration' do
before do
allow(cop).to receive(:in_migration?).and_return(true)
end
2020-05-24 23:13:21 +05:30
let(:offense) { '`add_column_with_default` is deprecated, use `add_column` instead' }
2020-03-13 15:44:24 +05:30
2021-02-22 17:27:13 +05:30
it 'registers an offense' do
2020-05-24 23:13:21 +05:30
expect_offense(<<~RUBY)
def up
add_column_with_default(:merge_request_diff_files, :artifacts, :boolean, default: true, allow_null: false)
^^^^^^^^^^^^^^^^^^^^^^^ #{offense}
end
RUBY
2020-03-13 15:44:24 +05:30
end
end
end