diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
commit | 48aff82709769b098321c738f3444b9bdaa694c6 (patch) | |
tree | e00c7c43e2d9b603a5a6af576b1685e400410dee /spec/rubocop/cop/graphql | |
parent | 879f5329ee916a948223f8f43d77fba4da6cd028 (diff) |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc42
Diffstat (limited to 'spec/rubocop/cop/graphql')
-rw-r--r-- | spec/rubocop/cop/graphql/gid_expected_type_spec.rb | 26 | ||||
-rw-r--r-- | spec/rubocop/cop/graphql/id_type_spec.rb | 36 |
2 files changed, 62 insertions, 0 deletions
diff --git a/spec/rubocop/cop/graphql/gid_expected_type_spec.rb b/spec/rubocop/cop/graphql/gid_expected_type_spec.rb new file mode 100644 index 00000000000..a81af2aea5d --- /dev/null +++ b/spec/rubocop/cop/graphql/gid_expected_type_spec.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require 'fast_spec_helper' +require 'rubocop' + +require_relative '../../../../rubocop/cop/graphql/gid_expected_type' + +RSpec.describe RuboCop::Cop::Graphql::GIDExpectedType, type: :rubocop do + include CopHelper + + subject(:cop) { described_class.new } + + it 'adds an offense when there is no expected_type parameter' do + inspect_source(<<~TYPE) + GitlabSchema.object_from_id(received_id) + TYPE + + expect(cop.offenses.size).to eq 1 + end + + it 'does not add an offense for calls that have an expected_type parameter' do + expect_no_offenses(<<~TYPE.strip) + GitlabSchema.object_from_id("some_id", expected_type: SomeClass) + TYPE + end +end diff --git a/spec/rubocop/cop/graphql/id_type_spec.rb b/spec/rubocop/cop/graphql/id_type_spec.rb new file mode 100644 index 00000000000..8767412e282 --- /dev/null +++ b/spec/rubocop/cop/graphql/id_type_spec.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +require 'fast_spec_helper' +require 'rubocop' + +require_relative '../../../../rubocop/cop/graphql/id_type' + +RSpec.describe RuboCop::Cop::Graphql::IDType, type: :rubocop 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) + argument :some_arg, GraphQL::ID_TYPE, some: other, params: do_not_matter + TYPE + + expect(cop.offenses.size).to eq 1 + end + + context 'whitelisted arguments' do + RuboCop::Cop::Graphql::IDType::WHITELISTED_ARGUMENTS.each do |arg| + it "does not add an offense for calls to #argument with #{arg} as argument name" do + expect_no_offenses(<<~TYPE.strip) + argument #{arg}, GraphQL::ID_TYPE, some: other, params: do_not_matter + TYPE + end + end + end + + it 'does not add an offense for calls to #argument without GraphQL::ID_TYPE' do + expect_no_offenses(<<~TYPE.strip) + argument :some_arg, ::Types::GlobalIDType[::Awardable], some: other, params: do_not_matter + TYPE + end +end |