summaryrefslogtreecommitdiff
path: root/spec/rubocop
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-04-20 10:00:54 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-04-20 10:00:54 +0000
commit3cccd102ba543e02725d247893729e5c73b38295 (patch)
treef36a04ec38517f5deaaacb5acc7d949688d1e187 /spec/rubocop
parent205943281328046ef7b4528031b90fbda70c75ac (diff)
downloadgitlab-ce-3cccd102ba543e02725d247893729e5c73b38295.tar.gz
Add latest changes from gitlab-org/gitlab@14-10-stable-eev14.10.0-rc42
Diffstat (limited to 'spec/rubocop')
-rw-r--r--spec/rubocop/cop/database/disable_referential_integrity_spec.rb36
-rw-r--r--spec/rubocop/cop/gitlab/avoid_feature_category_not_owned_spec.rb69
-rw-r--r--spec/rubocop/cop/qa/duplicate_testcase_link_spec.rb36
-rw-r--r--spec/rubocop/cop/qa/testcase_link_format_spec.rb45
4 files changed, 105 insertions, 81 deletions
diff --git a/spec/rubocop/cop/database/disable_referential_integrity_spec.rb b/spec/rubocop/cop/database/disable_referential_integrity_spec.rb
new file mode 100644
index 00000000000..9ac67363cb6
--- /dev/null
+++ b/spec/rubocop/cop/database/disable_referential_integrity_spec.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+require 'fast_spec_helper'
+require_relative '../../../../rubocop/cop/database/disable_referential_integrity'
+
+RSpec.describe RuboCop::Cop::Database::DisableReferentialIntegrity do
+ subject(:cop) { described_class.new }
+
+ it 'does not flag the use of disable_referential_integrity with a send receiver' do
+ expect_offense(<<~SOURCE)
+ foo.disable_referential_integrity
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use `disable_referential_integrity`, [...]
+ SOURCE
+ end
+
+ it 'flags the use of disable_referential_integrity with a full definition' do
+ expect_offense(<<~SOURCE)
+ ActiveRecord::Base.connection.disable_referential_integrity
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use `disable_referential_integrity`, [...]
+ SOURCE
+ end
+
+ it 'flags the use of disable_referential_integrity with a nil receiver' do
+ expect_offense(<<~SOURCE)
+ class Foo ; disable_referential_integrity ; end
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use `disable_referential_integrity`, [...]
+ SOURCE
+ end
+
+ it 'flags the use of disable_referential_integrity when passing a block' do
+ expect_offense(<<~SOURCE)
+ class Foo ; disable_referential_integrity { :foo } ; end
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use `disable_referential_integrity`, [...]
+ SOURCE
+ end
+end
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
diff --git a/spec/rubocop/cop/qa/duplicate_testcase_link_spec.rb b/spec/rubocop/cop/qa/duplicate_testcase_link_spec.rb
deleted file mode 100644
index fb424da90e8..00000000000
--- a/spec/rubocop/cop/qa/duplicate_testcase_link_spec.rb
+++ /dev/null
@@ -1,36 +0,0 @@
-# frozen_string_literal: true
-
-require 'fast_spec_helper'
-
-require_relative '../../../../rubocop/cop/qa/duplicate_testcase_link'
-
-RSpec.describe RuboCop::Cop::QA::DuplicateTestcaseLink do
- let(:source_file) { 'qa/page.rb' }
-
- subject(:cop) { described_class.new }
-
- context 'in a QA file' do
- before do
- allow(cop).to receive(:in_qa_file?).and_return(true)
- end
-
- it "registers an offense for a duplicate testcase link" do
- expect_offense(<<-RUBY)
- it 'some test', testcase: '/quality/test_cases/1892' do
- end
- it 'another test', testcase: '/quality/test_cases/1892' do
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Don't reuse the same testcase link in different tests. Replace one of `/quality/test_cases/1892`.
- end
- RUBY
- end
-
- it "doesnt offend if testcase link is unique" do
- expect_no_offenses(<<-RUBY)
- it 'some test', testcase: '/quality/test_cases/1893' do
- end
- it 'another test', testcase: '/quality/test_cases/1894' do
- end
- RUBY
- end
- end
-end
diff --git a/spec/rubocop/cop/qa/testcase_link_format_spec.rb b/spec/rubocop/cop/qa/testcase_link_format_spec.rb
deleted file mode 100644
index f9b43f2a293..00000000000
--- a/spec/rubocop/cop/qa/testcase_link_format_spec.rb
+++ /dev/null
@@ -1,45 +0,0 @@
-# frozen_string_literal: true
-
-require 'fast_spec_helper'
-
-require_relative '../../../../rubocop/cop/qa/testcase_link_format'
-
-RSpec.describe RuboCop::Cop::QA::TestcaseLinkFormat do
- let(:source_file) { 'qa/page.rb' }
- let(:msg) { 'Testcase link format incorrect. Please link a test case from the GitLab project. See: https://docs.gitlab.com/ee/development/testing_guide/end_to_end/best_practices.html#link-a-test-to-its-test-case.' }
-
- subject(:cop) { described_class.new }
-
- context 'in a QA file' do
- before do
- allow(cop).to receive(:in_qa_file?).and_return(true)
- end
-
- it "registers an offense for a testcase link for an issue" do
- node = "it 'another test', testcase: 'https://gitlab.com/gitlab-org/gitlab/-/issues/557' do"
-
- expect_offense(<<-RUBY, node: node, msg: msg)
- %{node}
- ^{node} %{msg}
- end
- RUBY
- end
-
- it "registers an offense for a testcase link for the wrong project" do
- node = "it 'another test', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/quality/test_cases/2455' do"
-
- expect_offense(<<-RUBY, node: node, msg: msg)
- %{node}
- ^{node} %{msg}
- end
- RUBY
- end
-
- it "doesnt offend if testcase link is correct" do
- expect_no_offenses(<<-RUBY)
- it 'some test', testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/348312' do
- end
- RUBY
- end
- end
-end