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
Boxiang Sun
gitlab-ce
Commits
357c794a
Commit
357c794a
authored
Oct 19, 2016
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor project_members_controller_spec
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
fa075771
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
78 deletions
+36
-78
spec/controllers/projects/project_members_controller_spec.rb
spec/controllers/projects/project_members_controller_spec.rb
+35
-78
spec/factories/project_members.rb
spec/factories/project_members.rb
+1
-0
No files found.
spec/controllers/projects/project_members_controller_spec.rb
View file @
357c794a
require
(
'spec_helper'
)
describe
Projects
::
ProjectMembersController
do
describe
'#apply_import'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
,
:public
)
}
describe
'POST apply_import'
do
let
(
:another_project
)
{
create
(
:project
,
:private
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:member
)
{
create
(
:user
)
}
before
do
...
...
@@ -47,23 +48,19 @@ describe Projects::ProjectMembersController do
end
end
describe
'#index'
do
context
'when user is member'
do
before
do
project
=
create
(
:project
,
:private
)
member
=
create
(
:user
)
project
.
team
<<
[
member
,
:guest
]
sign_in
(
member
)
get
:index
,
namespace_id:
project
.
namespace
,
project_id:
project
end
describe
'GET index'
do
it
'renders index with 200 status code'
do
get
:index
,
namespace_id:
project
.
namespace
,
project_id:
project
it
{
expect
(
response
).
to
have_http_status
(
200
)
}
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
).
to
render_template
(
:index
)
end
end
describe
'#destroy'
do
let
(
:project
)
{
create
(
:project
,
:public
)
}
describe
'DELETE destroy'
do
let
(
:member
)
{
create
(
:project_member
,
:developer
,
project:
project
)
}
before
{
sign_in
(
user
)
}
context
'when member is not found'
do
it
'returns 404'
do
...
...
@@ -76,18 +73,8 @@ describe Projects::ProjectMembersController do
end
context
'when member is found'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:team_user
)
{
create
(
:user
)
}
let
(
:member
)
do
project
.
team
<<
[
team_user
,
:developer
]
project
.
members
.
find_by
(
user_id:
team_user
.
id
)
end
context
'when user does not have enough rights'
do
before
do
project
.
team
<<
[
user
,
:developer
]
sign_in
(
user
)
end
before
{
project
.
team
<<
[
user
,
:developer
]
}
it
'returns 404'
do
delete
:destroy
,
namespace_id:
project
.
namespace
,
...
...
@@ -95,15 +82,12 @@ describe Projects::ProjectMembersController do
id:
member
expect
(
response
).
to
have_http_status
(
404
)
expect
(
project
.
users
).
to
include
team_us
er
expect
(
project
.
members
).
to
include
memb
er
end
end
context
'when user has enough rights'
do
before
do
project
.
team
<<
[
user
,
:master
]
sign_in
(
user
)
end
before
{
project
.
team
<<
[
user
,
:master
]
}
it
'[HTML] removes user from members'
do
delete
:destroy
,
namespace_id:
project
.
namespace
,
...
...
@@ -113,7 +97,7 @@ describe Projects::ProjectMembersController do
expect
(
response
).
to
redirect_to
(
namespace_project_project_members_path
(
project
.
namespace
,
project
)
)
expect
(
project
.
users
).
not_to
include
team_us
er
expect
(
project
.
members
).
not_to
include
memb
er
end
it
'[JS] removes user from members'
do
...
...
@@ -122,19 +106,16 @@ describe Projects::ProjectMembersController do
id:
member
expect
(
response
).
to
be_success
expect
(
project
.
users
).
not_to
include
team_us
er
expect
(
project
.
members
).
not_to
include
memb
er
end
end
end
end
describe
'#leave'
do
let
(
:project
)
{
create
(
:project
,
:public
)
}
let
(
:user
)
{
create
(
:user
)
}
describe
'DELETE leave'
do
before
{
sign_in
(
user
)
}
context
'when member is not found'
do
before
{
sign_in
(
user
)
}
it
'returns 404'
do
delete
:leave
,
namespace_id:
project
.
namespace
,
project_id:
project
...
...
@@ -145,10 +126,7 @@ describe Projects::ProjectMembersController do
context
'when member is found'
do
context
'and is not an owner'
do
before
do
project
.
team
<<
[
user
,
:developer
]
sign_in
(
user
)
end
before
{
project
.
team
<<
[
user
,
:developer
]
}
it
'removes user from members'
do
delete
:leave
,
namespace_id:
project
.
namespace
,
...
...
@@ -161,11 +139,9 @@ describe Projects::ProjectMembersController do
end
context
'and is an owner'
do
before
do
project
.
update
(
namespace_id:
user
.
namespace_id
)
project
.
team
<<
[
user
,
:master
,
user
]
sign_in
(
user
)
end
let
(
:project
)
{
create
(
:project
,
namespace:
user
.
namespace
)
}
before
{
project
.
team
<<
[
user
,
:master
]
}
it
'cannot remove himself from the project'
do
delete
:leave
,
namespace_id:
project
.
namespace
,
...
...
@@ -176,10 +152,7 @@ describe Projects::ProjectMembersController do
end
context
'and is a requester'
do
before
do
project
.
request_access
(
user
)
sign_in
(
user
)
end
before
{
project
.
request_access
(
user
)
}
it
'removes user from members'
do
delete
:leave
,
namespace_id:
project
.
namespace
,
...
...
@@ -194,13 +167,8 @@ describe Projects::ProjectMembersController do
end
end
describe
'#request_access'
do
let
(
:project
)
{
create
(
:project
,
:public
)
}
let
(
:user
)
{
create
(
:user
)
}
before
do
sign_in
(
user
)
end
describe
'POST request_access'
do
before
{
sign_in
(
user
)
}
it
'creates a new ProjectMember that is not a team member'
do
post
:request_access
,
namespace_id:
project
.
namespace
,
...
...
@@ -215,8 +183,10 @@ describe Projects::ProjectMembersController do
end
end
describe
'#approve'
do
let
(
:project
)
{
create
(
:project
,
:public
)
}
describe
'POST approve'
do
let
(
:member
)
{
create
(
:project_member
,
:access_request
,
project:
project
)
}
before
{
sign_in
(
user
)
}
context
'when member is not found'
do
it
'returns 404'
do
...
...
@@ -229,18 +199,8 @@ describe Projects::ProjectMembersController do
end
context
'when member is found'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:team_requester
)
{
create
(
:user
)
}
let
(
:member
)
do
project
.
request_access
(
team_requester
)
project
.
requesters
.
find_by
(
user_id:
team_requester
.
id
)
end
context
'when user does not have enough rights'
do
before
do
project
.
team
<<
[
user
,
:developer
]
sign_in
(
user
)
end
before
{
project
.
team
<<
[
user
,
:developer
]
}
it
'returns 404'
do
post
:approve_access_request
,
namespace_id:
project
.
namespace
,
...
...
@@ -248,15 +208,12 @@ describe Projects::ProjectMembersController do
id:
member
expect
(
response
).
to
have_http_status
(
404
)
expect
(
project
.
users
).
not_to
include
team_request
er
expect
(
project
.
members
).
not_to
include
memb
er
end
end
context
'when user has enough rights'
do
before
do
project
.
team
<<
[
user
,
:master
]
sign_in
(
user
)
end
before
{
project
.
team
<<
[
user
,
:master
]
}
it
'adds user to members'
do
post
:approve_access_request
,
namespace_id:
project
.
namespace
,
...
...
@@ -266,7 +223,7 @@ describe Projects::ProjectMembersController do
expect
(
response
).
to
redirect_to
(
namespace_project_project_members_path
(
project
.
namespace
,
project
)
)
expect
(
project
.
users
).
to
include
team_request
er
expect
(
project
.
members
).
to
include
memb
er
end
end
end
...
...
spec/factories/project_members.rb
View file @
357c794a
...
...
@@ -8,5 +8,6 @@ FactoryGirl.define do
trait
(
:reporter
)
{
access_level
ProjectMember
::
REPORTER
}
trait
(
:developer
)
{
access_level
ProjectMember
::
DEVELOPER
}
trait
(
:master
)
{
access_level
ProjectMember
::
MASTER
}
trait
(
:access_request
)
{
requested_at
Time
.
now
}
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