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
3ca064ee
Commit
3ca064ee
authored
Oct 13, 2016
by
Semyon Pupkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add missing tests for download snippet
ref:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/6720
parent
21e3712a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
83 additions
and
73 deletions
+83
-73
spec/controllers/snippets_controller_spec.rb
spec/controllers/snippets_controller_spec.rb
+83
-73
No files found.
spec/controllers/snippets_controller_spec.rb
View file @
3ca064ee
...
@@ -116,116 +116,126 @@ describe SnippetsController do
...
@@ -116,116 +116,126 @@ describe SnippetsController do
end
end
end
end
describe
'GET #raw'
do
%w(raw download)
.
each
do
|
action
|
let
(
:user
)
{
create
(
:user
)
}
describe
"GET
#{
action
}
"
do
context
'when the personal snippet is private'
do
let
(
:personal_snippet
)
{
create
(
:personal_snippet
,
:private
,
author:
user
)
}
context
'when signed in'
do
before
do
sign_in
(
user
)
end
context
'when the personal snippet is private'
do
context
'when signed in user is not the author'
do
let
(
:personal_snippet
)
{
create
(
:personal_snippet
,
:private
,
author:
user
)
}
let
(
:other_author
)
{
create
(
:author
)
}
let
(
:other_personal_snippet
)
{
create
(
:personal_snippet
,
:private
,
author:
other_author
)
}
context
'when signed in'
do
it
'responds with status 404'
do
before
do
get
action
,
id:
other_personal_snippet
.
to_param
sign_in
(
user
)
end
context
'when signed in user is not the author'
do
expect
(
response
).
to
have_http_status
(
404
)
let
(
:other_author
)
{
create
(
:author
)
}
end
let
(
:other_personal_snippet
)
{
create
(
:personal_snippet
,
:private
,
author:
other_author
)
}
end
it
'responds with status 404
'
do
context
'when signed in user is the author
'
do
get
:raw
,
id:
other_personal_snippet
.
to_param
before
{
get
action
,
id:
personal_snippet
.
to_param
}
expect
(
response
).
to
have_http_status
(
404
)
it
'responds with status 200'
do
end
expect
(
assigns
(
:snippet
)).
to
eq
(
personal_snippet
)
end
expect
(
response
).
to
have_http_status
(
200
)
end
context
'when signed in user is the author'
do
it
'has expected headers'
do
it
'renders the raw snippet'
do
expect
(
response
.
header
[
'Content-Type'
]).
to
eq
(
'text/plain; charset=utf-8'
)
get
:raw
,
id:
personal_snippet
.
to_param
expect
(
assigns
(
:snippet
)).
to
eq
(
personal_snippet
)
if
action
==
:download
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
.
header
[
'Content-Disposition'
]).
to
match
(
/attachment/
)
elsif
action
==
:raw
expect
(
response
.
header
[
'Content-Disposition'
]).
to
match
(
/inline/
)
end
end
end
end
end
end
end
context
'when not signed in'
do
context
'when not signed in'
do
it
'redirects to the sign in page'
do
it
'redirects to the sign in page'
do
get
:raw
,
id:
personal_snippet
.
to_param
get
action
,
id:
personal_snippet
.
to_param
expect
(
response
).
to
redirect_to
(
new_user_session_path
)
expect
(
response
).
to
redirect_to
(
new_user_session_path
)
end
end
end
end
end
end
context
'when the personal snippet is internal'
do
context
'when the personal snippet is internal'
do
let
(
:personal_snippet
)
{
create
(
:personal_snippet
,
:internal
,
author:
user
)
}
let
(
:personal_snippet
)
{
create
(
:personal_snippet
,
:internal
,
author:
user
)
}
context
'when signed in'
do
context
'when signed in'
do
before
do
before
do
sign_in
(
user
)
sign_in
(
user
)
end
end
it
'renders the raw snippet
'
do
it
'responds with status 200
'
do
get
:raw
,
id:
personal_snippet
.
to_param
get
action
,
id:
personal_snippet
.
to_param
expect
(
assigns
(
:snippet
)).
to
eq
(
personal_snippet
)
expect
(
assigns
(
:snippet
)).
to
eq
(
personal_snippet
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
end
end
context
'when not signed in'
do
context
'when not signed in'
do
it
'redirects to the sign in page'
do
it
'redirects to the sign in page'
do
get
:raw
,
id:
personal_snippet
.
to_param
get
action
,
id:
personal_snippet
.
to_param
expect
(
response
).
to
redirect_to
(
new_user_session_path
)
expect
(
response
).
to
redirect_to
(
new_user_session_path
)
end
end
end
end
end
end
context
'when the personal snippet is public'
do
context
'when the personal snippet is public'
do
let
(
:personal_snippet
)
{
create
(
:personal_snippet
,
:public
,
author:
user
)
}
let
(
:personal_snippet
)
{
create
(
:personal_snippet
,
:public
,
author:
user
)
}
context
'when signed in'
do
context
'when signed in'
do
before
do
before
do
sign_in
(
user
)
sign_in
(
user
)
end
end
it
'renders the raw snippet
'
do
it
'responds with status 200
'
do
get
:raw
,
id:
personal_snippet
.
to_param
get
action
,
id:
personal_snippet
.
to_param
expect
(
assigns
(
:snippet
)).
to
eq
(
personal_snippet
)
expect
(
assigns
(
:snippet
)).
to
eq
(
personal_snippet
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
end
end
context
'when not signed in'
do
context
'when not signed in'
do
it
'renders the raw snippet
'
do
it
'responds with status 200
'
do
get
:raw
,
id:
personal_snippet
.
to_param
get
action
,
id:
personal_snippet
.
to_param
expect
(
assigns
(
:snippet
)).
to
eq
(
personal_snippet
)
expect
(
assigns
(
:snippet
)).
to
eq
(
personal_snippet
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
end
end
end
end
context
'when the personal snippet does not exist'
do
context
'when the personal snippet does not exist'
do
context
'when signed in'
do
context
'when signed in'
do
before
do
before
do
sign_in
(
user
)
sign_in
(
user
)
end
end
it
'responds with status 404'
do
it
'responds with status 404'
do
get
:raw
,
id:
'doesntexist'
get
action
,
id:
'doesntexist'
expect
(
response
).
to
have_http_status
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
end
context
'when not signed in'
do
context
'when not signed in'
do
it
'responds with status 404'
do
it
'responds with status 404'
do
get
:raw
,
id:
'doesntexist'
get
action
,
id:
'doesntexist'
expect
(
response
).
to
have_http_status
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
end
end
end
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