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
Show 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
...
@@ -132,7 +132,7 @@ RSpec.describe API::Snippets, factory_default: :keep do
end
end
describe
'GET /snippets/:id/files/:ref/:file_path/raw'
do
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
it_behaves_like
'raw snippet files'
do
let
(
:api_path
)
{
"/snippets/
#{
snippet_id
}
/files/
#{
ref
}
/
#{
file_path
}
/raw"
}
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
# frozen_string_literal: true
RSpec
.
shared_examples
'raw snippet files'
do
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
(
:snippet_id
)
{
snippet
.
id
}
let
(
:user
)
{
snippet
.
author
}
let
(
:user
)
{
snippet
.
author
}
let
(
:file_path
)
{
'%2Egitattributes'
}
let
(
:file_path
)
{
'%2Egitattributes'
}
let
(
:ref
)
{
'master'
}
let
(
:ref
)
{
'master'
}
subject
{
get
api
(
api_path
,
personal_access_token:
user_token
)
}
context
'with an invalid snippet ID'
do
context
'with an invalid snippet ID'
do
let
(
:snippet_id
)
{
'invalid'
}
let
(
:snippet_id
)
{
non_existing_record_id
}
it
'returns 404'
do
it
'returns 404'
do
get
api
(
api_path
,
user
)
subject
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
expect
(
json_response
[
'message'
]).
to
eq
(
'404 Snippet Not Found'
)
expect
(
json_response
[
'message'
]).
to
eq
(
'404 Snippet Not Found'
)
...
@@ -22,7 +24,7 @@ RSpec.shared_examples 'raw snippet files' do
...
@@ -22,7 +24,7 @@ RSpec.shared_examples 'raw snippet files' do
it
'returns the raw file info'
do
it
'returns the raw file info'
do
expect
(
Gitlab
::
Workhorse
).
to
receive
(
:send_git_blob
).
and_call_original
expect
(
Gitlab
::
Workhorse
).
to
receive
(
:send_git_blob
).
and_call_original
get
api
(
api_path
,
user
)
subject
aggregate_failures
do
aggregate_failures
do
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
...
@@ -34,6 +36,17 @@ RSpec.shared_examples 'raw snippet files' do
...
@@ -34,6 +36,17 @@ RSpec.shared_examples 'raw snippet files' do
end
end
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
context
'with invalid params'
do
using
RSpec
::
Parameterized
::
TableSyntax
using
RSpec
::
Parameterized
::
TableSyntax
...
@@ -50,12 +63,12 @@ RSpec.shared_examples 'raw snippet files' do
...
@@ -50,12 +63,12 @@ RSpec.shared_examples 'raw snippet files' do
end
end
with_them
do
with_them
do
before
do
it
'returns the proper response code and message'
do
get
api
(
api_path
,
user
)
subject
end
it
{
expect
(
response
).
to
have_gitlab_http_status
(
status
)
}
expect
(
response
).
to
have_gitlab_http_status
(
status
)
it
{
expect
(
json_response
[
key
]).
to
eq
(
message
)
}
expect
(
json_response
[
key
]).
to
eq
(
message
)
end
end
end
end
end
end
end
...
@@ -256,7 +269,7 @@ end
...
@@ -256,7 +269,7 @@ end
RSpec
.
shared_examples
'expected response status'
do
RSpec
.
shared_examples
'expected response status'
do
it
'returns the correct response'
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
)
expect
(
response
).
to
have_gitlab_http_status
(
status
)
end
end
...
@@ -265,7 +278,7 @@ end
...
@@ -265,7 +278,7 @@ end
RSpec
.
shared_examples
'unauthenticated project snippet access'
do
RSpec
.
shared_examples
'unauthenticated project snippet access'
do
using
RSpec
::
Parameterized
::
TableSyntax
using
RSpec
::
Parameterized
::
TableSyntax
let
(
:user
)
{
nil
}
let
(
:user
_token
)
{
nil
}
where
(
:project_visibility
,
:snippet_visibility
,
:status
)
do
where
(
:project_visibility
,
:snippet_visibility
,
:status
)
do
:public
|
:public
|
:ok
:public
|
:public
|
:ok
...
@@ -317,6 +330,8 @@ RSpec.shared_examples 'member project snippet access' do
...
@@ -317,6 +330,8 @@ RSpec.shared_examples 'member project snippet access' do
end
end
RSpec
.
shared_examples
'project snippet access levels'
do
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
(
:project
)
{
create
(
:project
,
project_visibility
)
}
let
(
:snippet
)
{
create
(
:project_snippet
,
:repository
,
snippet_visibility
,
project:
project
)
}
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