diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 13:00:54 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 13:00:54 +0300 |
commit | 3cccd102ba543e02725d247893729e5c73b38295 (patch) | |
tree | f36a04ec38517f5deaaacb5acc7d949688d1e187 /spec/rubocop/cop/gitlab | |
parent | 205943281328046ef7b4528031b90fbda70c75ac (diff) |
Add latest changes from gitlab-org/gitlab@14-10-stable-eev14.10.0-rc42
Diffstat (limited to 'spec/rubocop/cop/gitlab')
-rw-r--r-- | spec/rubocop/cop/gitlab/avoid_feature_category_not_owned_spec.rb | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/spec/rubocop/cop/gitlab/avoid_feature_category_not_owned_spec.rb b/spec/rubocop/cop/gitlab/avoid_feature_category_not_owned_spec.rb new file mode 100644 index 00000000000..f6c6955f6bb --- /dev/null +++ b/spec/rubocop/cop/gitlab/avoid_feature_category_not_owned_spec.rb @@ -0,0 +1,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 |