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

bulk_perform_with_context_spec.rb « scalability « cop « rubocop « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6e526f7ad8f0cfd75845890693c2ad2dfab091be (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
# frozen_string_literal: true

require 'fast_spec_helper'
require 'rubocop'
require_relative '../../../../rubocop/cop/scalability/bulk_perform_with_context'

RSpec.describe RuboCop::Cop::Scalability::BulkPerformWithContext do
  include CopHelper

  subject(:cop) { described_class.new }

  it "adds an offense when calling bulk_perform_async" do
    inspect_source(<<~CODE)
      Worker.bulk_perform_async(args)
    CODE

    expect(cop.offenses.size).to eq(1)
  end

  it "adds an offense when calling bulk_perform_in" do
    inspect_source(<<~CODE)
      diffs.each_batch(of: BATCH_SIZE) do |relation, index|
        ids = relation.pluck_primary_key.map { |id| [id] }
        DeleteDiffFilesWorker.bulk_perform_in(index * 5.minutes, ids)
      end
    CODE

    expect(cop.offenses.size).to eq(1)
  end

  it "does not add an offense for migrations" do
    allow(cop).to receive(:in_migration?).and_return(true)

    inspect_source(<<~CODE)
      Worker.bulk_perform_in(args)
    CODE

    expect(cop.offenses.size).to eq(0)
  end

  it "does not add an offence for specs" do
    allow(cop).to receive(:in_spec?).and_return(true)

    inspect_source(<<~CODE)
      Worker.bulk_perform_in(args)
    CODE

    expect(cop.offenses.size).to eq(0)
  end

  it "does not add an offense for scheduling BackgroundMigrations" do
    inspect_source(<<~CODE)
      BackgroundMigrationWorker.bulk_perform_in(args)
    CODE

    expect(cop.offenses.size).to eq(0)
  end
end