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

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

46 lines
1.3 KiB
Ruby
Raw Permalink Normal View History

2021-09-30 23:02:18 +05:30
# frozen_string_literal: true
2022-10-11 01:57:18 +05:30
require 'rubocop_spec_helper'
2021-09-30 23:02:18 +05:30
require_relative '../../../../rubocop/cop/migration/sidekiq_queue_migrate'
RSpec.describe RuboCop::Cop::Migration::SidekiqQueueMigrate do
def source(meth = 'change')
"def #{meth}; sidekiq_queue_migrate 'queue', to: 'new_queue'; end"
end
context 'when in a regular migration' do
before do
allow(cop).to receive(:in_migration?).and_return(true)
allow(cop).to receive(:in_post_deployment_migration?).and_return(false)
end
%w(up down change any_other_method).each do |method_name|
it "registers an offense when sidekiq_queue_migrate is used in ##{method_name}" do
expect_offense(<<~RUBY)
def #{method_name}
sidekiq_queue_migrate 'queue', to: 'new_queue'
^^^^^^^^^^^^^^^^^^^^^ `sidekiq_queue_migrate` must only be used in post-deployment migrations
end
RUBY
end
end
end
context 'when in a post-deployment migration' do
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
expect_no_offenses(source)
end
end
context 'when outside of a migration' do
it 'registers no offense' do
expect_no_offenses(source)
end
end
end