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

sidekiq_api_usage_spec.rb « cop « rubocop « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 79a0774e6253abeadcc5ec93a4c06448d64d59dd (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
48
49
50
51
52
53
54
55
56
57
58
59
60
# frozen_string_literal: true

require 'rubocop_spec_helper'

require_relative '../../../rubocop/cop/sidekiq_api_usage'

RSpec.describe RuboCop::Cop::SidekiqApiUsage do
  let(:msg) { described_class::MSG }

  context 'when calling Sidekiq::Worker' do
    it 'registers no offences for calling skipping_transaction_check' do
      expect_no_offenses(<<~PATTERN)
        Sidekiq::Worker.skipping_transaction_check do
        end
      PATTERN
    end

    it 'registers no offences for calling raise_inside_transaction_exception' do
      expect_no_offenses(<<~PATTERN)
        Sidekiq::Worker.raise_inside_transaction_exception(cause: "testing")
      PATTERN
    end

    it 'registers no offences for calling raise_exception_for_being_inside_a_transaction?' do
      expect_no_offenses(<<~PATTERN)
        return if Sidekiq::Worker.raise_exception_for_being_inside_a_transaction?
      PATTERN
    end

    it 'registers offence for calling other Sidekiq::Worker methods' do
      expect_offense(<<~PATTERN)
        Sidekiq::Worker.drain_all
        ^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg}
      PATTERN
    end
  end

  it 'does not registers offence when calling Sidekiq::Testing' do
    expect_no_offenses(<<~PATTERN)
      Sidekiq::Testing.inline! do
        create_real_projects!
        create_large_projects!
      end
    PATTERN
  end

  it 'registers offence when calling Sidekiq API' do
    expect_offense(<<~PATTERN)
      Sidekiq::Queue.new('testing').all
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg}
    PATTERN
  end

  it 'registers offence when assigning Sidekiq API classes' do
    expect_offense(<<~PATTERN)
      retry_set = Sidekiq::RetrySet.new
                  ^^^^^^^^^^^^^^^^^^^^^ #{msg}
    PATTERN
  end
end