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
d5993408
Commit
d5993408
authored
Apr 26, 2017
by
Oswaldo Ferreira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create RelatedIssues::DestroyService
parent
bf7ba36b
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
91 additions
and
2 deletions
+91
-2
app/services/related_issues/destroy_service.rb
app/services/related_issues/destroy_service.rb
+28
-0
app/services/system_note_service.rb
app/services/system_note_service.rb
+19
-2
spec/services/related_issues/destroy_service_spec.rb
spec/services/related_issues/destroy_service_spec.rb
+28
-0
spec/services/system_note_service_spec.rb
spec/services/system_note_service_spec.rb
+16
-0
No files found.
app/services/related_issues/destroy_service.rb
0 → 100644
View file @
d5993408
module
RelatedIssues
class
DestroyService
<
BaseService
def
initialize
(
related_issue
,
user
)
@related_issue
=
related_issue
@current_user
=
user
@issue
=
related_issue
.
issue
@referenced_issue
=
related_issue
.
related_issue
end
def
execute
remove_relation!
create_notes!
success
(
message:
'Relation was removed'
)
end
private
def
remove_relation!
@related_issue
.
destroy!
end
def
create_notes!
SystemNoteService
.
unrelate_issue
(
@issue
,
@referenced_issue
,
current_user
)
SystemNoteService
.
unrelate_issue
(
@referenced_issue
,
@issue
,
current_user
)
end
end
end
app/services/system_note_service.rb
View file @
d5993408
...
...
@@ -554,7 +554,8 @@ module SystemNoteService
#
# noteable - Noteable object
# user - User performing approve
# noteable_ref - Referenced noteable object
# user - User performing reference
#
# Example Note text:
#
...
...
@@ -567,6 +568,22 @@ module SystemNoteService
create_note
(
NoteSummary
.
new
(
noteable
,
noteable
.
project
,
user
,
body
,
action:
'relate'
))
end
#
# noteable - Noteable object
# noteable_ref - Referenced noteable object
# user - User performing reference
#
# Example Note text:
#
# "removed the relation with gitlab-ce#9001"
#
# Returns the created Note object
def
unrelate_issue
(
noteable
,
noteable_ref
,
user
)
body
=
"removed the relation with
#{
noteable_ref
.
to_reference
(
noteable
.
project
)
}
"
create_note
(
NoteSummary
.
new
(
noteable
,
noteable
.
project
,
user
,
body
,
action:
'relate'
))
end
# Called when the merge request is approved by user
#
# noteable - Noteable object
...
...
spec/services/related_issues/destroy_service_spec.rb
0 → 100644
View file @
d5993408
require
'spec_helper'
describe
RelatedIssues
::
DestroyService
,
service:
true
do
describe
'#execute'
do
let
(
:user
)
{
create
:user
}
let!
(
:related_issue
)
{
create
:related_issue
}
subject
{
described_class
.
new
(
related_issue
,
user
).
execute
}
it
'remove related issue'
do
expect
{
subject
}.
to
change
(
RelatedIssue
,
:count
).
from
(
1
).
to
(
0
)
end
it
'create notes'
do
# Two-way notes creation
expect
(
SystemNoteService
).
to
receive
(
:unrelate_issue
)
.
with
(
related_issue
.
issue
,
related_issue
.
related_issue
,
user
)
expect
(
SystemNoteService
).
to
receive
(
:unrelate_issue
)
.
with
(
related_issue
.
related_issue
,
related_issue
.
issue
,
user
)
subject
end
it
'returns success message'
do
is_expected
.
to
eq
(
message:
'Relation was removed'
,
status: :success
)
end
end
end
spec/services/system_note_service_spec.rb
View file @
d5993408
...
...
@@ -915,6 +915,22 @@ describe SystemNoteService, services: true do
end
end
describe
'.unrelate_issue'
do
let
(
:noteable_ref
)
{
create
(
:issue
)
}
subject
{
described_class
.
unrelate_issue
(
noteable
,
noteable_ref
,
author
)
}
it_behaves_like
'a system note'
do
let
(
:action
)
{
'unrelate'
}
end
context
'when issue relation is removed'
do
it
'sets the note text'
do
expect
(
subject
.
note
).
to
eq
"removed the relation with
#{
noteable_ref
.
to_reference
(
project
)
}
"
end
end
end
describe
'.approve_mr'
do
let
(
:noteable
)
{
create
(
:merge_request
,
source_project:
project
)
}
subject
{
described_class
.
approve_mr
(
noteable
,
author
)
}
...
...
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