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
Léo-Paul Géneau
gitlab-ce
Commits
41007f6d
Commit
41007f6d
authored
Aug 15, 2016
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Address review feedback
parent
32e31d62
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
116 additions
and
86 deletions
+116
-86
app/controllers/projects/discussions_controller.rb
app/controllers/projects/discussions_controller.rb
+1
-1
app/controllers/projects/notes_controller.rb
app/controllers/projects/notes_controller.rb
+2
-2
app/models/diff_note.rb
app/models/diff_note.rb
+1
-1
app/models/discussion.rb
app/models/discussion.rb
+2
-0
app/services/merge_requests/resolved_discussion_notification_service.rb
...erge_requests/resolved_discussion_notification_service.rb
+1
-1
spec/controllers/projects/discussions_controller_spec.rb
spec/controllers/projects/discussions_controller_spec.rb
+27
-14
spec/controllers/projects/notes_controller_spec.rb
spec/controllers/projects/notes_controller_spec.rb
+80
-65
spec/models/diff_note_spec.rb
spec/models/diff_note_spec.rb
+1
-1
spec/services/merge_requests/resolved_discussion_notification_service.rb
...erge_requests/resolved_discussion_notification_service.rb
+1
-1
No files found.
app/controllers/projects/discussions_controller.rb
View file @
41007f6d
...
...
@@ -9,7 +9,7 @@ class Projects::DiscussionsController < Projects::ApplicationController
discussion
.
resolve!
(
current_user
)
MergeRequests
::
AllDiscussionsResolved
Service
.
new
(
project
,
current_user
).
execute
(
merge_request
)
MergeRequests
::
ResolvedDiscussionNotification
Service
.
new
(
project
,
current_user
).
execute
(
merge_request
)
render
json:
{
resolved_by:
discussion
.
resolved_by
.
try
(
:name
),
...
...
app/controllers/projects/notes_controller.rb
View file @
41007f6d
...
...
@@ -72,7 +72,7 @@ class Projects::NotesController < Projects::ApplicationController
note
.
resolve!
(
current_user
)
MergeRequests
::
AllDiscussionsResolved
Service
.
new
(
project
,
current_user
).
execute
(
note
.
noteable
)
MergeRequests
::
ResolvedDiscussionNotification
Service
.
new
(
project
,
current_user
).
execute
(
note
.
noteable
)
discussion
=
note
.
discussion
...
...
@@ -166,7 +166,7 @@ class Projects::NotesController < Projects::ApplicationController
}
if
note
.
diff_note?
discussion
=
note
.
as
_discussion
discussion
=
note
.
to
_discussion
attrs
.
merge!
(
diff_discussion_html:
diff_discussion_html
(
discussion
),
...
...
app/models/diff_note.rb
View file @
41007f6d
...
...
@@ -113,7 +113,7 @@ class DiffNote < Note
Discussion
.
new
(
discussion_notes
)
end
def
as
_discussion
def
to
_discussion
Discussion
.
new
([
self
])
end
...
...
app/models/discussion.rb
View file @
41007f6d
...
...
@@ -57,6 +57,8 @@ class Discussion
def
id
first_note
.
discussion_id
end
alias_method
:to_param
,
:id
def
diff_discussion?
first_note
.
diff_note?
...
...
app/services/merge_requests/
all_discussions_resolved
_service.rb
→
app/services/merge_requests/
resolved_discussion_notification
_service.rb
View file @
41007f6d
module
MergeRequests
class
AllDiscussionsResolved
Service
<
MergeRequests
::
BaseService
class
ResolvedDiscussionNotification
Service
<
MergeRequests
::
BaseService
def
execute
(
merge_request
)
return
unless
merge_request
.
discussions_resolved?
...
...
spec/controllers/projects/discussions_controller_spec.rb
View file @
41007f6d
...
...
@@ -5,6 +5,16 @@ describe Projects::DiscussionsController do
let
(
:project
)
{
create
(
:project
)
}
let
(
:merge_request
)
{
create
(
:merge_request
,
source_project:
project
)
}
let
(
:note
)
{
create
(
:diff_note_on_merge_request
,
noteable:
merge_request
,
project:
project
)
}
let
(
:discussion
)
{
note
.
discussion
}
let
(
:request_params
)
do
{
namespace_id:
project
.
namespace
,
project_id:
project
,
merge_request_id:
merge_request
,
id:
note
.
discussion_id
}
end
describe
'POST resolve'
do
before
do
...
...
@@ -13,7 +23,7 @@ describe Projects::DiscussionsController do
context
"when the user is not authorized to resolve the discussion"
do
it
"returns status 404"
do
post
:resolve
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
merge_request_id:
merge_request
.
iid
,
id:
note
.
discussion_id
post
:resolve
,
request_params
expect
(
response
).
to
have_http_status
(
404
)
end
...
...
@@ -30,7 +40,7 @@ describe Projects::DiscussionsController do
end
it
"returns status 404"
do
post
:resolve
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
merge_request_id:
merge_request
.
iid
,
id:
note
.
discussion_id
post
:resolve
,
request_params
expect
(
response
).
to
have_http_status
(
404
)
end
...
...
@@ -38,25 +48,26 @@ describe Projects::DiscussionsController do
context
"when the discussion is resolvable"
do
it
"resolves the discussion"
do
expect_any_instance_of
(
Discussion
).
to
receive
(
:resolve!
).
with
(
user
)
post
:resolve
,
request_params
post
:resolve
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
merge_request_id:
merge_request
.
iid
,
id:
note
.
discussion_id
expect
(
note
.
reload
.
discussion
.
resolved?
).
to
be
true
expect
(
note
.
reload
.
discussion
.
resolved_by
).
to
eq
(
user
)
end
it
"
checks whether all note
s are resolved"
do
expect_any_instance_of
(
MergeRequests
::
AllDiscussionsResolved
Service
).
to
receive
(
:execute
).
with
(
merge_request
)
it
"
sends notifications if all discussion
s are resolved"
do
expect_any_instance_of
(
MergeRequests
::
ResolvedDiscussionNotification
Service
).
to
receive
(
:execute
).
with
(
merge_request
)
post
:resolve
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
merge_request_id:
merge_request
.
iid
,
id:
note
.
discussion_id
post
:resolve
,
request_params
end
it
"returns the name of the resolving user"
do
post
:resolve
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
merge_request_id:
merge_request
.
iid
,
id:
note
.
discussion_id
post
:resolve
,
request_params
expect
(
JSON
.
parse
(
response
.
body
)[
"resolved_by"
]).
to
eq
(
user
.
name
)
end
it
"returns status 200"
do
post
:resolve
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
merge_request_id:
merge_request
.
iid
,
id:
note
.
discussion_id
post
:resolve
,
request_params
expect
(
response
).
to
have_http_status
(
200
)
end
...
...
@@ -67,11 +78,13 @@ describe Projects::DiscussionsController do
describe
'DELETE unresolve'
do
before
do
sign_in
user
note
.
discussion
.
resolve!
(
user
)
end
context
"when the user is not authorized to resolve the discussion"
do
it
"returns status 404"
do
delete
:unresolve
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
merge_request_id:
merge_request
.
iid
,
id:
note
.
discussion_id
delete
:unresolve
,
request_params
expect
(
response
).
to
have_http_status
(
404
)
end
...
...
@@ -88,7 +101,7 @@ describe Projects::DiscussionsController do
end
it
"returns status 404"
do
delete
:unresolve
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
merge_request_id:
merge_request
.
iid
,
id:
note
.
discussion_id
delete
:unresolve
,
request_params
expect
(
response
).
to
have_http_status
(
404
)
end
...
...
@@ -96,13 +109,13 @@ describe Projects::DiscussionsController do
context
"when the discussion is resolvable"
do
it
"unresolves the discussion"
do
expect_any_instance_of
(
Discussion
).
to
receive
(
:unresolve!
)
delete
:unresolve
,
request_params
delete
:unresolve
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
merge_request_id:
merge_request
.
iid
,
id:
note
.
discussion_id
expect
(
note
.
reload
.
discussion
.
resolved?
).
to
be
false
end
it
"returns status 200"
do
delete
:unresolve
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
merge_request_id:
merge_request
.
iid
,
id:
note
.
discussion_id
delete
:unresolve
,
request_params
expect
(
response
).
to
have_http_status
(
200
)
end
...
...
spec/controllers/projects/notes_controller_spec.rb
View file @
41007f6d
...
...
@@ -6,6 +6,14 @@ describe Projects::NotesController do
let
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:note
)
{
create
(
:note
,
noteable:
issue
,
project:
project
)
}
let
(
:request_params
)
do
{
namespace_id:
project
.
namespace
,
project_id:
project
,
id:
note
}
end
describe
'POST toggle_award_emoji'
do
before
do
sign_in
(
user
)
...
...
@@ -14,123 +22,130 @@ describe Projects::NotesController do
it
"toggles the award emoji"
do
expect
do
post
(
:toggle_award_emoji
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
id:
note
.
id
,
name:
"thumbsup"
)
post
(
:toggle_award_emoji
,
request_params
.
merge
(
name:
"thumbsup"
))
end
.
to
change
{
note
.
award_emoji
.
count
}.
by
(
1
)
expect
(
response
).
to
have_http_status
(
200
)
end
it
"removes the already awarded emoji"
do
post
(
:toggle_award_emoji
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
id:
note
.
id
,
name:
"thumbsup"
)
post
(
:toggle_award_emoji
,
request_params
.
merge
(
name:
"thumbsup"
))
expect
do
post
(
:toggle_award_emoji
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
id:
note
.
id
,
name:
"thumbsup"
)
post
(
:toggle_award_emoji
,
request_params
.
merge
(
name:
"thumbsup"
))
end
.
to
change
{
AwardEmoji
.
count
}.
by
(
-
1
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
describe
'POST resolve'
do
before
do
sign_in
user
end
describe
"resolving and unresolving"
do
let
(
:merge_request
)
{
create
(
:merge_request
,
source_project:
project
)
}
let
(
:note
)
{
create
(
:diff_note_on_merge_request
,
noteable:
merge_request
,
project:
project
)
}
context
"when the user is not authorized to resolve the note"
do
it
"returns status 404"
do
post
:resolve
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
id:
note
.
id
expect
(
response
).
to
have_http_status
(
404
)
end
end
context
"when the user is authorized to resolve the note"
do
describe
'POST resolve'
do
before
do
project
.
team
<<
[
user
,
:developer
]
sign_in
user
end
context
"when the
note is not resolvabl
e"
do
context
"when the
user is not authorized to resolve the not
e"
do
it
"returns status 404"
do
post
:resolve
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
id:
note
.
id
post
:resolve
,
request_params
expect
(
response
).
to
have_http_status
(
404
)
end
end
context
"when the note is resolvable"
do
let
(
:merge_request
)
{
create
(
:merge_request
,
source_project:
project
)
}
let
(
:note
)
{
create
(
:diff_note_on_merge_request
,
noteable:
merge_request
,
project:
project
)
}
it
"resolves the note"
do
expect_any_instance_of
(
DiffNote
).
to
receive
(
:resolve!
).
with
(
user
)
post
:resolve
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
id:
note
.
id
context
"when the user is authorized to resolve the note"
do
before
do
project
.
team
<<
[
user
,
:developer
]
end
it
"checks whether all notes are resolved"
do
expect_any_instance_of
(
MergeRequests
::
AllDiscussionsResolvedService
).
to
receive
(
:execute
).
with
(
merge_request
)
context
"when the note is not resolvable"
do
before
do
note
.
update
(
system:
true
)
end
post
:resolve
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
id:
note
.
id
it
"returns status 404"
do
post
:resolve
,
request_params
expect
(
response
).
to
have_http_status
(
404
)
end
end
it
"returns the name of the resolving user"
do
post
:resolve
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
id:
note
.
id
context
"when the note is resolvable"
do
it
"resolves the note"
do
post
:resolve
,
request_params
expect
(
JSON
.
parse
(
response
.
body
)[
"resolved_by"
]).
to
eq
(
user
.
name
)
end
expect
(
note
.
reload
.
resolved?
).
to
be
true
expect
(
note
.
reload
.
resolved_by
).
to
eq
(
user
)
end
it
"returns status 200
"
do
post
:resolve
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
id:
note
.
id
it
"sends notifications if all discussions are resolved
"
do
expect_any_instance_of
(
MergeRequests
::
ResolvedDiscussionNotificationService
).
to
receive
(
:execute
).
with
(
merge_request
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
end
end
post
:resolve
,
request_params
end
describe
'DELETE unresolve'
do
before
do
sign_in
user
end
it
"returns the name of the resolving user"
do
post
:resolve
,
request_params
expect
(
JSON
.
parse
(
response
.
body
)[
"resolved_by"
]).
to
eq
(
user
.
name
)
end
context
"when the user is not authorized to resolve the note"
do
it
"returns status 404"
do
delete
:unresolve
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
id:
note
.
id
it
"returns status 200"
do
post
:resolve
,
request_params
expect
(
response
).
to
have_http_status
(
404
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
end
end
context
"when the user is authorized to resolve the note"
do
describe
'DELETE unresolve'
do
before
do
project
.
team
<<
[
user
,
:developer
]
sign_in
user
note
.
resolve!
(
user
)
end
context
"when the
note is not resolvabl
e"
do
context
"when the
user is not authorized to resolve the not
e"
do
it
"returns status 404"
do
delete
:unresolve
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
id:
note
.
id
delete
:unresolve
,
request_params
expect
(
response
).
to
have_http_status
(
404
)
end
end
context
"when the note is resolvable"
do
let
(
:merge_request
)
{
create
(
:merge_request
,
source_project:
project
)
}
let
(
:note
)
{
create
(
:diff_note_on_merge_request
,
noteable:
merge_request
,
project:
project
)
}
context
"when the user is authorized to resolve the note"
do
before
do
project
.
team
<<
[
user
,
:developer
]
end
context
"when the note is not resolvable"
do
before
do
note
.
update
(
system:
true
)
end
it
"unresolves the note
"
do
expect_any_instance_of
(
DiffNote
).
to
receive
(
:unresolve!
)
it
"returns status 404
"
do
delete
:unresolve
,
request_params
delete
:unresolve
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
id:
note
.
id
expect
(
response
).
to
have_http_status
(
404
)
end
end
it
"returns status 200"
do
delete
:unresolve
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
id:
note
.
id
context
"when the note is resolvable"
do
it
"unresolves the note"
do
delete
:unresolve
,
request_params
expect
(
note
.
reload
.
resolved?
).
to
be
false
end
it
"returns status 200"
do
delete
:unresolve
,
request_params
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
end
end
...
...
spec/models/diff_note_spec.rb
View file @
41007f6d
...
...
@@ -103,7 +103,7 @@ describe DiffNote, models: true do
describe
"#active?"
do
context
"when noteable is a commit"
do
subject
{
create
(
:diff_note_on_commit
,
project:
project
,
position:
position
)
}
subject
{
build
(
:diff_note_on_commit
,
project:
project
,
position:
position
)
}
it
"returns true"
do
expect
(
subject
.
active?
).
to
be
true
...
...
spec/services/merge_requests/
all_discussions_resolved_service_spec
.rb
→
spec/services/merge_requests/
resolved_discussion_notification_service
.rb
View file @
41007f6d
require
'spec_helper'
describe
MergeRequests
::
AllDiscussionsResolved
Service
,
services:
true
do
describe
MergeRequests
::
ResolvedDiscussionNotification
Service
,
services:
true
do
let
(
:merge_request
)
{
create
(
:merge_request
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
merge_request
.
project
}
...
...
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