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>2020-11-19 11:27:35 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-11-19 11:27:35 +0300
commit7e9c479f7de77702622631cff2628a9c8dcbc627 (patch)
treec8f718a08e110ad7e1894510980d2155a6549197 /spec/rubocop/cop/graphql/resolver_type_spec.rb
parente852b0ae16db4052c1c567d9efa4facc81146e88 (diff)
Add latest changes from gitlab-org/gitlab@13-6-stable-eev13.6.0-rc42
Diffstat (limited to 'spec/rubocop/cop/graphql/resolver_type_spec.rb')
-rw-r--r--spec/rubocop/cop/graphql/resolver_type_spec.rb74
1 files changed, 74 insertions, 0 deletions
diff --git a/spec/rubocop/cop/graphql/resolver_type_spec.rb b/spec/rubocop/cop/graphql/resolver_type_spec.rb
new file mode 100644
index 00000000000..4807d66396a
--- /dev/null
+++ b/spec/rubocop/cop/graphql/resolver_type_spec.rb
@@ -0,0 +1,74 @@
+# frozen_string_literal: true
+
+require 'fast_spec_helper'
+require 'rubocop'
+
+require_relative '../../../../rubocop/cop/graphql/resolver_type'
+
+RSpec.describe RuboCop::Cop::Graphql::ResolverType, type: :rubocop do
+ include CopHelper
+
+ subject(:cop) { described_class.new }
+
+ it 'adds an offense when there is no type annotaion' do
+ lacks_type = <<-SRC
+ module Resolvers
+ class FooResolver < BaseResolver
+ 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
+ expect_no_offenses(<<-SRC)
+ module Resolvers
+ class FooResolver < BaseResolver
+ type [SomeEnum], null: true
+
+ def resolve(**args)
+ [:thing]
+ end
+ end
+ end
+ SRC
+ end
+
+ it 'ignores type calls on other objects' do
+ lacks_type = <<-SRC
+ module Resolvers
+ class FooResolver < BaseResolver
+ class FalsePositive < BaseObject
+ type RedHerringType, null: true
+ end
+
+ 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 unless the class is named using the Resolver convention' do
+ expect_no_offenses(<<-TYPE)
+ module Resolvers
+ class FooThingy
+ def something_other_than_resolve(**args)
+ [:thing]
+ end
+ end
+ end
+ TYPE
+ end
+end