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-08-20 21:42:06 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-08-20 21:42:06 +0300
commit6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch)
tree78be5963ec075d80116a932011d695dd33910b4e /spec/rubocop/cop/graphql
parent1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff)
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/rubocop/cop/graphql')
-rw-r--r--spec/rubocop/cop/graphql/json_type_spec.rb79
1 files changed, 79 insertions, 0 deletions
diff --git a/spec/rubocop/cop/graphql/json_type_spec.rb b/spec/rubocop/cop/graphql/json_type_spec.rb
new file mode 100644
index 00000000000..ac25e0feb69
--- /dev/null
+++ b/spec/rubocop/cop/graphql/json_type_spec.rb
@@ -0,0 +1,79 @@
+# frozen_string_literal: true
+
+require 'fast_spec_helper'
+require 'rubocop'
+require_relative '../../../../rubocop/cop/graphql/json_type'
+
+RSpec.describe RuboCop::Cop::Graphql::JSONType, type: :rubocop do
+ include CopHelper
+
+ subject(:cop) { described_class.new }
+
+ context 'fields' do
+ it 'adds an offense when GraphQL::Types::JSON is used' do
+ inspect_source(<<~RUBY.strip)
+ class MyType
+ field :some_field, GraphQL::Types::JSON
+ 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)
+ class MyType
+ field :some_field, GraphQL::Types::JSON, null: true, description: 'My description'
+ end
+ RUBY
+
+ expect(cop.offenses.size).to eq(1)
+ end
+
+ it 'does not add an offense for other types' do
+ expect_no_offenses(<<~RUBY.strip)
+ class MyType
+ field :some_field, GraphQL::STRING_TYPE
+ end
+ RUBY
+ end
+ end
+
+ context 'arguments' do
+ it 'adds an offense when GraphQL::Types::JSON is used' do
+ inspect_source(<<~RUBY.strip)
+ class MyType
+ argument :some_arg, GraphQL::Types::JSON
+ 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)
+ class MyType
+ argument :some_arg, GraphQL::Types::JSON, null: true, description: 'My description'
+ end
+ RUBY
+
+ expect(cop.offenses.size).to eq(1)
+ end
+
+ it 'does not add an offense for other types' do
+ expect_no_offenses(<<~RUBY.strip)
+ class MyType
+ argument :some_arg, GraphQL::STRING_TYPE
+ end
+ RUBY
+ end
+ end
+
+ it 'does not add an offense for uses outside of field or argument' do
+ expect_no_offenses(<<~RUBY.strip)
+ class MyType
+ foo :some_field, GraphQL::Types::JSON
+ end
+ RUBY
+ end
+end