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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

57 lines
1.6 KiB
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
2022-10-11 01:57:18 +05:30
require 'rubocop_spec_helper'
2018-03-17 18:26:18 +05:30
require_relative '../../../../rubocop/cop/migration/remove_column'
2021-03-08 18:12:59 +05:30
RSpec.describe RuboCop::Cop::Migration::RemoveColumn do
2018-03-17 18:26:18 +05:30
def source(meth = 'change')
"def #{meth}; remove_column :table, :column; end"
end
2021-04-17 20:07:23 +05:30
context 'when in a regular migration' do
2018-03-17 18:26:18 +05:30
before do
allow(cop).to receive(:in_migration?).and_return(true)
allow(cop).to receive(:in_post_deployment_migration?).and_return(false)
end
it 'registers an offense when remove_column is used in the change method' do
2021-04-17 20:07:23 +05:30
expect_offense(<<~RUBY)
def change
remove_column :table, :column
^^^^^^^^^^^^^ `remove_column` must only be used in post-deployment migrations
end
RUBY
2018-03-17 18:26:18 +05:30
end
it 'registers an offense when remove_column is used in the up method' do
2021-04-17 20:07:23 +05:30
expect_offense(<<~RUBY)
def up
remove_column :table, :column
^^^^^^^^^^^^^ `remove_column` must only be used in post-deployment migrations
end
RUBY
2018-03-17 18:26:18 +05:30
end
it 'registers no offense when remove_column is used in the down method' do
2021-04-17 20:07:23 +05:30
expect_no_offenses(source('down'))
2018-03-17 18:26:18 +05:30
end
end
2021-04-17 20:07:23 +05:30
context 'when in a post-deployment migration' do
2018-03-17 18:26:18 +05:30
before do
allow(cop).to receive(:in_migration?).and_return(true)
allow(cop).to receive(:in_post_deployment_migration?).and_return(true)
end
it 'registers no offense' do
2021-04-17 20:07:23 +05:30
expect_no_offenses(source)
2018-03-17 18:26:18 +05:30
end
end
2021-04-17 20:07:23 +05:30
context 'when outside of a migration' do
2018-03-17 18:26:18 +05:30
it 'registers no offense' do
2021-04-17 20:07:23 +05:30
expect_no_offenses(source)
2018-03-17 18:26:18 +05:30
end
end
end