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
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
Show 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
...
@@ -9,7 +9,7 @@ class Projects::DiscussionsController < Projects::ApplicationController
discussion
.
resolve!
(
current_user
)
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:
{
render
json:
{
resolved_by:
discussion
.
resolved_by
.
try
(
:name
),
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
...
@@ -72,7 +72,7 @@ class Projects::NotesController < Projects::ApplicationController
note
.
resolve!
(
current_user
)
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
discussion
=
note
.
discussion
...
@@ -166,7 +166,7 @@ class Projects::NotesController < Projects::ApplicationController
...
@@ -166,7 +166,7 @@ class Projects::NotesController < Projects::ApplicationController
}
}
if
note
.
diff_note?
if
note
.
diff_note?
discussion
=
note
.
as
_discussion
discussion
=
note
.
to
_discussion
attrs
.
merge!
(
attrs
.
merge!
(
diff_discussion_html:
diff_discussion_html
(
discussion
),
diff_discussion_html:
diff_discussion_html
(
discussion
),
...
...
app/models/diff_note.rb
View file @
41007f6d
...
@@ -113,7 +113,7 @@ class DiffNote < Note
...
@@ -113,7 +113,7 @@ class DiffNote < Note
Discussion
.
new
(
discussion_notes
)
Discussion
.
new
(
discussion_notes
)
end
end
def
as
_discussion
def
to
_discussion
Discussion
.
new
([
self
])
Discussion
.
new
([
self
])
end
end
...
...
app/models/discussion.rb
View file @
41007f6d
...
@@ -58,6 +58,8 @@ class Discussion
...
@@ -58,6 +58,8 @@ class Discussion
first_note
.
discussion_id
first_note
.
discussion_id
end
end
alias_method
:to_param
,
:id
def
diff_discussion?
def
diff_discussion?
first_note
.
diff_note?
first_note
.
diff_note?
end
end
...
...
app/services/merge_requests/
all_discussions_resolved
_service.rb
→
app/services/merge_requests/
resolved_discussion_notification
_service.rb
View file @
41007f6d
module
MergeRequests
module
MergeRequests
class
AllDiscussionsResolved
Service
<
MergeRequests
::
BaseService
class
ResolvedDiscussionNotification
Service
<
MergeRequests
::
BaseService
def
execute
(
merge_request
)
def
execute
(
merge_request
)
return
unless
merge_request
.
discussions_resolved?
return
unless
merge_request
.
discussions_resolved?
...
...
spec/controllers/projects/discussions_controller_spec.rb
View file @
41007f6d
...
@@ -5,6 +5,16 @@ describe Projects::DiscussionsController do
...
@@ -5,6 +5,16 @@ describe Projects::DiscussionsController do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:merge_request
)
{
create
(
:merge_request
,
source_project:
project
)
}
let
(
:merge_request
)
{
create
(
:merge_request
,
source_project:
project
)
}
let
(
:note
)
{
create
(
:diff_note_on_merge_request
,
noteable:
merge_request
,
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
describe
'POST resolve'
do
before
do
before
do
...
@@ -13,7 +23,7 @@ describe Projects::DiscussionsController do
...
@@ -13,7 +23,7 @@ describe Projects::DiscussionsController do
context
"when the user is not authorized to resolve the discussion"
do
context
"when the user is not authorized to resolve the discussion"
do
it
"returns status 404"
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
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
@@ -30,7 +40,7 @@ describe Projects::DiscussionsController do
...
@@ -30,7 +40,7 @@ describe Projects::DiscussionsController do
end
end
it
"returns status 404"
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
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
@@ -38,25 +48,26 @@ describe Projects::DiscussionsController do
...
@@ -38,25 +48,26 @@ describe Projects::DiscussionsController do
context
"when the discussion is resolvable"
do
context
"when the discussion is resolvable"
do
it
"resolves the discussion"
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
end
it
"
checks whether all note
s are resolved"
do
it
"
sends notifications if all discussion
s are resolved"
do
expect_any_instance_of
(
MergeRequests
::
AllDiscussionsResolved
Service
).
to
receive
(
:execute
).
with
(
merge_request
)
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
end
it
"returns the name of the resolving user"
do
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
)
expect
(
JSON
.
parse
(
response
.
body
)[
"resolved_by"
]).
to
eq
(
user
.
name
)
end
end
it
"returns status 200"
do
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
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
...
@@ -67,11 +78,13 @@ describe Projects::DiscussionsController do
...
@@ -67,11 +78,13 @@ describe Projects::DiscussionsController do
describe
'DELETE unresolve'
do
describe
'DELETE unresolve'
do
before
do
before
do
sign_in
user
sign_in
user
note
.
discussion
.
resolve!
(
user
)
end
end
context
"when the user is not authorized to resolve the discussion"
do
context
"when the user is not authorized to resolve the discussion"
do
it
"returns status 404"
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
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
@@ -88,7 +101,7 @@ describe Projects::DiscussionsController do
...
@@ -88,7 +101,7 @@ describe Projects::DiscussionsController do
end
end
it
"returns status 404"
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
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
@@ -96,13 +109,13 @@ describe Projects::DiscussionsController do
...
@@ -96,13 +109,13 @@ describe Projects::DiscussionsController do
context
"when the discussion is resolvable"
do
context
"when the discussion is resolvable"
do
it
"unresolves the discussion"
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
end
it
"returns status 200"
do
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
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
...
...
spec/controllers/projects/notes_controller_spec.rb
View file @
41007f6d
...
@@ -6,6 +6,14 @@ describe Projects::NotesController do
...
@@ -6,6 +6,14 @@ describe Projects::NotesController do
let
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:note
)
{
create
(
:note
,
noteable:
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
describe
'POST toggle_award_emoji'
do
before
do
before
do
sign_in
(
user
)
sign_in
(
user
)
...
@@ -14,26 +22,27 @@ describe Projects::NotesController do
...
@@ -14,26 +22,27 @@ describe Projects::NotesController do
it
"toggles the award emoji"
do
it
"toggles the award emoji"
do
expect
do
expect
do
post
(
:toggle_award_emoji
,
namespace_id:
project
.
namespace
.
path
,
post
(
:toggle_award_emoji
,
request_params
.
merge
(
name:
"thumbsup"
))
project_id:
project
.
path
,
id:
note
.
id
,
name:
"thumbsup"
)
end
.
to
change
{
note
.
award_emoji
.
count
}.
by
(
1
)
end
.
to
change
{
note
.
award_emoji
.
count
}.
by
(
1
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
it
"removes the already awarded emoji"
do
it
"removes the already awarded emoji"
do
post
(
:toggle_award_emoji
,
namespace_id:
project
.
namespace
.
path
,
post
(
:toggle_award_emoji
,
request_params
.
merge
(
name:
"thumbsup"
))
project_id:
project
.
path
,
id:
note
.
id
,
name:
"thumbsup"
)
expect
do
expect
do
post
(
:toggle_award_emoji
,
namespace_id:
project
.
namespace
.
path
,
post
(
:toggle_award_emoji
,
request_params
.
merge
(
name:
"thumbsup"
))
project_id:
project
.
path
,
id:
note
.
id
,
name:
"thumbsup"
)
end
.
to
change
{
AwardEmoji
.
count
}.
by
(
-
1
)
end
.
to
change
{
AwardEmoji
.
count
}.
by
(
-
1
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
end
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
)
}
describe
'POST resolve'
do
describe
'POST resolve'
do
before
do
before
do
sign_in
user
sign_in
user
...
@@ -41,7 +50,7 @@ describe Projects::NotesController do
...
@@ -41,7 +50,7 @@ describe Projects::NotesController do
context
"when the user is not authorized to resolve the note"
do
context
"when the user is not authorized to resolve the note"
do
it
"returns status 404"
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
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
@@ -53,37 +62,39 @@ describe Projects::NotesController do
...
@@ -53,37 +62,39 @@ describe Projects::NotesController do
end
end
context
"when the note is not resolvable"
do
context
"when the note is not resolvable"
do
before
do
note
.
update
(
system:
true
)
end
it
"returns status 404"
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
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
end
context
"when the note is resolvable"
do
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
it
"resolves the note"
do
expect_any_instance_of
(
DiffNote
).
to
receive
(
:resolve!
).
with
(
user
)
post
:resolve
,
request_params
post
:resolve
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
id:
note
.
id
expect
(
note
.
reload
.
resolved?
).
to
be
true
expect
(
note
.
reload
.
resolved_by
).
to
eq
(
user
)
end
end
it
"checks whether all note
s are resolved"
do
it
"sends notifications if all discussion
s are resolved"
do
expect_any_instance_of
(
MergeRequests
::
AllDiscussionsResolved
Service
).
to
receive
(
:execute
).
with
(
merge_request
)
expect_any_instance_of
(
MergeRequests
::
ResolvedDiscussionNotification
Service
).
to
receive
(
:execute
).
with
(
merge_request
)
post
:resolve
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
id:
note
.
id
post
:resolve
,
request_params
end
end
it
"returns the name of the resolving user"
do
it
"returns the name of the resolving user"
do
post
:resolve
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
id:
note
.
id
post
:resolve
,
request_params
expect
(
JSON
.
parse
(
response
.
body
)[
"resolved_by"
]).
to
eq
(
user
.
name
)
expect
(
JSON
.
parse
(
response
.
body
)[
"resolved_by"
]).
to
eq
(
user
.
name
)
end
end
it
"returns status 200"
do
it
"returns status 200"
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
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
...
@@ -94,11 +105,13 @@ describe Projects::NotesController do
...
@@ -94,11 +105,13 @@ describe Projects::NotesController do
describe
'DELETE unresolve'
do
describe
'DELETE unresolve'
do
before
do
before
do
sign_in
user
sign_in
user
note
.
resolve!
(
user
)
end
end
context
"when the user is not authorized to resolve the note"
do
context
"when the user is not authorized to resolve the note"
do
it
"returns status 404"
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
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
@@ -110,29 +123,31 @@ describe Projects::NotesController do
...
@@ -110,29 +123,31 @@ describe Projects::NotesController do
end
end
context
"when the note is not resolvable"
do
context
"when the note is not resolvable"
do
before
do
note
.
update
(
system:
true
)
end
it
"returns status 404"
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
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
end
context
"when the note is resolvable"
do
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
"unresolves the note"
do
it
"unresolves the note"
do
expect_any_instance_of
(
DiffNote
).
to
receive
(
:unresolve!
)
delete
:unresolve
,
request_params
delete
:unresolve
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
id:
note
.
id
expect
(
note
.
reload
.
resolved?
).
to
be
false
end
end
it
"returns status 200"
do
it
"returns status 200"
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
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
end
end
end
end
end
end
end
end
end
spec/models/diff_note_spec.rb
View file @
41007f6d
...
@@ -103,7 +103,7 @@ describe DiffNote, models: true do
...
@@ -103,7 +103,7 @@ describe DiffNote, models: true do
describe
"#active?"
do
describe
"#active?"
do
context
"when noteable is a commit"
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
it
"returns true"
do
expect
(
subject
.
active?
).
to
be
true
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'
require
'spec_helper'
describe
MergeRequests
::
AllDiscussionsResolved
Service
,
services:
true
do
describe
MergeRequests
::
ResolvedDiscussionNotification
Service
,
services:
true
do
let
(
:merge_request
)
{
create
(
:merge_request
)
}
let
(
:merge_request
)
{
create
(
:merge_request
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
merge_request
.
project
}
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