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.

59 lines
1.6 KiB
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
2020-07-28 23:09:34 +05:30
require 'fast_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
subject(:cop) { described_class.new }
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