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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-04-21 02:50:22 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-04-21 02:50:22 +0300
commit9dc93a4519d9d5d7be48ff274127136236a3adb3 (patch)
tree70467ae3692a0e35e5ea56bcb803eb512a10bedb /spec/rubocop/cop/gitlab
parent4b0f34b6d759d6299322b3a54453e930c6121ff0 (diff)
Add latest changes from gitlab-org/gitlab@13-11-stable-eev13.11.0-rc43
Diffstat (limited to 'spec/rubocop/cop/gitlab')
-rw-r--r--spec/rubocop/cop/gitlab/delegate_predicate_methods_spec.rb40
-rw-r--r--spec/rubocop/cop/gitlab/feature_available_usage_spec.rb96
2 files changed, 136 insertions, 0 deletions
diff --git a/spec/rubocop/cop/gitlab/delegate_predicate_methods_spec.rb b/spec/rubocop/cop/gitlab/delegate_predicate_methods_spec.rb
new file mode 100644
index 00000000000..1ceff0dd681
--- /dev/null
+++ b/spec/rubocop/cop/gitlab/delegate_predicate_methods_spec.rb
@@ -0,0 +1,40 @@
+# frozen_string_literal: true
+
+require 'fast_spec_helper'
+require_relative '../../../../rubocop/cop/gitlab/delegate_predicate_methods'
+
+RSpec.describe RuboCop::Cop::Gitlab::DelegatePredicateMethods do
+ subject(:cop) { described_class.new }
+
+ it 'registers offense for single predicate method with allow_nil:true' do
+ expect_offense(<<~SOURCE)
+ delegate :is_foo?, :do_foo, to: :bar, allow_nil: true
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Using `delegate` with `allow_nil` on the following predicate methods is discouraged: is_foo?.
+ SOURCE
+ end
+
+ it 'registers offense for multiple predicate methods with allow_nil:true' do
+ expect_offense(<<~SOURCE)
+ delegate :is_foo?, :is_bar?, to: :bar, allow_nil: true
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Using `delegate` with `allow_nil` on the following predicate methods is discouraged: is_foo?, is_bar?.
+ SOURCE
+ end
+
+ it 'registers no offense for non-predicate method with allow_nil:true' do
+ expect_no_offenses(<<~SOURCE)
+ delegate :do_foo, to: :bar, allow_nil: true
+ SOURCE
+ end
+
+ it 'registers no offense with predicate method with allow_nil:false' do
+ expect_no_offenses(<<~SOURCE)
+ delegate :is_foo?, to: :bar, allow_nil: false
+ SOURCE
+ end
+
+ it 'registers no offense with predicate method without allow_nil' do
+ expect_no_offenses(<<~SOURCE)
+ delegate :is_foo?, to: :bar
+ SOURCE
+ end
+end
diff --git a/spec/rubocop/cop/gitlab/feature_available_usage_spec.rb b/spec/rubocop/cop/gitlab/feature_available_usage_spec.rb
new file mode 100644
index 00000000000..514ef357785
--- /dev/null
+++ b/spec/rubocop/cop/gitlab/feature_available_usage_spec.rb
@@ -0,0 +1,96 @@
+# frozen_string_literal: true
+
+require 'fast_spec_helper'
+require 'rubocop'
+require 'rubocop/rspec/support'
+require_relative '../../../../rubocop/cop/gitlab/feature_available_usage'
+
+RSpec.describe RuboCop::Cop::Gitlab::FeatureAvailableUsage do
+ subject(:cop) { described_class.new }
+
+ context 'no arguments given' do
+ it 'does not flag the use of Gitlab::Sourcegraph.feature_available? with no arguments' do
+ expect_no_offenses('Gitlab::Sourcegraph.feature_available?')
+ expect_no_offenses('subject { described_class.feature_available? }')
+ end
+ end
+
+ context 'one argument given' do
+ it 'does not flag the use of License.feature_available?' do
+ expect_no_offenses('License.feature_available?(:push_rules)')
+ end
+
+ it 'flags the use with a dynamic feature as nil' do
+ expect_offense(<<~SOURCE)
+ feature_available?(nil)
+ ^^^^^^^^^^^^^^^^^^^^^^^ `feature_available?` should not be called for features that can be licensed (`nil` given), use `licensed_feature_available?(feature)` instead.
+ SOURCE
+ expect_offense(<<~SOURCE)
+ project.feature_available?(nil)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `feature_available?` should not be called for features that can be licensed (`nil` given), use `licensed_feature_available?(feature)` instead.
+ SOURCE
+ end
+
+ it 'flags the use with an OSS project feature' do
+ expect_offense(<<~SOURCE)
+ project.feature_available?(:issues)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `feature_available?` should be called with two arguments: `feature` and `user`.
+ SOURCE
+ expect_offense(<<~SOURCE)
+ feature_available?(:issues)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `feature_available?` should be called with two arguments: `feature` and `user`.
+ SOURCE
+ end
+
+ it 'flags the use with a feature that is not a project feature' do
+ expect_offense(<<~SOURCE)
+ feature_available?(:foo)
+ ^^^^^^^^^^^^^^^^^^^^^^^^ `feature_available?` should not be called for features that can be licensed (`:foo` given), use `licensed_feature_available?(feature)` instead.
+ SOURCE
+ expect_offense(<<~SOURCE)
+ project.feature_available?(:foo)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `feature_available?` should not be called for features that can be licensed (`:foo` given), use `licensed_feature_available?(feature)` instead.
+ SOURCE
+ expect_offense(<<~SOURCE)
+ feature_available?(foo)
+ ^^^^^^^^^^^^^^^^^^^^^^^ `feature_available?` should not be called for features that can be licensed (`foo` isn't a literal so we cannot say if it's legit or not), using `licensed_feature_available?(feature)` may be more appropriate.
+ SOURCE
+ expect_offense(<<~SOURCE)
+ foo = :feature
+ feature_available?(foo)
+ ^^^^^^^^^^^^^^^^^^^^^^^ `feature_available?` should not be called for features that can be licensed (`foo` isn't a literal so we cannot say if it's legit or not), using `licensed_feature_available?(feature)` may be more appropriate.
+ SOURCE
+ end
+ end
+
+ context 'two arguments given' do
+ it 'does not flag the use with an OSS project feature' do
+ expect_no_offenses('feature_available?(:issues, user)')
+ expect_no_offenses('project.feature_available?(:issues, user)')
+ end
+
+ it 'does not flag the use with an EE project feature' do
+ expect_no_offenses('feature_available?(:requirements, user)')
+ expect_no_offenses('project.feature_available?(:requirements, user)')
+ end
+
+ it 'flags the use with a dynamic feature as a method call with two args' do
+ expect_offense(<<~SOURCE)
+ feature_available?(:foo, current_user)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `feature_available?` should not be called for features that can be licensed (`:foo` given), use `licensed_feature_available?(feature)` instead.
+ SOURCE
+ expect_offense(<<~SOURCE)
+ project.feature_available?(:foo, current_user)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `feature_available?` should not be called for features that can be licensed (`:foo` given), use `licensed_feature_available?(feature)` instead.
+ SOURCE
+ expect_offense(<<~SOURCE)
+ feature_available?(foo, current_user)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `feature_available?` should not be called for features that can be licensed (`foo` isn't a literal so we cannot say if it's legit or not), using `licensed_feature_available?(feature)` may be more appropriate.
+ SOURCE
+ expect_offense(<<~SOURCE)
+ project.feature_available?(foo, current_user)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `feature_available?` should not be called for features that can be licensed (`foo` isn't a literal so we cannot say if it's legit or not), using `licensed_feature_available?(feature)` may be more appropriate.
+ SOURCE
+ end
+ end
+end