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
1a644860
Commit
1a644860
authored
Feb 26, 2020
by
Rajendra Kadam
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use shared examples in rspecs to group similar contexts
parent
53579e0a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
63 deletions
+65
-63
spec/requests/api/groups_spec.rb
spec/requests/api/groups_spec.rb
+65
-63
No files found.
spec/requests/api/groups_spec.rb
View file @
1a644860
...
@@ -21,6 +21,28 @@ describe API::Groups do
...
@@ -21,6 +21,28 @@ describe API::Groups do
group2
.
add_owner
(
user2
)
group2
.
add_owner
(
user2
)
end
end
shared_examples
'it uploads group avatar'
do
it
'returns avatar url in response'
do
make_upload_request
group_id
=
json_response
[
'id'
]
expect
(
json_response
[
'avatar_url'
]).
to
eq
(
'http://localhost/uploads/'
\
'-/system/group/avatar/'
\
"
#{
group_id
}
/banana_sample.gif"
)
end
end
shared_examples
'it returns 400 for bad upload request'
do
it
'returns 400'
do
make_upload_request
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
expect
(
response
.
message
).
to
eq
(
'Bad Request'
)
expect
(
json_response
[
'message'
]).
to
eq
(
message
)
end
end
describe
"GET /groups"
do
describe
"GET /groups"
do
context
"when unauthenticated"
do
context
"when unauthenticated"
do
it
"returns public groups"
do
it
"returns public groups"
do
...
@@ -539,6 +561,13 @@ describe API::Groups do
...
@@ -539,6 +561,13 @@ describe API::Groups do
describe
'PUT /groups/:id'
do
describe
'PUT /groups/:id'
do
let
(
:new_group_name
)
{
'New Group'
}
let
(
:new_group_name
)
{
'New Group'
}
def
make_upload_request
group_param
=
{
avatar:
fixture_file_upload
(
file_path
)
}
put
api
(
"/groups/
#{
group1
.
id
}
"
,
user1
),
params:
group_param
end
context
'when authenticated as the group owner'
do
context
'when authenticated as the group owner'
do
it
'updates the group'
do
it
'updates the group'
do
put
api
(
"/groups/
#{
group1
.
id
}
"
,
user1
),
params:
{
put
api
(
"/groups/
#{
group1
.
id
}
"
,
user1
),
params:
{
...
@@ -570,43 +599,26 @@ describe API::Groups do
...
@@ -570,43 +599,26 @@ describe API::Groups do
expect
(
json_response
[
'default_branch_protection'
]).
to
eq
(
::
Gitlab
::
Access
::
MAINTAINER_PROJECT_ACCESS
)
expect
(
json_response
[
'default_branch_protection'
]).
to
eq
(
::
Gitlab
::
Access
::
MAINTAINER_PROJECT_ACCESS
)
end
end
it
'updates avatar'
do
context
'group avatar update'
do
group_param
=
{
context
'when appropriate file is used'
do
avatar:
fixture_file_upload
(
'spec/fixtures/banana_sample.gif'
,
'image/gif'
)
let
(
:file_path
)
{
'spec/fixtures/banana_sample.gif'
}
}
put
api
(
"/groups/
#{
group1
.
id
}
"
,
user1
),
params:
group_param
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
it_behaves_like
'it uploads group avatar'
expect
(
json_response
[
'avatar_url'
]).
to
eq
(
'http://localhost/uploads/'
\
'-/system/group/avatar/'
\
"
#{
group1
.
id
}
/banana_sample.gif"
)
end
end
it
'returns 400 if file type is invalid to update avatar'
do
context
'when invalid file is used'
do
group_param
=
{
let
(
:file_path
)
{
'spec/fixtures/doc_sample.txt'
}
avatar:
fixture_file_upload
(
'spec/fixtures/doc_sample.txt'
,
'text/plain'
)
let
(
:message
)
{
{
"avatar"
=>
[
"file format is not supported. Please try one of the following supported formats: png, jpg, jpeg, gif, bmp, tiff, ico"
]
}
}
}
put
api
(
"/groups/
#{
group1
.
id
}
"
,
user1
),
params:
group_param
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
it_behaves_like
'it returns 400 for bad upload request'
expect
(
response
.
message
).
to
eq
(
'Bad Request'
)
expect
(
json_response
[
'message'
][
'avatar'
]).
to
eq
([
'file format is not supported.'
\
' Please try one of the following supported formats:'
\
' png, jpg, jpeg, gif, bmp, tiff, ico'
])
end
end
it
'returns 400 if file size exceeds allowed limit for group avatar'
do
context
'when file is too big'
do
group_param
=
{
let
(
:file_path
)
{
'spec/fixtures/big-image.png'
}
avatar:
fixture_file_upload
(
'spec/fixtures/big-image.png'
,
'image/png'
)
let
(
:message
)
{
{
"avatar"
=>
[
"is too big (should be at most 200 KB)"
]
}
}
}
put
api
(
"/groups/
#{
group1
.
id
}
"
,
user1
),
params:
group_param
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
it_behaves_like
'it returns 400 for bad upload request'
expect
(
response
.
message
).
to
eq
(
'Bad Request'
)
end
expect
(
json_response
[
'message'
][
'avatar'
]).
to
eq
([
'is too big (should be at most 200 KB)'
])
end
end
it
'returns 404 for a non existing group'
do
it
'returns 404 for a non existing group'
do
...
@@ -979,6 +991,12 @@ describe API::Groups do
...
@@ -979,6 +991,12 @@ describe API::Groups do
end
end
describe
"POST /groups"
do
describe
"POST /groups"
do
def
make_upload_request
group
=
attributes_for_group_api
request_access_enabled:
false
group
[
:avatar
]
=
fixture_file_upload
(
file_path
)
post
api
(
"/groups"
,
user3
),
params:
group
end
context
"when authenticated as user without group permissions"
do
context
"when authenticated as user without group permissions"
do
it
"does not create group"
do
it
"does not create group"
do
group
=
attributes_for_group_api
group
=
attributes_for_group_api
...
@@ -1027,42 +1045,26 @@ describe API::Groups do
...
@@ -1027,42 +1045,26 @@ describe API::Groups do
expect
(
json_response
[
"visibility"
]).
to
eq
(
Gitlab
::
VisibilityLevel
.
string_level
(
Gitlab
::
CurrentSettings
.
current_application_settings
.
default_group_visibility
))
expect
(
json_response
[
"visibility"
]).
to
eq
(
Gitlab
::
VisibilityLevel
.
string_level
(
Gitlab
::
CurrentSettings
.
current_application_settings
.
default_group_visibility
))
end
end
it
"uploads avatar for a group"
do
context
'group avatar upload'
do
group
=
attributes_for_group_api
request_access_enabled:
false
context
'when appropriate file is used'
do
group
[
:avatar
]
=
fixture_file_upload
(
'spec/fixtures/banana_sample.gif'
,
'image/gif'
)
let
(
:file_path
)
{
'spec/fixtures/banana_sample.gif'
}
post
api
(
"/groups"
,
user3
),
params:
group
group_id
=
json_response
[
'id'
]
it_behaves_like
'it uploads group avatar'
expect
(
json_response
[
'avatar_url'
]).
to
eq
(
'http://localhost/uploads/'
\
'-/system/group/avatar/'
\
"
#{
group_id
}
/banana_sample.gif"
)
end
end
it
'returns a 400 if file type is invalid for group avatar'
do
context
'when invalid file is used'
do
group
=
attributes_for_group_api
request_access_enabled:
false
let
(
:file_path
)
{
'spec/fixtures/doc_sample.txt'
}
group
[
:avatar
]
=
fixture_file_upload
(
'spec/fixtures/doc_sample.txt'
,
'text/plain'
)
let
(
:message
)
{
'Failed to save group {:avatar=>["file format is not supported. Please try one of the following supported formats: png, jpg, jpeg, gif, bmp, tiff, ico"]}'
}
post
api
(
"/groups"
,
user3
),
params:
group
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
it_behaves_like
'it returns 400 for bad upload request'
expect
(
response
.
message
).
to
eq
(
'Bad Request'
)
expect
(
json_response
[
'message'
]).
to
eq
(
'Failed to save group'
\
' {:avatar=>["file format is not supported.'
\
' Please try one of the following supported formats:'
\
' png, jpg, jpeg, gif, bmp, tiff, ico"]}'
)
end
end
it
'returns 400 if group avatar file size exceeds allowed limit'
do
context
'when file is too big'
do
group
=
attributes_for_group_api
request_access_enabled:
false
let
(
:file_path
)
{
'spec/fixtures/big-image.png'
}
group
[
:avatar
]
=
fixture_file_upload
(
'spec/fixtures/big-image.png'
,
'image/png'
)
let
(
:message
)
{
'Failed to save group {:avatar=>["is too big (should be at most 200 KB)"]}'
}
post
api
(
"/groups"
,
user3
),
params:
group
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
it_behaves_like
'it returns 400 for bad upload request'
expect
(
response
.
message
).
to
eq
(
'Bad Request'
)
end
expect
(
json_response
[
'message'
]).
to
eq
(
'Failed to save group'
\
' {:avatar=>["is too big (should be at most 200 KB)"]}'
)
end
end
it
"creates a nested group"
do
it
"creates a nested group"
do
...
...
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