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-02-18 13:34:06 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-02-18 13:34:06 +0300
commit859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 (patch)
treed7f2700abe6b4ffcb2dcfc80631b2d87d0609239 /spec/rubocop/cop/graphql
parent446d496a6d000c73a304be52587cd9bbc7493136 (diff)
Add latest changes from gitlab-org/gitlab@13-9-stable-eev13.9.0-rc42
Diffstat (limited to 'spec/rubocop/cop/graphql')
-rw-r--r--spec/rubocop/cop/graphql/authorize_types_spec.rb7
-rw-r--r--spec/rubocop/cop/graphql/descriptions_spec.rb22
-rw-r--r--spec/rubocop/cop/graphql/gid_expected_type_spec.rb7
-rw-r--r--spec/rubocop/cop/graphql/id_type_spec.rb7
-rw-r--r--spec/rubocop/cop/graphql/json_type_spec.rb24
-rw-r--r--spec/rubocop/cop/graphql/resolver_type_spec.rb18
6 files changed, 30 insertions, 55 deletions
diff --git a/spec/rubocop/cop/graphql/authorize_types_spec.rb b/spec/rubocop/cop/graphql/authorize_types_spec.rb
index a1b7a3f3a9b..9242b865b20 100644
--- a/spec/rubocop/cop/graphql/authorize_types_spec.rb
+++ b/spec/rubocop/cop/graphql/authorize_types_spec.rb
@@ -6,21 +6,18 @@ require 'rubocop'
require_relative '../../../../rubocop/cop/graphql/authorize_types'
RSpec.describe RuboCop::Cop::Graphql::AuthorizeTypes do
- include CopHelper
-
subject(:cop) { described_class.new }
it 'adds an offense when there is no authorize call' do
- inspect_source(<<~TYPE)
+ 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
field :a_thing
field :another_thing
end
end
TYPE
-
- expect(cop.offenses.size).to eq 1
end
it 'does not add an offense for classes that have an authorize call' do
diff --git a/spec/rubocop/cop/graphql/descriptions_spec.rb b/spec/rubocop/cop/graphql/descriptions_spec.rb
index b44205b0920..9ad40fad83d 100644
--- a/spec/rubocop/cop/graphql/descriptions_spec.rb
+++ b/spec/rubocop/cop/graphql/descriptions_spec.rb
@@ -5,38 +5,34 @@ require 'rubocop'
require_relative '../../../../rubocop/cop/graphql/descriptions'
RSpec.describe RuboCop::Cop::Graphql::Descriptions do
- include CopHelper
-
subject(:cop) { described_class.new }
context 'fields' do
it 'adds an offense when there is no description' do
- inspect_source(<<~TYPE)
+ expect_offense(<<~TYPE)
module Types
class FakeType < BaseObject
field :a_thing,
+ ^^^^^^^^^^^^^^^ Please add a `description` property.
GraphQL::STRING_TYPE,
null: false
end
end
TYPE
-
- expect(cop.offenses.size).to eq 1
end
it 'adds an offense when description does not end in a period' do
- inspect_source(<<~TYPE)
+ expect_offense(<<~TYPE)
module Types
class FakeType < BaseObject
field :a_thing,
+ ^^^^^^^^^^^^^^^ `description` strings must end with a `.`.
GraphQL::STRING_TYPE,
null: false,
description: 'A descriptive description'
end
end
TYPE
-
- expect(cop.offenses.size).to eq 1
end
it 'does not add an offense when description is correct' do
@@ -55,32 +51,30 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do
context 'arguments' do
it 'adds an offense when there is no description' do
- inspect_source(<<~TYPE)
+ expect_offense(<<~TYPE)
module Types
class FakeType < BaseObject
argument :a_thing,
+ ^^^^^^^^^^^^^^^^^^ Please add a `description` property.
GraphQL::STRING_TYPE,
null: false
end
end
TYPE
-
- expect(cop.offenses.size).to eq 1
end
it 'adds an offense when description does not end in a period' do
- inspect_source(<<~TYPE)
+ expect_offense(<<~TYPE)
module Types
class FakeType < BaseObject
argument :a_thing,
+ ^^^^^^^^^^^^^^^^^^ `description` strings must end with a `.`.
GraphQL::STRING_TYPE,
null: false,
description: 'Behold! A description'
end
end
TYPE
-
- expect(cop.offenses.size).to eq 1
end
it 'does not add an offense when description is correct' do
diff --git a/spec/rubocop/cop/graphql/gid_expected_type_spec.rb b/spec/rubocop/cop/graphql/gid_expected_type_spec.rb
index 8fd7ae03748..d9a129244d6 100644
--- a/spec/rubocop/cop/graphql/gid_expected_type_spec.rb
+++ b/spec/rubocop/cop/graphql/gid_expected_type_spec.rb
@@ -6,16 +6,13 @@ require 'rubocop'
require_relative '../../../../rubocop/cop/graphql/gid_expected_type'
RSpec.describe RuboCop::Cop::Graphql::GIDExpectedType do
- include CopHelper
-
subject(:cop) { described_class.new }
it 'adds an offense when there is no expected_type parameter' do
- inspect_source(<<~TYPE)
+ expect_offense(<<~TYPE)
GitlabSchema.object_from_id(received_id)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Add an expected_type parameter to #object_from_id calls if possible.
TYPE
-
- expect(cop.offenses.size).to eq 1
end
it 'does not add an offense for calls that have an expected_type parameter' do
diff --git a/spec/rubocop/cop/graphql/id_type_spec.rb b/spec/rubocop/cop/graphql/id_type_spec.rb
index 6135c9fef43..93c01cd7f06 100644
--- a/spec/rubocop/cop/graphql/id_type_spec.rb
+++ b/spec/rubocop/cop/graphql/id_type_spec.rb
@@ -6,16 +6,13 @@ require 'rubocop'
require_relative '../../../../rubocop/cop/graphql/id_type'
RSpec.describe RuboCop::Cop::Graphql::IDType do
- include CopHelper
-
subject(:cop) { described_class.new }
it 'adds an offense when GraphQL::ID_TYPE is used as a param to #argument' do
- inspect_source(<<~TYPE)
+ expect_offense(<<~TYPE)
argument :some_arg, GraphQL::ID_TYPE, some: other, params: do_not_matter
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use GraphQL::ID_TYPE, use a specific GlobalIDType instead
TYPE
-
- expect(cop.offenses.size).to eq 1
end
context 'whitelisted arguments' do
diff --git a/spec/rubocop/cop/graphql/json_type_spec.rb b/spec/rubocop/cop/graphql/json_type_spec.rb
index 6d9f86e44d2..91838c1708e 100644
--- a/spec/rubocop/cop/graphql/json_type_spec.rb
+++ b/spec/rubocop/cop/graphql/json_type_spec.rb
@@ -5,29 +5,29 @@ require 'rubocop'
require_relative '../../../../rubocop/cop/graphql/json_type'
RSpec.describe RuboCop::Cop::Graphql::JSONType do
- include CopHelper
+ let(:msg) do
+ 'Avoid using GraphQL::Types::JSON. See: https://docs.gitlab.com/ee/development/api_graphql_styleguide.html#json'
+ end
subject(:cop) { described_class.new }
context 'fields' do
it 'adds an offense when GraphQL::Types::JSON is used' do
- inspect_source(<<~RUBY.strip)
+ expect_offense(<<~RUBY)
class MyType
field :some_field, GraphQL::Types::JSON
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg}
end
RUBY
-
- expect(cop.offenses.size).to eq(1)
end
it 'adds an offense when GraphQL::Types::JSON is used with other keywords' do
- inspect_source(<<~RUBY.strip)
+ expect_offense(<<~RUBY)
class MyType
field :some_field, GraphQL::Types::JSON, null: true, description: 'My description'
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg}
end
RUBY
-
- expect(cop.offenses.size).to eq(1)
end
it 'does not add an offense for other types' do
@@ -41,23 +41,21 @@ RSpec.describe RuboCop::Cop::Graphql::JSONType do
context 'arguments' do
it 'adds an offense when GraphQL::Types::JSON is used' do
- inspect_source(<<~RUBY.strip)
+ expect_offense(<<~RUBY)
class MyType
argument :some_arg, GraphQL::Types::JSON
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg}
end
RUBY
-
- expect(cop.offenses.size).to eq(1)
end
it 'adds an offense when GraphQL::Types::JSON is used with other keywords' do
- inspect_source(<<~RUBY.strip)
+ expect_offense(<<~RUBY)
class MyType
argument :some_arg, GraphQL::Types::JSON, null: true, description: 'My description'
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg}
end
RUBY
-
- expect(cop.offenses.size).to eq(1)
end
it 'does not add an offense for other types' do
diff --git a/spec/rubocop/cop/graphql/resolver_type_spec.rb b/spec/rubocop/cop/graphql/resolver_type_spec.rb
index 25213e30528..11c0ad284a9 100644
--- a/spec/rubocop/cop/graphql/resolver_type_spec.rb
+++ b/spec/rubocop/cop/graphql/resolver_type_spec.rb
@@ -6,24 +6,19 @@ require 'rubocop'
require_relative '../../../../rubocop/cop/graphql/resolver_type'
RSpec.describe RuboCop::Cop::Graphql::ResolverType do
- include CopHelper
-
subject(:cop) { described_class.new }
- it 'adds an offense when there is no type annotaion' do
- lacks_type = <<-SRC
+ it 'adds an offense when there is no type annotation' do
+ expect_offense(<<~SRC)
module Resolvers
class FooResolver < BaseResolver
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Missing type annotation: Please add `type` DSL method call. e.g: type UserType.connection_type, null: true
def resolve(**args)
[:thing]
end
end
end
SRC
-
- inspect_source(lacks_type)
-
- expect(cop.offenses.size).to eq 1
end
it 'does not add an offense for resolvers that have a type call' do
@@ -41,9 +36,10 @@ RSpec.describe RuboCop::Cop::Graphql::ResolverType do
end
it 'ignores type calls on other objects' do
- lacks_type = <<-SRC
+ expect_offense(<<~SRC)
module Resolvers
class FooResolver < BaseResolver
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Missing type annotation: Please add `type` DSL method call. e.g: type UserType.connection_type, null: true
class FalsePositive < BaseObject
type RedHerringType, null: true
end
@@ -54,10 +50,6 @@ RSpec.describe RuboCop::Cop::Graphql::ResolverType do
end
end
SRC
-
- inspect_source(lacks_type)
-
- expect(cop.offenses.size).to eq 1
end
it 'does not add an offense unless the class is named using the Resolver convention' do