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
Jérome Perrin
gitlab-ce
Commits
3f029144
Commit
3f029144
authored
Oct 26, 2016
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Complete and improve specs
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
1db9f826
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
105 additions
and
56 deletions
+105
-56
app/controllers/projects_controller.rb
app/controllers/projects_controller.rb
+2
-2
spec/controllers/projects/merge_requests_controller_spec.rb
spec/controllers/projects/merge_requests_controller_spec.rb
+54
-14
spec/features/merge_requests/check_if_mergeable_with_unresolved_discussions.rb
...equests/check_if_mergeable_with_unresolved_discussions.rb
+33
-17
spec/models/merge_request_spec.rb
spec/models/merge_request_spec.rb
+16
-23
No files found.
app/controllers/projects_controller.rb
View file @
3f029144
...
@@ -334,9 +334,9 @@ class ProjectsController < Projects::ApplicationController
...
@@ -334,9 +334,9 @@ class ProjectsController < Projects::ApplicationController
:issues_tracker_id
,
:default_branch
,
:issues_tracker_id
,
:default_branch
,
:visibility_level
,
:import_url
,
:last_activity_at
,
:namespace_id
,
:avatar
,
:visibility_level
,
:import_url
,
:last_activity_at
,
:namespace_id
,
:avatar
,
:build_allow_git_fetch
,
:build_timeout_in_minutes
,
:build_coverage_regex
,
:build_allow_git_fetch
,
:build_timeout_in_minutes
,
:build_coverage_regex
,
:public_builds
,
:only_allow_merge_if_build_succeeds
,
:public_builds
,
:only_allow_merge_if_build_succeeds
,
:request_access_enabled
,
:only_allow_merge_if_all_discussions_are_resolved
,
:only_allow_merge_if_all_discussions_are_resolved
,
:
request_access_enabled
,
:
lfs_enabled
,
project_feature_attributes
:lfs_enabled
,
project_feature_attributes
)
)
end
end
...
...
spec/controllers/projects/merge_requests_controller_spec.rb
View file @
3f029144
...
@@ -298,13 +298,18 @@ describe Projects::MergeRequestsController do
...
@@ -298,13 +298,18 @@ describe Projects::MergeRequestsController do
end
end
end
end
context
'when project project has unresolved discussion'
do
describe
'only_allow_merge_if_all_discussions_are_resolved? setting'
do
let
(
:merge_request
)
{
create
(
:merge_request_with_diff_notes
,
source_project:
project
,
author:
user
)
}
context
'when enabled'
do
before
do
before
do
project
.
update_column
(
:only_allow_merge_if_all_discussions_are_resolved
,
allowed
)
project
.
update_column
(
:only_allow_merge_if_all_discussions_are_resolved
,
true
)
end
end
context
"when the only_allow_merge_if_all_discussions_are_resolved? is true"
do
context
'with unresolved discussion'
do
let
(
:allowed
)
{
true
}
before
do
expect
(
merge_request
).
not_to
be_discussions_resolved
end
it
'returns :failed'
do
it
'returns :failed'
do
merge_with_sha
merge_with_sha
...
@@ -313,10 +318,44 @@ describe Projects::MergeRequestsController do
...
@@ -313,10 +318,44 @@ describe Projects::MergeRequestsController do
end
end
end
end
context
"when the only_allow_merge_if_all_discussions_are_resolved? is false"
do
context
'with all discussions resolved'
do
let
(
:allowed
)
{
false
}
before
do
merge_request
.
discussions
.
each
{
|
d
|
d
.
resolve!
(
user
)
}
expect
(
merge_request
).
to
be_discussions_resolved
end
it
'returns :failed'
do
it
'returns :success'
do
merge_with_sha
expect
(
assigns
(
:status
)).
to
eq
(
:success
)
end
end
end
context
'when disabled'
do
before
do
project
.
update_column
(
:only_allow_merge_if_all_discussions_are_resolved
,
false
)
end
context
'with unresolved discussion'
do
before
do
expect
(
merge_request
).
not_to
be_discussions_resolved
end
it
'returns :success'
do
merge_with_sha
expect
(
assigns
(
:status
)).
to
eq
(
:success
)
end
end
context
'with all discussions resolved'
do
before
do
merge_request
.
discussions
.
each
{
|
d
|
d
.
resolve!
(
user
)
}
expect
(
merge_request
).
to
be_discussions_resolved
end
it
'returns :success'
do
merge_with_sha
merge_with_sha
expect
(
assigns
(
:status
)).
to
eq
(
:success
)
expect
(
assigns
(
:status
)).
to
eq
(
:success
)
...
@@ -325,6 +364,7 @@ describe Projects::MergeRequestsController do
...
@@ -325,6 +364,7 @@ describe Projects::MergeRequestsController do
end
end
end
end
end
end
end
describe
"DELETE destroy"
do
describe
"DELETE destroy"
do
it
"denies access to users unless they're admin or project owner"
do
it
"denies access to users unless they're admin or project owner"
do
...
...
spec/features/merge_requests/check_if_mergeable_with_unresolved_discussions.rb
View file @
3f029144
require
'spec_helper'
require
'spec_helper'
feature
'Check if mergeable with unresolved discussions'
,
js:
true
,
feature:
true
do
feature
'Check if mergeable with unresolved discussions'
,
js:
true
,
feature:
true
do
let
!
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
!
(
:project
)
{
create
(
:project
,
:public
,
only_allow_merge_if_all_discussions_are_resolved:
allowed
)
}
let
(
:project
)
{
create
(
:project
)
}
let!
(
:merge_request
)
{
create
(
:merge_request_with_diff_notes
,
source_project:
project
,
author:
user
,
title:
"Bug NS-04"
)
}
let!
(
:merge_request
)
{
create
(
:merge_request_with_diff_notes
,
source_project:
project
,
author:
user
)
}
before
do
before
do
login_as
user
login_as
user
project
.
team
<<
[
user
,
:master
]
project
.
team
<<
[
user
,
:master
]
end
end
context
'when only_allow_merge_if_all_discussions_are_resolved is false'
do
context
'when project.only_allow_merge_if_all_discussions_are_resolved == true'
do
let
(
:allowed
)
{
false
}
before
do
project
.
update_column
(
:only_allow_merge_if_all_discussions_are_resolved
,
true
)
end
it
'allows MR to be merged'
do
context
'with unresolved discussions'
do
it
'does not allow to merge'
do
visit_merge_request
(
merge_request
)
visit_merge_request
(
merge_request
)
expect
(
page
).
to
have_button
'Accept Merge Request'
expect
(
page
).
not_to
have_button
'Accept Merge Request'
expect
(
page
).
to
have_content
(
'This merge request has unresolved discussions'
)
end
end
end
end
context
'when only_allow_merge_if_all_discussions_are_resolved is true'
do
context
'with all discussions resolved'
do
let
(
:allowed
)
{
true
}
context
"when discussions are resolved"
do
before
do
before
do
merge_request
.
discussions
.
each
{
|
d
|
d
.
resolve!
(
user
)
}
merge_request
.
discussions
.
each
{
|
d
|
d
.
resolve!
(
user
)
}
end
end
...
@@ -35,14 +35,30 @@ feature 'Check if mergeable with unresolved discussions', js: true, feature: tru
...
@@ -35,14 +35,30 @@ feature 'Check if mergeable with unresolved discussions', js: true, feature: tru
expect
(
page
).
to
have_button
'Accept Merge Request'
expect
(
page
).
to
have_button
'Accept Merge Request'
end
end
end
end
end
context
"when discussions are unresolved"
do
context
'when project.only_allow_merge_if_all_discussions_are_resolved == false'
do
before
do
project
.
update_column
(
:only_allow_merge_if_all_discussions_are_resolved
,
false
)
end
context
'with unresolved discussions'
do
it
'does not allow to merge'
do
it
'does not allow to merge'
do
visit_merge_request
(
merge_request
)
visit_merge_request
(
merge_request
)
expect
(
page
).
not_to
have_button
'Accept Merge Request'
expect
(
page
).
to
have_button
'Accept Merge Request'
expect
(
page
).
to
have_content
(
'This merge request has unresolved discussions'
)
end
end
context
'with all discussions resolved'
do
before
do
merge_request
.
discussions
.
each
{
|
d
|
d
.
resolve!
(
user
)
}
end
it
'allows MR to be merged'
do
visit_merge_request
(
merge_request
)
expect
(
page
).
to
have_button
'Accept Merge Request'
end
end
end
end
end
end
...
...
spec/models/merge_request_spec.rb
View file @
3f029144
...
@@ -825,11 +825,8 @@ describe MergeRequest, models: true do
...
@@ -825,11 +825,8 @@ describe MergeRequest, models: true do
end
end
context
'when failed'
do
context
'when failed'
do
before
{
allow
(
subject
).
to
receive
(
:broken?
)
{
false
}
}
context
'when #mergeable_ci_state? is false'
do
context
'when project settings restrict to merge only if build succeeds and build failed'
do
before
do
before
do
project
.
only_allow_merge_if_build_succeeds
=
true
allow
(
subject
).
to
receive
(
:mergeable_ci_state?
)
{
false
}
allow
(
subject
).
to
receive
(
:mergeable_ci_state?
)
{
false
}
end
end
...
@@ -838,9 +835,8 @@ describe MergeRequest, models: true do
...
@@ -838,9 +835,8 @@ describe MergeRequest, models: true do
end
end
end
end
context
"when project settings restrict to merge only when all the discussions are resolved"
do
context
'when #mergeable_discussions_state? is false'
do
before
do
before
do
project
.
only_allow_merge_if_all_discussions_are_resolved
=
true
allow
(
subject
).
to
receive
(
:mergeable_discussions_state?
)
{
false
}
allow
(
subject
).
to
receive
(
:mergeable_discussions_state?
)
{
false
}
end
end
...
@@ -899,45 +895,42 @@ describe MergeRequest, models: true do
...
@@ -899,45 +895,42 @@ describe MergeRequest, models: true do
end
end
describe
'#mergeable_discussions_state?'
do
describe
'#mergeable_discussions_state?'
do
let!
(
:user
)
{
create
(
:user
)
}
let
(
:merge_request
)
{
create
(
:merge_request_with_diff_notes
,
source_project:
project
)
}
let!
(
:project
)
{
create
(
:project
,
only_allow_merge_if_all_discussions_are_resolved:
allowed
)
}
subject
{
create
(
:merge_request_with_diff_notes
,
source_project:
project
)
}
context
'when
is
true'
do
context
'when
project.only_allow_merge_if_all_discussions_are_resolved ==
true'
do
let
(
:
allowed
)
{
true
}
let
(
:
project
)
{
create
(
:project
,
only_allow_merge_if_all_discussions_are_resolved:
true
)
}
context
'w
hen discussions are
resolved'
do
context
'w
ith all discussions
resolved'
do
before
do
before
do
subject
.
discussions
.
each
{
|
d
|
d
.
resolve!
(
use
r
)
}
merge_request
.
discussions
.
each
{
|
d
|
d
.
resolve!
(
merge_request
.
autho
r
)
}
end
end
it
'returns true'
do
it
'returns true'
do
expect
(
subjec
t
.
mergeable_discussions_state?
).
to
be_truthy
expect
(
merge_reques
t
.
mergeable_discussions_state?
).
to
be_truthy
end
end
end
end
context
'w
hen discussions are unresolved
'
do
context
'w
ith unresolved discussions
'
do
before
do
before
do
subject
.
discussions
.
map
(
&
:unresolve!
)
merge_request
.
discussions
.
each
(
&
:unresolve!
)
end
end
it
'returns false'
do
it
'returns false'
do
expect
(
subjec
t
.
mergeable_discussions_state?
).
to
be_falsey
expect
(
merge_reques
t
.
mergeable_discussions_state?
).
to
be_falsey
end
end
end
end
end
end
context
'when
is
false'
do
context
'when
project.only_allow_merge_if_all_discussions_are_resolved ==
false'
do
let
(
:
allowed
)
{
false
}
let
(
:
project
)
{
create
(
:project
,
only_allow_merge_if_all_discussions_are_resolved:
false
)
}
context
'w
hen discussions are unresolved
'
do
context
'w
ith unresolved discussions
'
do
before
do
before
do
subject
.
discussions
.
map
(
&
:unresolve!
)
merge_request
.
discussions
.
each
(
&
:unresolve!
)
end
end
it
'returns true'
do
it
'returns true'
do
expect
(
subjec
t
.
mergeable_discussions_state?
).
to
be_truthy
expect
(
merge_reques
t
.
mergeable_discussions_state?
).
to
be_truthy
end
end
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