Fix a KeyError in GitlabSchema
This commit is contained in:
parent
465f82e32c
commit
beeeede2ee
2 changed files with 13 additions and 3 deletions
|
@ -31,7 +31,7 @@ class GitlabSchema < GraphQL::Schema
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.max_query_complexity(ctx)
|
def self.max_query_complexity(ctx)
|
||||||
current_user = ctx&.fetch(:current_user)
|
current_user = ctx&.fetch(:current_user, nil)
|
||||||
|
|
||||||
if current_user&.admin
|
if current_user&.admin
|
||||||
ADMIN_COMPLEXITY
|
ADMIN_COMPLEXITY
|
||||||
|
|
|
@ -34,12 +34,22 @@ describe GitlabSchema do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'for different types of users' do
|
context 'for different types of users' do
|
||||||
it 'returns DEFAULT_MAX_COMPLEXITY for no user' do
|
it 'returns DEFAULT_MAX_COMPLEXITY for no context' do
|
||||||
expect(GraphQL::Schema).to receive(:execute).with('query', hash_including(max_complexity: GitlabSchema::DEFAULT_MAX_COMPLEXITY))
|
expect(GraphQL::Schema)
|
||||||
|
.to receive(:execute)
|
||||||
|
.with('query', hash_including(max_complexity: GitlabSchema::DEFAULT_MAX_COMPLEXITY))
|
||||||
|
|
||||||
described_class.execute('query')
|
described_class.execute('query')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'returns DEFAULT_MAX_COMPLEXITY for no user' do
|
||||||
|
expect(GraphQL::Schema)
|
||||||
|
.to receive(:execute)
|
||||||
|
.with('query', hash_including(max_complexity: GitlabSchema::DEFAULT_MAX_COMPLEXITY))
|
||||||
|
|
||||||
|
described_class.execute('query', context: {})
|
||||||
|
end
|
||||||
|
|
||||||
it 'returns AUTHENTICATED_COMPLEXITY for a logged in user' do
|
it 'returns AUTHENTICATED_COMPLEXITY for a logged in user' do
|
||||||
user = build :user
|
user = build :user
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue