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
5d0450d8
Commit
5d0450d8
authored
May 30, 2017
by
Oswaldo Ferreira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Save relations whenever possible (dropping transaction)
parent
c97f060c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
63 deletions
+17
-63
app/services/issue_links/create_service.rb
app/services/issue_links/create_service.rb
+4
-20
spec/requests/projects/issue_links_controller_spec.rb
spec/requests/projects/issue_links_controller_spec.rb
+5
-4
spec/services/issue_links/create_service_spec.rb
spec/services/issue_links/create_service_spec.rb
+8
-39
No files found.
app/services/issue_links/create_service.rb
View file @
5d0450d8
...
...
@@ -10,25 +10,19 @@ module IssueLinks
end
create_issue_link
success_message
rescue
=>
exception
error
(
exception
.
message
,
401
)
success
end
private
def
create_issue_link
IssueLink
.
transaction
do
referenced_issues
.
each
do
|
referenced_issue
|
relate_issues
(
referenced_issue
)
create_notes
(
referenced_issue
)
end
referenced_issues
.
each
do
|
referenced_issue
|
create_notes
(
referenced_issue
)
if
relate_issues
(
referenced_issue
)
end
end
def
relate_issues
(
referenced_issue
)
IssueLink
.
create
!
(
source:
@issue
,
target:
referenced_issue
)
IssueLink
.
create
(
source:
@issue
,
target:
referenced_issue
)
end
def
create_notes
(
referenced_issue
)
...
...
@@ -49,15 +43,5 @@ module IssueLinks
end
end
end
def
success_message
verb
=
referenced_issues
.
size
>
1
?
'were'
:
'was'
success
(
message:
"
#{
issues_sentence
(
referenced_issues
)
}
#{
verb
}
successfully related"
)
end
def
issues_sentence
(
issues
)
issues
.
map
{
|
issue
|
issue
.
to_reference
(
@issue
.
project
)
}.
sort
.
to_sentence
end
end
end
spec/requests/projects/issue_links_controller_spec.rb
View file @
5d0450d8
...
...
@@ -38,6 +38,7 @@ describe Projects::IssueLinksController do
describe
'POST /*namespace_id/:project_id/issues/:issue_id/links'
do
let
(
:issue_b
)
{
create
:issue
,
project:
project
}
let
(
:issue_references
)
{
[
issue_b
.
to_reference
]
}
let
(
:user_role
)
{
:developer
}
before
do
...
...
@@ -49,7 +50,7 @@ describe Projects::IssueLinksController do
post
namespace_project_issue_links_path
(
namespace_id:
issue
.
project
.
namespace
,
project_id:
issue
.
project
,
issue_id:
issue
,
issue_references:
[
issue_b
.
to_reference
]
,
issue_references:
issue_references
,
format: :json
)
end
...
...
@@ -60,7 +61,7 @@ describe Projects::IssueLinksController do
list_service_response
=
IssueLinks
::
ListService
.
new
(
issue
,
user
).
execute
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'result'
]).
to
eq
(
'
message'
=>
"
#{
issue_b
.
to_reference
}
was successfully related"
,
'
status'
=>
'success'
)
expect
(
json_response
[
'result'
]).
to
eq
(
'status'
=>
'success'
)
expect
(
json_response
[
'issues'
]).
to
eq
(
list_service_response
.
as_json
)
end
end
...
...
@@ -77,7 +78,7 @@ describe Projects::IssueLinksController do
end
context
'when failing service result'
do
let
(
:issue_
b
)
{
issue
}
let
(
:issue_
references
)
{
[
'#999'
]
}
it
'returns failure JSON'
do
subject
...
...
@@ -85,7 +86,7 @@ describe Projects::IssueLinksController do
list_service_response
=
IssueLinks
::
ListService
.
new
(
issue
,
user
).
execute
expect
(
response
).
to
have_http_status
(
401
)
expect
(
json_response
[
'result'
]).
to
eq
(
'message'
=>
"Validation failed: Source issue cannot be related to itself"
,
expect
(
json_response
[
'result'
]).
to
eq
(
'message'
=>
'No Issue found for given reference'
,
'status'
=>
'error'
,
'http_status'
=>
401
)
expect
(
json_response
[
'issues'
]).
to
eq
(
list_service_response
.
as_json
)
...
...
spec/services/issue_links/create_service_spec.rb
View file @
5d0450d8
...
...
@@ -85,7 +85,7 @@ describe IssueLinks::CreateService, service: true do
end
it
'returns success message with Issue reference'
do
is_expected
.
to
eq
(
message:
"
#{
issue_a_ref
}
and
#{
another_project_issue_ref
}
were successfully related"
,
status: :success
)
is_expected
.
to
eq
(
status: :success
)
end
it
'creates notes'
do
...
...
@@ -105,40 +105,7 @@ describe IssueLinks::CreateService, service: true do
end
end
context
'success message'
do
let
(
:issue_a
)
{
create
:issue
,
project:
project
}
let
(
:another_project
)
{
create
:empty_project
,
namespace:
project
.
namespace
}
let
(
:another_project_issue
)
{
create
:issue
,
project:
another_project
}
let
(
:issue_a_ref
)
{
issue_a
.
to_reference
}
let
(
:another_project_issue_ref
)
{
another_project_issue
.
to_reference
(
project
)
}
before
do
another_project
.
team
<<
[
user
,
:developer
]
end
context
'multiple Issues relation'
do
let
(
:params
)
do
{
issue_references:
[
issue_a_ref
,
another_project_issue_ref
]
}
end
it
'returns success message with Issue reference'
do
is_expected
.
to
eq
(
message:
"
#{
issue_a_ref
}
and
#{
another_project_issue_ref
}
were successfully related"
,
status: :success
)
end
end
context
'single Issue relation'
do
let
(
:params
)
do
{
issue_references:
[
issue_a_ref
]
}
end
it
'returns success message with Issue reference'
do
is_expected
.
to
eq
(
message:
"
#{
issue_a_ref
}
was successfully related"
,
status: :success
)
end
end
end
context
'when relation already exists'
do
context
'when reference of any already related issue is present'
do
let
(
:issue_a
)
{
create
:issue
,
project:
project
}
let
(
:issue_b
)
{
create
:issue
,
project:
project
}
...
...
@@ -150,12 +117,14 @@ describe IssueLinks::CreateService, service: true do
{
issue_references:
[
issue_b
.
to_reference
,
issue_a
.
to_reference
]
}
end
it
'returns
error
'
do
is_expected
.
to
eq
(
message:
'Validation failed: Source issue is already related'
,
status: :error
,
http_status:
401
)
it
'returns
success
'
do
is_expected
.
to
eq
(
status: :success
)
end
it
'no relation is created'
do
expect
{
subject
}.
not_to
change
(
IssueLink
,
:count
)
it
'valid relations are created'
do
expect
{
subject
}.
to
change
(
IssueLink
,
:count
).
from
(
1
).
to
(
2
)
expect
(
IssueLink
.
find_by!
(
target:
issue_b
)).
to
have_attributes
(
source:
issue
)
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