Welcome to mirror list, hosted at ThFree Co, Russian Federation.

sidekiq_queue_migrate_spec.rb « migration « cop « rubocop « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 499351b3585d1fbab3f402195fc3d0a61a4ca12d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# frozen_string_literal: true

require 'fast_spec_helper'
require_relative '../../../../rubocop/cop/migration/sidekiq_queue_migrate'

RSpec.describe RuboCop::Cop::Migration::SidekiqQueueMigrate do
  subject(:cop) { described_class.new }

  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