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
7f6362a2
Commit
7f6362a2
authored
Sep 11, 2020
by
Francisco Javier López
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve performance of project snippet controller spec
parent
d900a29c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
30 deletions
+24
-30
spec/controllers/projects/snippets_controller_spec.rb
spec/controllers/projects/snippets_controller_spec.rb
+24
-30
No files found.
spec/controllers/projects/snippets_controller_spec.rb
View file @
7f6362a2
...
...
@@ -6,12 +6,12 @@ RSpec.describe Projects::SnippetsController do
include
Gitlab
::
Routing
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:
user2
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project_empty_repo
,
:public
)
}
let_it_be
(
:
other_user
)
{
create
(
:user
)
}
let
_it_be
(
:project
)
{
create
(
:project_empty_repo
,
:public
)
}
before
do
project
.
add_maintainer
(
user
)
project
.
add_
maintainer
(
user2
)
project
.
add_
developer
(
other_user
)
end
describe
'GET #index'
do
...
...
@@ -47,7 +47,7 @@ RSpec.describe Projects::SnippetsController do
end
context
'when the project snippet is private'
do
let
!
(
:project_snippet
)
{
create
(
:project_snippet
,
:private
,
project:
project
,
author:
user
)
}
let
_it_be
(
:project_snippet
)
{
create
(
:project_snippet
,
:private
,
project:
project
,
author:
user
)
}
context
'when anonymous'
do
it
'does not include the private snippet'
do
...
...
@@ -59,11 +59,9 @@ RSpec.describe Projects::SnippetsController do
end
context
'when signed in as the author'
do
before
do
it
'renders the snippet'
do
sign_in
(
user
)
end
it
'renders the snippet'
do
subject
expect
(
assigns
(
:snippets
)).
to
include
(
project_snippet
)
...
...
@@ -72,11 +70,9 @@ RSpec.describe Projects::SnippetsController do
end
context
'when signed in as a project member'
do
before
do
sign_in
(
user2
)
end
it
'renders the snippet'
do
sign_in
(
other_user
)
subject
expect
(
assigns
(
:snippets
)).
to
include
(
project_snippet
)
...
...
@@ -171,7 +167,6 @@ RSpec.describe Projects::SnippetsController do
end
describe
'PUT #update'
do
let
(
:project
)
{
create
:project
,
:public
}
let
(
:visibility_level
)
{
Snippet
::
PUBLIC
}
let
(
:snippet
)
{
create
:project_snippet
,
author:
user
,
project:
project
,
visibility_level:
visibility_level
}
...
...
@@ -297,7 +292,7 @@ RSpec.describe Projects::SnippetsController do
end
describe
'POST #mark_as_spam'
do
let
(
:snippet
)
{
create
(
:project_snippet
,
:private
,
project:
project
,
author:
user
)
}
let
_it_be
(
:snippet
)
{
create
(
:project_snippet
,
:private
,
project:
project
,
author:
user
)
}
before
do
allow_next_instance_of
(
Spam
::
AkismetService
)
do
|
instance
|
...
...
@@ -345,7 +340,7 @@ RSpec.describe Projects::SnippetsController do
%w[show raw]
.
each
do
|
action
|
describe
"GET #
#{
action
}
"
do
context
'when the project snippet is private'
do
let
(
:project_snippet
)
{
create
(
:project_snippet
,
:private
,
:repository
,
project:
project
,
author:
user
)
}
let
_it_be
(
:project_snippet
)
{
create
(
:project_snippet
,
:private
,
:repository
,
project:
project
,
author:
user
)
}
subject
{
get
action
,
params:
{
namespace_id:
project
.
namespace
,
project_id:
project
,
id:
project_snippet
.
to_param
}
}
...
...
@@ -367,7 +362,7 @@ RSpec.describe Projects::SnippetsController do
context
'when signed in as a project member'
do
before
do
sign_in
(
user2
)
sign_in
(
other_user
)
end
it_behaves_like
'successful response'
...
...
@@ -480,9 +475,8 @@ RSpec.describe Projects::SnippetsController do
subject
{
get
:raw
,
params:
params
}
context
'when repository is empty'
do
let
(
:content
)
{
"first line
\r\n
second line
\r\n
third line"
}
let
(
:formatted_content
)
{
content
.
gsub
(
/\r\n/
,
"
\n
"
)
}
let
(
:project_snippet
)
do
let_it_be
(
:content
)
{
"first line
\r\n
second line
\r\n
third line"
}
let_it_be
(
:project_snippet
)
do
create
(
:project_snippet
,
:public
,
:empty_repo
,
project:
project
,
...
...
@@ -491,6 +485,8 @@ RSpec.describe Projects::SnippetsController do
)
end
let
(
:formatted_content
)
{
content
.
gsub
(
/\r\n/
,
"
\n
"
)
}
context
'CRLF line ending'
do
before
do
allow_next_instance_of
(
Blob
)
do
|
instance
|
...
...
@@ -517,7 +513,7 @@ RSpec.describe Projects::SnippetsController do
end
context
'when repository is not empty'
do
let
(
:project_snippet
)
do
let
_it_be
(
:project_snippet
)
do
create
(
:project_snippet
,
:public
,
:repository
,
project:
project
,
...
...
@@ -539,7 +535,7 @@ RSpec.describe Projects::SnippetsController do
end
describe
'DELETE #destroy'
do
let
!
(
:snippet
)
{
create
(
:project_snippet
,
:private
,
project:
project
,
author:
user
)
}
let
_it_be
(
:snippet
)
{
create
(
:project_snippet
,
:private
,
project:
project
,
author:
user
)
}
let
(
:params
)
do
{
...
...
@@ -549,20 +545,22 @@ RSpec.describe Projects::SnippetsController do
}
end
subject
{
delete
:destroy
,
params:
params
}
context
'when current user has ability to destroy the snippet'
do
before
do
sign_in
(
user
)
end
it
'removes the snippet'
do
delete
:destroy
,
params:
params
subject
expect
{
snippet
.
reload
}.
to
raise_error
(
ActiveRecord
::
RecordNotFound
)
end
context
'when snippet is succesfuly destroyed'
do
it
'redirects to the project snippets page'
do
delete
:destroy
,
params:
params
subject
expect
(
response
).
to
redirect_to
(
project_snippets_path
(
project
))
end
...
...
@@ -575,7 +573,7 @@ RSpec.describe Projects::SnippetsController do
end
it
'renders the snippet page with errors'
do
delete
:destroy
,
params:
params
subject
expect
(
flash
[
:alert
]).
to
eq
(
'Failed to remove snippet.'
)
expect
(
response
).
to
redirect_to
(
project_snippet_path
(
project
,
snippet
))
...
...
@@ -584,14 +582,10 @@ RSpec.describe Projects::SnippetsController do
end
context
'when current_user does not have ability to destroy the snippet'
do
let
(
:another_user
)
{
create
(
:user
)
}
before
do
sign_in
(
another_user
)
end
it
'responds with status 404'
do
delete
:destroy
,
params:
params
sign_in
(
other_user
)
subject
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
...
...
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