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
263f4247
Commit
263f4247
authored
Oct 14, 2020
by
fjsanpedro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve requests/api/project_snippets_spec performance
parent
934bbceb
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
72 deletions
+79
-72
spec/requests/api/project_snippets_spec.rb
spec/requests/api/project_snippets_spec.rb
+52
-60
spec/requests/api/snippets_spec.rb
spec/requests/api/snippets_spec.rb
+1
-1
spec/support/shared_examples/requests/api/snippets_shared_examples.rb
.../shared_examples/requests/api/snippets_shared_examples.rb
+26
-11
No files found.
spec/requests/api/project_snippets_spec.rb
View file @
263f4247
This diff is collapsed.
Click to expand it.
spec/requests/api/snippets_spec.rb
View file @
263f4247
...
...
@@ -132,7 +132,7 @@ RSpec.describe API::Snippets, factory_default: :keep do
end
describe
'GET /snippets/:id/files/:ref/:file_path/raw'
do
let
(
:snippet
)
{
private_snippet
}
let
_it_be
(
:snippet
)
{
private_snippet
}
it_behaves_like
'raw snippet files'
do
let
(
:api_path
)
{
"/snippets/
#{
snippet_id
}
/files/
#{
ref
}
/
#{
file_path
}
/raw"
}
...
...
spec/support/shared_examples/requests/api/snippets_shared_examples.rb
View file @
263f4247
# frozen_string_literal: true
RSpec
.
shared_examples
'raw snippet files'
do
let_it_be
(
:u
nauthorized_user
)
{
create
(
:use
r
)
}
let_it_be
(
:u
ser_token
)
{
create
(
:personal_access_token
,
user:
snippet
.
autho
r
)
}
let
(
:snippet_id
)
{
snippet
.
id
}
let
(
:user
)
{
snippet
.
author
}
let
(
:file_path
)
{
'%2Egitattributes'
}
let
(
:ref
)
{
'master'
}
subject
{
get
api
(
api_path
,
personal_access_token:
user_token
)
}
context
'with an invalid snippet ID'
do
let
(
:snippet_id
)
{
'invalid'
}
let
(
:snippet_id
)
{
non_existing_record_id
}
it
'returns 404'
do
get
api
(
api_path
,
user
)
subject
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
expect
(
json_response
[
'message'
]).
to
eq
(
'404 Snippet Not Found'
)
...
...
@@ -22,7 +24,7 @@ RSpec.shared_examples 'raw snippet files' do
it
'returns the raw file info'
do
expect
(
Gitlab
::
Workhorse
).
to
receive
(
:send_git_blob
).
and_call_original
get
api
(
api_path
,
user
)
subject
aggregate_failures
do
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
...
...
@@ -34,6 +36,17 @@ RSpec.shared_examples 'raw snippet files' do
end
end
context
'with unauthorized user'
do
let
(
:user_token
)
{
create
(
:personal_access_token
)
}
it
'returns 404'
do
subject
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
expect
(
json_response
[
'message'
]).
to
eq
(
'404 Snippet Not Found'
)
end
end
context
'with invalid params'
do
using
RSpec
::
Parameterized
::
TableSyntax
...
...
@@ -50,12 +63,12 @@ RSpec.shared_examples 'raw snippet files' do
end
with_them
do
before
do
get
api
(
api_path
,
user
)
end
it
'returns the proper response code and message'
do
subject
it
{
expect
(
response
).
to
have_gitlab_http_status
(
status
)
}
it
{
expect
(
json_response
[
key
]).
to
eq
(
message
)
}
expect
(
response
).
to
have_gitlab_http_status
(
status
)
expect
(
json_response
[
key
]).
to
eq
(
message
)
end
end
end
end
...
...
@@ -256,7 +269,7 @@ end
RSpec
.
shared_examples
'expected response status'
do
it
'returns the correct response'
do
get
api
(
path
,
user
)
get
api
(
path
,
personal_access_token:
user_token
)
expect
(
response
).
to
have_gitlab_http_status
(
status
)
end
...
...
@@ -265,7 +278,7 @@ end
RSpec
.
shared_examples
'unauthenticated project snippet access'
do
using
RSpec
::
Parameterized
::
TableSyntax
let
(
:user
)
{
nil
}
let
(
:user
_token
)
{
nil
}
where
(
:project_visibility
,
:snippet_visibility
,
:status
)
do
:public
|
:public
|
:ok
...
...
@@ -317,6 +330,8 @@ RSpec.shared_examples 'member project snippet access' do
end
RSpec
.
shared_examples
'project snippet access levels'
do
let_it_be
(
:user_token
)
{
create
(
:personal_access_token
,
user:
user
)
}
let
(
:project
)
{
create
(
:project
,
project_visibility
)
}
let
(
:snippet
)
{
create
(
:project_snippet
,
:repository
,
snippet_visibility
,
project:
project
)
}
...
...
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