Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
0f1936d6
Commit
0f1936d6
authored
Sep 13, 2019
by
charlieablett
Committed by
Jan Provaznik
Sep 13, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add authorize types test
parent
b56ae4df
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
16 deletions
+20
-16
rubocop/cop/graphql/authorize_types.rb
rubocop/cop/graphql/authorize_types.rb
+3
-3
rubocop/graphql_helpers.rb
rubocop/graphql_helpers.rb
+0
-13
spec/rubocop/cop/graphql/authorize_types_spec.rb
spec/rubocop/cop/graphql/authorize_types_spec.rb
+17
-0
No files found.
rubocop/cop/graphql/authorize_types.rb
View file @
0f1936d6
...
...
@@ -7,12 +7,12 @@ module RuboCop
MSG
=
'Add an `authorize :ability` call to the type: '
\
'https://docs.gitlab.com/ee/development/api_graphql_styleguide.html#type-authorization'
TYPES_DIR
=
'app/graphql/types'
# We want to exclude our own basetypes and scalars
WHITELISTED_TYPES
=
%w[BaseEnum BaseScalar BasePermissionType MutationType
QueryType GraphQL::Schema BaseUnion]
.
freeze
TYPES_DIR
=
'app/graphql/types'
def_node_search
:authorize?
,
<<~
PATTERN
(send nil? :authorize ...)
PATTERN
...
...
@@ -30,7 +30,7 @@ module RuboCop
def
in_type?
(
node
)
path
=
node
.
location
.
expression
.
source_buffer
.
name
path
.
include?
(
TYPES_DIR
)
path
.
include?
TYPES_DIR
end
def
whitelisted?
(
class_node
)
...
...
rubocop/graphql_helpers.rb
deleted
100644 → 0
View file @
b56ae4df
# frozen_string_literal: true
module
RuboCop
module
GraphqlHelpers
TYPES_DIR
=
'app/graphql/types'
def
in_type?
(
node
)
path
=
node
.
location
.
expression
.
source_buffer
.
name
path
.
include?
(
TYPES_DIR
)
end
end
end
spec/rubocop/cop/graphql/authorize_types_spec.rb
View file @
0f1936d6
...
...
@@ -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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment