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

feature_category_spec.rb « background_migration « cop « rubocop « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1d1b6cfad5a39064b43b4394094fce26c4cec004 (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
61
62
63
64
65
66
67
68
69
# frozen_string_literal: true

require 'rubocop_spec_helper'
require_relative '../../../../rubocop/cop/background_migration/feature_category'

RSpec.describe RuboCop::Cop::BackgroundMigration::FeatureCategory, feature_category: :database do
  context 'for non background migrations' do
    before do
      allow(cop).to receive(:in_background_migration?).and_return(false)
    end

    it 'does not throw any offense' do
      expect_no_offenses(<<~RUBY)
        module Gitlab
          module BackgroundMigration
            class MyJob < Gitlab::BackgroundMigration::BatchedMigrationJob
              def perform; end
            end
          end
        end
      RUBY
    end
  end

  context 'for background migrations' do
    before do
      allow(cop).to receive(:in_background_migration?).and_return(true)
    end

    it 'throws offense on not defining the feature_category' do
      expect_offense(<<~RUBY)
        module Gitlab
          module BackgroundMigration
            class MyJob1 < Gitlab::BackgroundMigration::BatchedMigrationJob
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{described_class::MSG}
            end
          end
        end
      RUBY
    end

    it 'throws offense on not defining a valid feature_category' do
      expect_offense(<<~RUBY)
        module Gitlab
          module BackgroundMigration
            class MyJob1 < Gitlab::BackgroundMigration::BatchedMigrationJob
            feature_category :invalid_random
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{described_class::INVALID_FEATURE_CATEGORY_MSG}
            end
          end
        end
      RUBY
    end

    it 'will not throw offense on defining a valid feature_category' do
      expect_no_offenses(<<~RUBY)
        module Gitlab
          module BackgroundMigration
            class MyJob < Gitlab::BackgroundMigration::BatchedMigrationJob
              feature_category :database

              def perform; end
            end
          end
        end
      RUBY
    end
  end
end