BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
0349e83a
Commit
0349e83a
authored
Dec 20, 2016
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve specs for Files API
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
5652da8b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
34 deletions
+61
-34
files_spec.rb
spec/requests/api/files_spec.rb
+51
-23
repositories_spec.rb
spec/requests/api/repositories_spec.rb
+0
-11
repositories_shared_context.rb
spec/support/api/repositories_shared_context.rb
+10
-0
No files found.
spec/requests/api/files_spec.rb
View file @
0349e83a
...
@@ -4,7 +4,14 @@ describe API::Files, api: true do
...
@@ -4,7 +4,14 @@ describe API::Files, api: true do
include
ApiHelpers
include
ApiHelpers
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let!
(
:project
)
{
create
(
:project
,
namespace:
user
.
namespace
)
}
let!
(
:project
)
{
create
(
:project
,
namespace:
user
.
namespace
)
}
let
(
:guest
)
{
create
(
:user
).
tap
{
|
u
|
create
(
:project_member
,
:guest
,
user:
u
,
project:
project
)
}
}
let
(
:file_path
)
{
'files/ruby/popen.rb'
}
let
(
:file_path
)
{
'files/ruby/popen.rb'
}
let
(
:params
)
do
{
file_path:
file_path
,
ref:
'master'
}
end
let
(
:author_email
)
{
FFaker
::
Internet
.
email
}
let
(
:author_email
)
{
FFaker
::
Internet
.
email
}
# I have to remove periods from the end of the name
# I have to remove periods from the end of the name
...
@@ -24,14 +31,11 @@ describe API::Files, api: true do
...
@@ -24,14 +31,11 @@ describe API::Files, api: true do
before
{
project
.
team
<<
[
user
,
:developer
]
}
before
{
project
.
team
<<
[
user
,
:developer
]
}
describe
"GET /projects/:id/repository/files"
do
describe
"GET /projects/:id/repository/files"
do
let
(
:route
)
{
"/projects/
#{
project
.
id
}
/repository/files"
}
shared_examples_for
'repository files'
do
shared_examples_for
'repository files'
do
it
"returns file info"
do
it
"returns file info"
do
params
=
{
get
api
(
route
,
current_user
),
params
file_path:
file_path
,
ref:
'master'
,
}
get
api
(
"/projects/
#{
project
.
id
}
/repository/files"
,
current_user
),
params
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'file_path'
]).
to
eq
(
file_path
)
expect
(
json_response
[
'file_path'
]).
to
eq
(
file_path
)
...
@@ -39,36 +43,60 @@ describe API::Files, api: true do
...
@@ -39,36 +43,60 @@ describe API::Files, api: true do
expect
(
json_response
[
'last_commit_id'
]).
to
eq
(
'570e7b2abdd848b95f2f578043fc23bd6f6fd24d'
)
expect
(
json_response
[
'last_commit_id'
]).
to
eq
(
'570e7b2abdd848b95f2f578043fc23bd6f6fd24d'
)
expect
(
Base64
.
decode64
(
json_response
[
'content'
]).
lines
.
first
).
to
eq
(
"require 'fileutils'
\n
"
)
expect
(
Base64
.
decode64
(
json_response
[
'content'
]).
lines
.
first
).
to
eq
(
"require 'fileutils'
\n
"
)
end
end
context
'when no params are given'
do
it_behaves_like
'400 response'
do
let
(
:request
)
{
get
api
(
route
,
current_user
)
}
end
end
context
'when file_path does not exist'
do
let
(
:params
)
do
{
file_path:
'app/models/application.rb'
,
ref:
'master'
,
}
end
it_behaves_like
'404 response'
do
let
(
:request
)
{
get
api
(
route
,
current_user
),
params
}
let
(
:message
)
{
'404 File Not Found'
}
end
end
context
'when repository is disabled'
do
include_context
'disabled repository'
it_behaves_like
'403 response'
do
let
(
:request
)
{
get
api
(
route
,
current_user
),
params
}
end
end
end
end
context
'when unauthenticated'
do
context
'when unauthenticated'
,
'and project is public'
do
it_behaves_like
'repository files'
do
it_behaves_like
'repository files'
do
let
(
:project
)
{
create
(
:project
,
:public
)
}
let
(
:project
)
{
create
(
:project
,
:public
)
}
let
(
:current_user
)
{
nil
}
let
(
:current_user
)
{
nil
}
end
end
end
end
context
'when authenticated'
do
context
'when unauthenticated'
,
'and project is private'
do
it_behaves_like
'repository files'
do
it_behaves_like
'404 response'
do
let
(
:current_user
)
{
user
}
let
(
:request
)
{
get
api
(
route
),
params
}
let
(
:message
)
{
'404 Project Not Found'
}
end
end
end
end
it
"returns a 400 bad request if no params given"
do
context
'when authenticated'
,
'as a developer'
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/files"
,
user
)
it_behaves_like
'repository files'
do
let
(
:current_user
)
{
user
}
e
xpect
(
response
).
to
have_http_status
(
400
)
e
nd
end
end
it
"returns a 404 if such file does not exist"
do
context
'when authenticated'
,
'as a guest'
do
params
=
{
it_behaves_like
'403 response'
do
file_path:
'app/models/application.rb'
,
let
(
:request
)
{
get
api
(
route
,
guest
),
params
}
ref:
'master'
,
end
}
get
api
(
"/projects/
#{
project
.
id
}
/repository/files"
,
user
),
params
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
end
...
...
spec/requests/api/repositories_spec.rb
View file @
0349e83a
...
@@ -11,17 +11,6 @@ describe API::Repositories, api: true do
...
@@ -11,17 +11,6 @@ describe API::Repositories, api: true do
let!
(
:project
)
{
create
(
:project
,
creator_id:
user
.
id
)
}
let!
(
:project
)
{
create
(
:project
,
creator_id:
user
.
id
)
}
let!
(
:master
)
{
create
(
:project_member
,
:master
,
user:
user
,
project:
project
)
}
let!
(
:master
)
{
create
(
:project_member
,
:master
,
user:
user
,
project:
project
)
}
shared_context
'disabled repository'
do
before
do
project
.
project_feature
.
update_attributes!
(
repository_access_level:
ProjectFeature
::
DISABLED
,
merge_requests_access_level:
ProjectFeature
::
DISABLED
,
builds_access_level:
ProjectFeature
::
DISABLED
)
expect
(
project
.
feature_available?
(
:repository
,
current_user
)).
to
be
false
end
end
describe
"GET /projects/:id/repository/tree"
do
describe
"GET /projects/:id/repository/tree"
do
let
(
:route
)
{
"/projects/
#{
project
.
id
}
/repository/tree"
}
let
(
:route
)
{
"/projects/
#{
project
.
id
}
/repository/tree"
}
...
...
spec/support/api/repositories_shared_context.rb
0 → 100644
View file @
0349e83a
shared_context
'disabled repository'
do
before
do
project
.
project_feature
.
update_attributes!
(
repository_access_level:
ProjectFeature
::
DISABLED
,
merge_requests_access_level:
ProjectFeature
::
DISABLED
,
builds_access_level:
ProjectFeature
::
DISABLED
)
expect
(
project
.
feature_available?
(
:repository
,
current_user
)).
to
be
false
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