summaryrefslogtreecommitdiff
path: root/spec/rubocop
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-09-13 13:26:31 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-09-13 13:26:31 +0000
commitb7dfe2ae4054aa40e15182fd3c6cb7dd39f131db (patch)
tree5ab080ca9cadeb6cd9578bf301e4e9e8810bed9e /spec/rubocop
parent25cb337cf12438169f1b14bc5dace8a06a7356e3 (diff)
downloadgitlab-ce-b7dfe2ae4054aa40e15182fd3c6cb7dd39f131db.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/rubocop')
-rw-r--r--spec/rubocop/cop/graphql/authorize_types_spec.rb17
-rw-r--r--spec/rubocop/cop/graphql/descriptions_spec.rb75
2 files changed, 92 insertions, 0 deletions
diff --git a/spec/rubocop/cop/graphql/authorize_types_spec.rb b/spec/rubocop/cop/graphql/authorize_types_spec.rb
index eae3e176d64..af4315ecd34 100644
--- a/spec/rubocop/cop/graphql/authorize_types_spec.rb
+++ b/spec/rubocop/cop/graphql/authorize_types_spec.rb
@@ -11,6 +11,23 @@ describe RuboCop::Cop::Graphql::AuthorizeTypes do
subject(:cop) { described_class.new }
+ context 'when NOT in a type folder' do
+ before do
+ allow(cop).to receive(:in_type?).and_return(false)
+ end
+
+ it 'does not add an offense even though there is no authorize call' do
+ expect_no_offenses(<<~TYPE.strip)
+ module Types
+ class AType < BaseObject
+ field :a_thing
+ field :another_thing
+ end
+ end
+ TYPE
+ end
+ end
+
context 'when in a type folder' do
before do
allow(cop).to receive(:in_type?).and_return(true)
diff --git a/spec/rubocop/cop/graphql/descriptions_spec.rb b/spec/rubocop/cop/graphql/descriptions_spec.rb
new file mode 100644
index 00000000000..8cfdc05172d
--- /dev/null
+++ b/spec/rubocop/cop/graphql/descriptions_spec.rb
@@ -0,0 +1,75 @@
+# frozen_string_literal: true
+
+require 'fast_spec_helper'
+require 'rubocop'
+require 'rubocop/rspec/support'
+require_relative '../../../../rubocop/cop/graphql/descriptions'
+
+describe RuboCop::Cop::Graphql::Descriptions do
+ include RuboCop::RSpec::ExpectOffense
+ include CopHelper
+
+ subject(:cop) { described_class.new }
+
+ context 'fields' do
+ it 'adds an offense when there is no field description' do
+ inspect_source(<<~TYPE)
+ module Types
+ class FakeType < BaseObject
+ field :a_thing,
+ GraphQL::STRING_TYPE,
+ null: false
+ end
+ end
+ TYPE
+
+ expect(cop.offenses.size).to eq 1
+ end
+
+ it 'does not add an offense for fields with a description' do
+ expect_no_offenses(<<~TYPE.strip)
+ module Types
+ class FakeType < BaseObject
+ graphql_name 'FakeTypeName'
+
+ argument :a_thing,
+ GraphQL::STRING_TYPE,
+ null: false,
+ description: 'A descriptive description'
+ end
+ end
+ TYPE
+ end
+ end
+
+ context 'arguments' do
+ it 'adds an offense when there is no argument description' do
+ inspect_source(<<~TYPE)
+ module Types
+ class FakeType < BaseObject
+ argument :a_thing,
+ GraphQL::STRING_TYPE,
+ null: false
+ end
+ end
+ TYPE
+
+ expect(cop.offenses.size).to eq 1
+ end
+
+ it 'does not add an offense for arguments with a description' do
+ expect_no_offenses(<<~TYPE.strip)
+ module Types
+ class FakeType < BaseObject
+ graphql_name 'FakeTypeName'
+
+ argument :a_thing,
+ GraphQL::STRING_TYPE,
+ null: false,
+ description: 'Behold! A description'
+ end
+ end
+ TYPE
+ end
+ end
+end