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-12-20 16:37:47 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-12-20 16:37:47 +0300
commitaee0a117a889461ce8ced6fcf73207fe017f1d99 (patch)
tree891d9ef189227a8445d83f35c1b0fc99573f4380 /spec/rubocop
parent8d46af3258650d305f53b819eabf7ab18d22f59e (diff)
Add latest changes from gitlab-org/gitlab@14-6-stable-eev14.6.0-rc42
Diffstat (limited to 'spec/rubocop')
-rw-r--r--spec/rubocop/code_reuse_helpers_spec.rb75
-rw-r--r--spec/rubocop/cop/graphql/authorize_types_spec.rb2
-rw-r--r--spec/rubocop/cop/graphql/old_types_spec.rb16
-rw-r--r--spec/rubocop/cop/qa/testcase_link_format_spec.rb45
-rw-r--r--spec/rubocop/cop/static_translation_definition_spec.rb16
5 files changed, 147 insertions, 7 deletions
diff --git a/spec/rubocop/code_reuse_helpers_spec.rb b/spec/rubocop/code_reuse_helpers_spec.rb
index 695c152e3db..3220cff1681 100644
--- a/spec/rubocop/code_reuse_helpers_spec.rb
+++ b/spec/rubocop/code_reuse_helpers_spec.rb
@@ -21,6 +21,8 @@ RSpec.describe RuboCop::CodeReuseHelpers do
end.new
end
+ let(:ee_file_path) { File.expand_path('../../ee/app/models/license.rb', __dir__) }
+
describe '#send_to_constant?' do
it 'returns true when sending to a constant' do
node = build_and_parse_source('Foo.bar')
@@ -312,4 +314,77 @@ RSpec.describe RuboCop::CodeReuseHelpers do
cop.disallow_send_to(def_node, 'Finder', 'oops')
end
end
+
+ describe '#ee?' do
+ before do
+ stub_env('FOSS_ONLY', nil)
+ allow(File).to receive(:exist?).with(ee_file_path) { true }
+ end
+
+ it 'returns true when ee/app/models/license.rb exists' do
+ expect(cop.ee?).to eq(true)
+ end
+ end
+
+ describe '#jh?' do
+ context 'when jh directory exists and EE_ONLY is not set' do
+ before do
+ stub_env('EE_ONLY', nil)
+
+ allow(Dir).to receive(:exist?).with(File.expand_path('../../jh', __dir__)) { true }
+ end
+
+ context 'when ee/app/models/license.rb exists' do
+ before do
+ allow(File).to receive(:exist?).with(ee_file_path) { true }
+ end
+
+ context 'when FOSS_ONLY is not set' do
+ before do
+ stub_env('FOSS_ONLY', nil)
+ end
+
+ it 'returns true' do
+ expect(cop.jh?).to eq(true)
+ end
+ end
+
+ context 'when FOSS_ONLY is set to 1' do
+ before do
+ stub_env('FOSS_ONLY', '1')
+ end
+
+ it 'returns false' do
+ expect(cop.jh?).to eq(false)
+ end
+ end
+ end
+
+ context 'when ee/app/models/license.rb not exist' do
+ before do
+ allow(File).to receive(:exist?).with(ee_file_path) { false }
+ end
+
+ context 'when FOSS_ONLY is not set' do
+ before do
+ stub_env('FOSS_ONLY', nil)
+ end
+
+ it 'returns true' do
+ expect(cop.jh?).to eq(false)
+ end
+ end
+
+ context 'when FOSS_ONLY is set to 1' do
+ before do
+ stub_env('FOSS_ONLY', '1')
+ end
+
+ it 'returns false' do
+ expect(cop.jh?).to eq(false)
+ end
+ end
+ end
+ end
+ end
end
diff --git a/spec/rubocop/cop/graphql/authorize_types_spec.rb b/spec/rubocop/cop/graphql/authorize_types_spec.rb
index 6c521789e34..7aa36030526 100644
--- a/spec/rubocop/cop/graphql/authorize_types_spec.rb
+++ b/spec/rubocop/cop/graphql/authorize_types_spec.rb
@@ -11,7 +11,7 @@ RSpec.describe RuboCop::Cop::Graphql::AuthorizeTypes do
expect_offense(<<~TYPE)
module Types
class AType < BaseObject
- ^^^^^^^^^^^^^^^^^^^^^^^^ Add an `authorize :ability` call to the type: https://docs.gitlab.com/ee/development/api_graphql_styleguide.html#type-authorization
+ ^^^^^^^^^^^^^^^^^^^^^^^^ Add an `authorize :ability` call to the type: https://docs.gitlab.com/ee/development/graphql_guide/authorization.html#type-authorization
field :a_thing
field :another_thing
end
diff --git a/spec/rubocop/cop/graphql/old_types_spec.rb b/spec/rubocop/cop/graphql/old_types_spec.rb
index 396bf4ce997..5cf3b11548f 100644
--- a/spec/rubocop/cop/graphql/old_types_spec.rb
+++ b/spec/rubocop/cop/graphql/old_types_spec.rb
@@ -10,10 +10,16 @@ RSpec.describe RuboCop::Cop::Graphql::OldTypes do
subject(:cop) { described_class.new }
where(:old_type, :message) do
- 'GraphQL::ID_TYPE' | 'Avoid using GraphQL::ID_TYPE. Use GraphQL::Types::ID instead'
- 'GraphQL::INT_TYPE' | 'Avoid using GraphQL::INT_TYPE. Use GraphQL::Types::Int instead'
- 'GraphQL::STRING_TYPE' | 'Avoid using GraphQL::STRING_TYPE. Use GraphQL::Types::String instead'
- 'GraphQL::BOOLEAN_TYPE' | 'Avoid using GraphQL::BOOLEAN_TYPE. Use GraphQL::Types::Boolean instead'
+ 'GraphQL::ID_TYPE' | 'Avoid using GraphQL::ID_TYPE. Use GraphQL::Types::ID instead'
+ 'GraphQL::INT_TYPE' | 'Avoid using GraphQL::INT_TYPE. Use GraphQL::Types::Int instead'
+ 'GraphQL::STRING_TYPE' | 'Avoid using GraphQL::STRING_TYPE. Use GraphQL::Types::String instead'
+ 'GraphQL::BOOLEAN_TYPE' | 'Avoid using GraphQL::BOOLEAN_TYPE. Use GraphQL::Types::Boolean instead'
+ 'GraphQL::FLOAT_TYPE' | 'Avoid using GraphQL::FLOAT_TYPE. Use GraphQL::Types::Float instead'
+ '::GraphQL::ID_TYPE' | 'Avoid using GraphQL::ID_TYPE. Use GraphQL::Types::ID instead'
+ '::GraphQL::INT_TYPE' | 'Avoid using GraphQL::INT_TYPE. Use GraphQL::Types::Int instead'
+ '::GraphQL::STRING_TYPE' | 'Avoid using GraphQL::STRING_TYPE. Use GraphQL::Types::String instead'
+ '::GraphQL::BOOLEAN_TYPE' | 'Avoid using GraphQL::BOOLEAN_TYPE. Use GraphQL::Types::Boolean instead'
+ '::GraphQL::FLOAT_TYPE' | 'Avoid using GraphQL::FLOAT_TYPE. Use GraphQL::Types::Float instead'
end
with_them do
@@ -27,7 +33,7 @@ RSpec.describe RuboCop::Cop::Graphql::OldTypes do
RUBY
end
- it "adds an offense when an old type is used with other keywords" do
+ it 'adds an offense when an old type is used with other keywords' do
expect_offense(<<~RUBY)
class MyType
field :some_field, #{old_type}, null: true, description: 'My description'
diff --git a/spec/rubocop/cop/qa/testcase_link_format_spec.rb b/spec/rubocop/cop/qa/testcase_link_format_spec.rb
new file mode 100644
index 00000000000..f9b43f2a293
--- /dev/null
+++ b/spec/rubocop/cop/qa/testcase_link_format_spec.rb
@@ -0,0 +1,45 @@
+# 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
diff --git a/spec/rubocop/cop/static_translation_definition_spec.rb b/spec/rubocop/cop/static_translation_definition_spec.rb
index b2b04cbcbde..554a7c17a4b 100644
--- a/spec/rubocop/cop/static_translation_definition_spec.rb
+++ b/spec/rubocop/cop/static_translation_definition_spec.rb
@@ -112,7 +112,7 @@ RSpec.describe RuboCop::Cop::StaticTranslationDefinition do
}
end
CODE
- <<~CODE
+ <<~CODE,
class MyClass
def hello
{
@@ -121,6 +121,20 @@ RSpec.describe RuboCop::Cop::StaticTranslationDefinition do
end
end
CODE
+ <<~CODE,
+ SomeClass = Struct.new do
+ def text
+ _('Some translated text')
+ end
+ end
+ CODE
+ <<~CODE
+ Struct.new('SomeClass') do
+ def text
+ _('Some translated text')
+ end
+ end
+ CODE
]
end