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
8516e3ab
Commit
8516e3ab
authored
Sep 18, 2017
by
Micaël Bergeron
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add spec for forked project
parent
4714cb58
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
70 additions
and
66 deletions
+70
-66
spec/ee/spec/controllers/projects/merge_requests_controller_spec.rb
...ec/controllers/projects/merge_requests_controller_spec.rb
+70
-66
No files found.
spec/ee/spec/controllers/projects/merge_requests_controller_spec.rb
View file @
8516e3ab
require
'spec_helper'
describe
Projects
::
MergeRequestsController
do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:merge_request
)
{
create
(
:merge_request_with_diffs
,
target_project:
project
,
source_project:
project
)
}
let
(
:user
)
{
project
.
owner
}
let
(
:viewer
)
{
user
}
shared_examples
'approvals'
do
def
json_response
JSON
.
parse
(
response
.
body
)
end
let
(
:approver
)
{
create
(
:user
)
}
before
do
sign_in
(
viewer
)
merge_request
.
update_attribute
:approvals_before_merge
,
2
project
.
team
<<
[
approver
,
:developer
]
project
.
approver_ids
=
[
user
,
approver
].
map
(
&
:id
).
join
(
','
)
end
context
'approvals'
do
def
json_response
JSON
.
parse
(
response
.
body
)
describe
'approve'
do
before
do
post
:approve
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
.
to_param
,
id:
merge_request
.
iid
,
format: :json
end
let
(
:approver
)
{
create
(
:user
)
}
before
do
merge_request
.
update_attribute
:approvals_before_merge
,
2
project
.
team
<<
[
approver
,
:developer
]
project
.
approver_ids
=
[
user
,
approver
].
map
(
&
:id
).
join
(
','
)
it
'approves the merge request'
do
expect
(
response
).
to
be_success
expect
(
json_response
[
'approvals_left'
]).
to
eq
1
expect
(
json_response
[
'approved_by'
].
size
).
to
eq
1
expect
(
json_response
[
'approved_by'
][
0
][
'user'
][
'username'
]).
to
eq
user
.
username
expect
(
json_response
[
'user_has_approved'
]).
to
be
true
expect
(
json_response
[
'user_can_approve'
]).
to
be
false
expect
(
json_response
[
'suggested_approvers'
].
size
).
to
eq
1
expect
(
json_response
[
'suggested_approvers'
][
0
][
'username'
]).
to
eq
approver
.
username
end
end
describe
'approve'
do
before
do
post
:approve
,
describe
'approvals'
do
before
do
merge_request
.
approvals
.
create
(
user:
approver
)
get
:approvals
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
.
to_param
,
id:
merge_request
.
iid
,
format: :json
end
end
it
'approves the merge request'
do
expect
(
response
).
to
be_success
expect
(
json_response
[
'approvals_left'
]).
to
eq
1
expect
(
json_response
[
'approved_by'
].
size
).
to
eq
1
expect
(
json_response
[
'approved_by'
][
0
][
'user'
][
'username'
]).
to
eq
user
.
username
expect
(
json_response
[
'user_has_approved'
]).
to
be
true
expect
(
json_response
[
'user_can_approve'
]).
to
be
false
expect
(
json_response
[
'suggested_approvers'
].
size
).
to
eq
1
expect
(
json_response
[
'suggested_approvers'
][
0
][
'username'
]).
to
eq
approver
.
username
end
it
'shows approval information'
do
expect
(
response
).
to
be_success
expect
(
json_response
[
'approvals_left'
]).
to
eq
1
expect
(
json_response
[
'approved_by'
].
size
).
to
eq
1
expect
(
json_response
[
'approved_by'
][
0
][
'user'
][
'username'
]).
to
eq
approver
.
username
expect
(
json_response
[
'user_has_approved'
]).
to
be
false
expect
(
json_response
[
'user_can_approve'
]).
to
be
true
expect
(
json_response
[
'suggested_approvers'
].
size
).
to
eq
1
expect
(
json_response
[
'suggested_approvers'
][
0
][
'username'
]).
to
eq
user
.
username
end
end
describe
'approvals
'
do
before
do
merge_request
.
approvals
.
create
(
user:
approv
er
)
get
:approvals
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
.
to_param
,
id:
merge_request
.
iid
,
format: :json
end
describe
'unapprove
'
do
before
do
merge_request
.
approvals
.
create
(
user:
us
er
)
delete
:unapprove
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
.
to_param
,
id:
merge_request
.
iid
,
format: :json
end
it
'shows approval information'
do
expect
(
response
).
to
be_success
expect
(
json_response
[
'approvals_left'
]).
to
eq
1
expect
(
json_response
[
'approved_by'
].
size
).
to
eq
1
expect
(
json_response
[
'approved_by'
][
0
][
'user'
][
'username'
]).
to
eq
approver
.
username
expect
(
json_response
[
'user_has_approved'
]).
to
be
false
expect
(
json_response
[
'user_can_approve'
]).
to
be
true
expect
(
json_response
[
'suggested_approvers'
].
size
).
to
eq
1
expect
(
json_response
[
'suggested_approvers'
][
0
][
'username'
]).
to
eq
user
.
username
end
it
'unapproves the merge request'
do
expect
(
response
).
to
be_success
expect
(
json_response
[
'approvals_left'
]).
to
eq
2
expect
(
json_response
[
'approved_by'
]).
to
be_empty
expect
(
json_response
[
'user_has_approved'
]).
to
be
false
expect
(
json_response
[
'user_can_approve'
]).
to
be
true
expect
(
json_response
[
'suggested_approvers'
].
size
).
to
eq
2
end
end
end
describe
'unapprove'
do
before
do
merge_request
.
approvals
.
create
(
user:
user
)
delete
:unapprove
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
.
to_param
,
id:
merge_request
.
iid
,
format: :json
end
describe
Projects
::
MergeRequestsController
do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:merge_request
)
{
create
(
:merge_request_with_diffs
,
target_project:
project
,
source_project:
project
)
}
let
(
:user
)
{
project
.
owner
}
let
(
:viewer
)
{
user
}
it
'unapproves the merge request'
do
expect
(
response
).
to
be_success
expect
(
json_response
[
'approvals_left'
]).
to
eq
2
expect
(
json_response
[
'approved_by'
]).
to
be_empty
expect
(
json_response
[
'user_has_approved'
]).
to
be
false
expect
(
json_response
[
'user_can_approve'
]).
to
be
true
expect
(
json_response
[
'suggested_approvers'
].
size
).
to
eq
2
end
end
before
do
sign_in
(
viewer
)
end
it_behaves_like
'approvals'
describe
'PUT update'
do
def
update_merge_request
(
params
=
{})
post
:update
,
...
...
@@ -353,6 +355,8 @@ describe Projects::MergeRequestsController do
fork_project
.
add_reporter
(
user
)
end
it_behaves_like
'approvals'
context
'user cannot push to source branch'
do
it
'returns 404'
do
expect_rebase_worker_for
(
viewer
).
never
...
...
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