blob: f6c6955f6bb075cfa69c087eb25b4e4beed0c51f (
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 'fast_spec_helper'
require_relative '../../../../rubocop/cop/gitlab/avoid_feature_category_not_owned'
RSpec.describe RuboCop::Cop::Gitlab::AvoidFeatureCategoryNotOwned do
subject(:cop) { described_class.new }
shared_examples 'defining feature category on a class' do
it 'flags a method call on a class' do
expect_offense(<<~SOURCE)
feature_category :not_owned
^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid adding new endpoints with `feature_category :not_owned`. See https://docs.gitlab.com/ee/development/feature_categorization
SOURCE
end
it 'flags a method call on a class with an array passed' do
expect_offense(<<~SOURCE)
feature_category :not_owned, [:index, :edit]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid adding new endpoints with `feature_category :not_owned`. See https://docs.gitlab.com/ee/development/feature_categorization
SOURCE
end
it 'flags a method call on a class with an array passed' do
expect_offense(<<~SOURCE)
worker.feature_category :not_owned, [:index, :edit]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid adding new endpoints with `feature_category :not_owned`. See https://docs.gitlab.com/ee/development/feature_categorization
SOURCE
end
end
context 'in controllers' do
before do
allow(subject).to receive(:in_controller?).and_return(true)
end
it_behaves_like 'defining feature category on a class'
end
context 'in workers' do
before do
allow(subject).to receive(:in_worker?).and_return(true)
end
it_behaves_like 'defining feature category on a class'
end
context 'for grape endpoints' do
before do
allow(subject).to receive(:in_api?).and_return(true)
end
it_behaves_like 'defining feature category on a class'
it 'flags when passed as a hash for a Grape endpoint as keyword args' do
expect_offense(<<~SOURCE)
get :hello, feature_category: :not_owned
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid adding new endpoints with `feature_category :not_owned`. See https://docs.gitlab.com/ee/development/feature_categorization
SOURCE
end
it 'flags when passed as a hash for a Grape endpoint in a hash' do
expect_offense(<<~SOURCE)
get :hello, { feature_category: :not_owned, urgency: :low}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid adding new endpoints with `feature_category :not_owned`. See https://docs.gitlab.com/ee/development/feature_categorization
SOURCE
end
end
end
|