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
0
Merge Requests
0
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
Tatuya Kamada
gitlab-ce
Commits
fa075771
Commit
fa075771
authored
Oct 19, 2016
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor group_members_controller_spec
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
72af0e73
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
86 deletions
+35
-86
spec/controllers/groups/group_members_controller_spec.rb
spec/controllers/groups/group_members_controller_spec.rb
+34
-86
spec/factories/group_members.rb
spec/factories/group_members.rb
+1
-0
No files found.
spec/controllers/groups/group_members_controller_spec.rb
View file @
fa075771
...
@@ -2,16 +2,10 @@ require 'spec_helper'
...
@@ -2,16 +2,10 @@ require 'spec_helper'
describe
Groups
::
GroupMembersController
do
describe
Groups
::
GroupMembersController
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:group
)
{
create
(
:group
,
:public
)
}
describe
'#index'
do
describe
'GET index'
do
let
(
:group
)
{
create
(
:group
)
}
it
'renders index with 200 status code'
do
before
do
group
.
add_owner
(
user
)
stub_application_setting
(
restricted_visibility_levels:
[
Gitlab
::
VisibilityLevel
::
PUBLIC
])
end
it
'renders index with group members'
do
get
:index
,
group_id:
group
get
:index
,
group_id:
group
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
...
@@ -19,74 +13,56 @@ describe Groups::GroupMembersController do
...
@@ -19,74 +13,56 @@ describe Groups::GroupMembersController do
end
end
end
end
describe
'#destroy'
do
describe
'DELETE destroy'
do
let
(
:group
)
{
create
(
:group
,
:public
)
}
let
(
:member
)
{
create
(
:group_member
,
:developer
,
group:
group
)
}
before
{
sign_in
(
user
)
}
context
'when member is not found'
do
context
'when member is not found'
do
it
'returns 403'
do
it
'returns 403'
do
delete
:destroy
,
group_id:
group
,
delete
:destroy
,
group_id:
group
,
id:
42
id:
42
expect
(
response
).
to
have_http_status
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
end
end
context
'when member is found'
do
context
'when member is found'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:group_user
)
{
create
(
:user
)
}
let
(
:member
)
do
group
.
add_developer
(
group_user
)
group
.
members
.
find_by
(
user_id:
group_user
)
end
context
'when user does not have enough rights'
do
context
'when user does not have enough rights'
do
before
do
before
{
group
.
add_developer
(
user
)
}
group
.
add_developer
(
user
)
sign_in
(
user
)
end
it
'returns 403'
do
it
'returns 403'
do
delete
:destroy
,
group_id:
group
,
delete
:destroy
,
group_id:
group
,
id:
member
id:
member
expect
(
response
).
to
have_http_status
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
expect
(
group
.
users
).
to
include
group_us
er
expect
(
group
.
members
).
to
include
memb
er
end
end
end
end
context
'when user has enough rights'
do
context
'when user has enough rights'
do
before
do
before
{
group
.
add_owner
(
user
)
}
group
.
add_owner
(
user
)
sign_in
(
user
)
end
it
'[HTML] removes user from members'
do
it
'[HTML] removes user from members'
do
delete
:destroy
,
group_id:
group
,
delete
:destroy
,
group_id:
group
,
id:
member
id:
member
expect
(
response
).
to
set_flash
.
to
'User was successfully removed from group.'
expect
(
response
).
to
set_flash
.
to
'User was successfully removed from group.'
expect
(
response
).
to
redirect_to
(
group_group_members_path
(
group
))
expect
(
response
).
to
redirect_to
(
group_group_members_path
(
group
))
expect
(
group
.
users
).
not_to
include
group_us
er
expect
(
group
.
members
).
not_to
include
memb
er
end
end
it
'[JS] removes user from members'
do
it
'[JS] removes user from members'
do
xhr
:delete
,
:destroy
,
group_id:
group
,
xhr
:delete
,
:destroy
,
group_id:
group
,
id:
member
id:
member
expect
(
response
).
to
be_success
expect
(
response
).
to
be_success
expect
(
group
.
users
).
not_to
include
group_us
er
expect
(
group
.
members
).
not_to
include
memb
er
end
end
end
end
end
end
end
end
describe
'#leave'
do
describe
'DELETE leave'
do
let
(
:group
)
{
create
(
:group
,
:public
)
}
before
{
sign_in
(
user
)
}
let
(
:user
)
{
create
(
:user
)
}
context
'when member is not found'
do
context
'when member is not found'
do
before
{
sign_in
(
user
)
}
it
'returns 404'
do
it
'returns 404'
do
delete
:leave
,
group_id:
group
delete
:leave
,
group_id:
group
...
@@ -96,10 +72,7 @@ describe Groups::GroupMembersController do
...
@@ -96,10 +72,7 @@ describe Groups::GroupMembersController do
context
'when member is found'
do
context
'when member is found'
do
context
'and is not an owner'
do
context
'and is not an owner'
do
before
do
before
{
group
.
add_developer
(
user
)
}
group
.
add_developer
(
user
)
sign_in
(
user
)
end
it
'removes user from members'
do
it
'removes user from members'
do
delete
:leave
,
group_id:
group
delete
:leave
,
group_id:
group
...
@@ -111,10 +84,7 @@ describe Groups::GroupMembersController do
...
@@ -111,10 +84,7 @@ describe Groups::GroupMembersController do
end
end
context
'and is an owner'
do
context
'and is an owner'
do
before
do
before
{
group
.
add_owner
(
user
)
}
group
.
add_owner
(
user
)
sign_in
(
user
)
end
it
'cannot removes himself from the group'
do
it
'cannot removes himself from the group'
do
delete
:leave
,
group_id:
group
delete
:leave
,
group_id:
group
...
@@ -124,10 +94,7 @@ describe Groups::GroupMembersController do
...
@@ -124,10 +94,7 @@ describe Groups::GroupMembersController do
end
end
context
'and is a requester'
do
context
'and is a requester'
do
before
do
before
{
group
.
request_access
(
user
)
}
group
.
request_access
(
user
)
sign_in
(
user
)
end
it
'removes user from members'
do
it
'removes user from members'
do
delete
:leave
,
group_id:
group
delete
:leave
,
group_id:
group
...
@@ -141,13 +108,8 @@ describe Groups::GroupMembersController do
...
@@ -141,13 +108,8 @@ describe Groups::GroupMembersController do
end
end
end
end
describe
'#request_access'
do
describe
'POST request_access'
do
let
(
:group
)
{
create
(
:group
,
:public
)
}
before
{
sign_in
(
user
)
}
let
(
:user
)
{
create
(
:user
)
}
before
do
sign_in
(
user
)
end
it
'creates a new GroupMember that is not a team member'
do
it
'creates a new GroupMember that is not a team member'
do
post
:request_access
,
group_id:
group
post
:request_access
,
group_id:
group
...
@@ -159,53 +121,39 @@ describe Groups::GroupMembersController do
...
@@ -159,53 +121,39 @@ describe Groups::GroupMembersController do
end
end
end
end
describe
'#approve_access_request'
do
describe
'POST approve_access_request'
do
let
(
:group
)
{
create
(
:group
,
:public
)
}
let
(
:member
)
{
create
(
:group_member
,
:access_request
,
group:
group
)
}
before
{
sign_in
(
user
)
}
context
'when member is not found'
do
context
'when member is not found'
do
it
'returns 403'
do
it
'returns 403'
do
post
:approve_access_request
,
group_id:
group
,
post
:approve_access_request
,
group_id:
group
,
id:
42
id:
42
expect
(
response
).
to
have_http_status
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
end
end
context
'when member is found'
do
context
'when member is found'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:group_requester
)
{
create
(
:user
)
}
let
(
:member
)
do
group
.
request_access
(
group_requester
)
group
.
requesters
.
find_by
(
user_id:
group_requester
)
end
context
'when user does not have enough rights'
do
context
'when user does not have enough rights'
do
before
do
before
{
group
.
add_developer
(
user
)
}
group
.
add_developer
(
user
)
sign_in
(
user
)
end
it
'returns 403'
do
it
'returns 403'
do
post
:approve_access_request
,
group_id:
group
,
post
:approve_access_request
,
group_id:
group
,
id:
member
id:
member
expect
(
response
).
to
have_http_status
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
expect
(
group
.
users
).
not_to
include
group_request
er
expect
(
group
.
members
).
not_to
include
memb
er
end
end
end
end
context
'when user has enough rights'
do
context
'when user has enough rights'
do
before
do
before
{
group
.
add_owner
(
user
)
}
group
.
add_owner
(
user
)
sign_in
(
user
)
end
it
'adds user to members'
do
it
'adds user to members'
do
post
:approve_access_request
,
group_id:
group
,
post
:approve_access_request
,
group_id:
group
,
id:
member
id:
member
expect
(
response
).
to
redirect_to
(
group_group_members_path
(
group
))
expect
(
response
).
to
redirect_to
(
group_group_members_path
(
group
))
expect
(
group
.
users
).
to
include
group_request
er
expect
(
group
.
members
).
to
include
memb
er
end
end
end
end
end
end
...
...
spec/factories/group_members.rb
View file @
fa075771
...
@@ -9,5 +9,6 @@ FactoryGirl.define do
...
@@ -9,5 +9,6 @@ FactoryGirl.define do
trait
(
:developer
)
{
access_level
GroupMember
::
DEVELOPER
}
trait
(
:developer
)
{
access_level
GroupMember
::
DEVELOPER
}
trait
(
:master
)
{
access_level
GroupMember
::
MASTER
}
trait
(
:master
)
{
access_level
GroupMember
::
MASTER
}
trait
(
:owner
)
{
access_level
GroupMember
::
OWNER
}
trait
(
:owner
)
{
access_level
GroupMember
::
OWNER
}
trait
(
:access_request
)
{
requested_at
Time
.
now
}
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