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

34 lines
982 B
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_relative '../../../../rubocop/cop/migration/add_column_with_default'
2021-03-08 18:12:59 +05:30
RSpec.describe RuboCop::Cop::Migration::AddColumnWithDefault do
2020-03-13 15:44:24 +05:30
let(:cop) { described_class.new }
2021-04-17 20:07:23 +05:30
context 'when outside of a migration' do
2020-03-13 15:44:24 +05:30
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
2021-04-17 20:07:23 +05:30
context 'when in a migration' do
2020-03-13 15:44:24 +05:30
before do
allow(cop).to receive(:in_migration?).and_return(true)
end
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)
2021-04-17 20:07:23 +05:30
^^^^^^^^^^^^^^^^^^^^^^^ `add_column_with_default` is deprecated, use `add_column` instead
2020-05-24 23:13:21 +05:30
end
RUBY
2020-03-13 15:44:24 +05:30
end
end
end