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
91a735d4
Commit
91a735d4
authored
May 24, 2017
by
Oswaldo Ferreira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename models, namespaces, routes to new IssueLink pattern
parent
7afdb317
Changes
17
Show whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
204 additions
and
114 deletions
+204
-114
app/controllers/projects/issue_links_controller.rb
app/controllers/projects/issue_links_controller.rb
+55
-0
app/models/issue_link.rb
app/models/issue_link.rb
+19
-0
app/models/related_issue.rb
app/models/related_issue.rb
+0
-19
app/policies/project_policy.rb
app/policies/project_policy.rb
+3
-3
app/services/issue_links/create_service.rb
app/services/issue_links/create_service.rb
+5
-5
app/services/issue_links/destroy_service.rb
app/services/issue_links/destroy_service.rb
+6
-6
app/services/issue_links/list_service.rb
app/services/issue_links/list_service.rb
+13
-13
config/locales/en.yml
config/locales/en.yml
+5
-0
config/routes/project.rb
config/routes/project.rb
+1
-1
spec/controllers/projects/issue_links_controller_spec.rb
spec/controllers/projects/issue_links_controller_spec.rb
+14
-14
spec/factories/issue_links.rb
spec/factories/issue_links.rb
+6
-0
spec/factories/related_issues.rb
spec/factories/related_issues.rb
+0
-6
spec/models/issue_link_spec.rb
spec/models/issue_link_spec.rb
+30
-0
spec/policies/project_policy_spec.rb
spec/policies/project_policy_spec.rb
+3
-3
spec/services/issue_links/create_service_spec.rb
spec/services/issue_links/create_service_spec.rb
+9
-9
spec/services/issue_links/destroy_service_spec.rb
spec/services/issue_links/destroy_service_spec.rb
+6
-6
spec/services/issue_links/list_service_spec.rb
spec/services/issue_links/list_service_spec.rb
+29
-29
No files found.
app/controllers/projects/
related_issue
s_controller.rb
→
app/controllers/projects/
issue_link
s_controller.rb
View file @
91a735d4
module
Projects
module
Projects
class
RelatedIssue
sController
<
ApplicationController
class
IssueLink
sController
<
ApplicationController
before_action
:authorize_read_
related_issue
!
before_action
:authorize_read_
issue_link
!
before_action
:authorize_admin_
related_issue
!
,
only:
[
:create
,
:destroy
]
before_action
:authorize_admin_
issue_link
!
,
only:
[
:create
,
:destroy
]
def
index
def
index
render
json:
issues
render
json:
issues
...
@@ -9,7 +9,7 @@ module Projects
...
@@ -9,7 +9,7 @@ module Projects
def
create
def
create
opts
=
params
.
slice
(
:issue_references
)
opts
=
params
.
slice
(
:issue_references
)
result
=
RelatedIssue
s
::
CreateService
.
new
(
issue
,
current_user
,
opts
).
execute
result
=
IssueLink
s
::
CreateService
.
new
(
issue
,
current_user
,
opts
).
execute
if
result
[
:status
]
==
:success
if
result
[
:status
]
==
:success
render
json:
{
result:
result
,
issues:
issues
},
status:
result
[
:http_status
]
render
json:
{
result:
result
,
issues:
issues
},
status:
result
[
:http_status
]
...
@@ -19,13 +19,13 @@ module Projects
...
@@ -19,13 +19,13 @@ module Projects
end
end
def
destroy
def
destroy
related_issue
=
RelatedIssue
.
find
(
params
[
:id
])
issue_link
=
IssueLink
.
find
(
params
[
:id
])
# In order to remove a given relation, one must be allowed to admin_
related_issue
both the current
# In order to remove a given relation, one must be allowed to admin_
issue_link
both the current
# project and on the related issue project.
# project and on the related issue project.
return
render_404
unless
can?
(
current_user
,
:admin_
related_issue
,
related_issue
.
related_issue
.
project
)
return
render_404
unless
can?
(
current_user
,
:admin_
issue_link
,
issue_link
.
target
.
project
)
result
=
RelatedIssues
::
DestroyService
.
new
(
related_issue
,
current_user
).
execute
result
=
IssueLinks
::
DestroyService
.
new
(
issue_link
,
current_user
).
execute
render
json:
{
result:
result
,
issues:
issues
}
render
json:
{
result:
result
,
issues:
issues
}
end
end
...
@@ -33,15 +33,15 @@ module Projects
...
@@ -33,15 +33,15 @@ module Projects
private
private
def
issues
def
issues
RelatedIssue
s
::
ListService
.
new
(
issue
,
current_user
).
execute
IssueLink
s
::
ListService
.
new
(
issue
,
current_user
).
execute
end
end
def
authorize_admin_
related_issue
!
def
authorize_admin_
issue_link
!
render_404
unless
can?
(
current_user
,
:admin_
related_issue
,
@project
)
render_404
unless
can?
(
current_user
,
:admin_
issue_link
,
@project
)
end
end
def
authorize_read_
related_issue
!
def
authorize_read_
issue_link
!
render_404
unless
can?
(
current_user
,
:read_
related_issue
,
@project
)
render_404
unless
can?
(
current_user
,
:read_
issue_link
,
@project
)
end
end
def
issue
def
issue
...
...
app/models/issue_link.rb
0 → 100644
View file @
91a735d4
class
IssueLink
<
ActiveRecord
::
Base
belongs_to
:source
,
class_name:
'Issue'
belongs_to
:target
,
class_name:
'Issue'
validates
:source
,
presence:
true
validates
:target
,
presence:
true
validates
:source
,
uniqueness:
{
scope: :target_id
,
message:
'is already related'
}
validate
:check_self_relation
private
def
check_self_relation
return
unless
source
||
target
if
source
==
target
errors
.
add
(
:source
,
'cannot be related to itself'
)
end
end
end
app/models/related_issue.rb
deleted
100644 → 0
View file @
7afdb317
class
RelatedIssue
<
ActiveRecord
::
Base
belongs_to
:issue
belongs_to
:related_issue
,
class_name:
'Issue'
validates
:issue
,
presence:
true
validates
:related_issue
,
presence:
true
validates
:issue
,
uniqueness:
{
scope: :related_issue_id
,
message:
'is already related'
}
validate
:check_self_relation
private
def
check_self_relation
return
unless
issue
||
related_issue
if
issue
==
related_issue
errors
.
add
(
:issue
,
'cannot be related to itself'
)
end
end
end
app/policies/project_policy.rb
View file @
91a735d4
...
@@ -57,7 +57,7 @@ class ProjectPolicy < BasePolicy
...
@@ -57,7 +57,7 @@ class ProjectPolicy < BasePolicy
end
end
# EE-only
# EE-only
can!
:read_
related_issue
can!
:read_
issue_link
end
end
def
reporter_access!
def
reporter_access!
...
@@ -84,7 +84,7 @@ class ProjectPolicy < BasePolicy
...
@@ -84,7 +84,7 @@ class ProjectPolicy < BasePolicy
end
end
# EE-only
# EE-only
can!
:admin_
related_issue
can!
:admin_
issue_link
end
end
# Permissions given when an user is team member of a project
# Permissions given when an user is team member of a project
...
@@ -329,6 +329,6 @@ class ProjectPolicy < BasePolicy
...
@@ -329,6 +329,6 @@ class ProjectPolicy < BasePolicy
can!
:read_issue
can!
:read_issue
# EE-only
# EE-only
can!
:read_
related_issue
can!
:read_
issue_link
end
end
end
end
app/services/
related_issue
s/create_service.rb
→
app/services/
issue_link
s/create_service.rb
View file @
91a735d4
module
RelatedIssue
s
module
IssueLink
s
class
CreateService
<
BaseService
class
CreateService
<
BaseService
def
initialize
(
issue
,
user
,
params
)
def
initialize
(
issue
,
user
,
params
)
@issue
,
@current_user
,
@params
=
issue
,
user
,
params
.
dup
@issue
,
@current_user
,
@params
=
issue
,
user
,
params
.
dup
...
@@ -9,7 +9,7 @@ module RelatedIssues
...
@@ -9,7 +9,7 @@ module RelatedIssues
return
error
(
'No Issue found for given reference'
,
401
)
return
error
(
'No Issue found for given reference'
,
401
)
end
end
create_
related_issues
create_
issue_link
success_message
success_message
rescue
=>
exception
rescue
=>
exception
...
@@ -18,8 +18,8 @@ module RelatedIssues
...
@@ -18,8 +18,8 @@ module RelatedIssues
private
private
def
create_
related_issues
def
create_
issue_link
RelatedIssue
.
transaction
do
IssueLink
.
transaction
do
referenced_issues
.
each
do
|
referenced_issue
|
referenced_issues
.
each
do
|
referenced_issue
|
relate_issues
(
referenced_issue
)
relate_issues
(
referenced_issue
)
create_notes
(
referenced_issue
)
create_notes
(
referenced_issue
)
...
@@ -28,7 +28,7 @@ module RelatedIssues
...
@@ -28,7 +28,7 @@ module RelatedIssues
end
end
def
relate_issues
(
referenced_issue
)
def
relate_issues
(
referenced_issue
)
RelatedIssue
.
create!
(
issue:
@issue
,
related_issue
:
referenced_issue
)
IssueLink
.
create!
(
source:
@issue
,
target
:
referenced_issue
)
end
end
def
create_notes
(
referenced_issue
)
def
create_notes
(
referenced_issue
)
...
...
app/services/
related_issue
s/destroy_service.rb
→
app/services/
issue_link
s/destroy_service.rb
View file @
91a735d4
module
RelatedIssue
s
module
IssueLink
s
class
DestroyService
<
BaseService
class
DestroyService
<
BaseService
def
initialize
(
related_issue
,
user
)
def
initialize
(
issue_link
,
user
)
@
related_issue
=
related_issue
@
issue_link
=
issue_link
@current_user
=
user
@current_user
=
user
@issue
=
related_issue
.
issu
e
@issue
=
issue_link
.
sourc
e
@referenced_issue
=
related_issue
.
related_issue
@referenced_issue
=
issue_link
.
target
end
end
def
execute
def
execute
...
@@ -17,7 +17,7 @@ module RelatedIssues
...
@@ -17,7 +17,7 @@ module RelatedIssues
private
private
def
remove_relation!
def
remove_relation!
@
related_issue
.
destroy!
@
issue_link
.
destroy!
end
end
def
create_notes!
def
create_notes!
...
...
app/services/
related_issue
s/list_service.rb
→
app/services/
issue_link
s/list_service.rb
View file @
91a735d4
module
RelatedIssue
s
module
IssueLink
s
class
ListService
class
ListService
include
Gitlab
::
Routing
include
Gitlab
::
Routing
...
@@ -29,14 +29,14 @@ module RelatedIssues
...
@@ -29,14 +29,14 @@ module RelatedIssues
# TODO: Simplify query using AR
# TODO: Simplify query using AR
@issues
=
Issue
.
find_by_sql
(
@issues
=
Issue
.
find_by_sql
(
<<-
SQL
.
strip_heredoc
<<-
SQL
.
strip_heredoc
SELECT issues.*,
related_issues.id as related_issue
s_id FROM issues
SELECT issues.*,
issue_links.id as issue_link
s_id FROM issues
INNER JOIN
related_issues ON related_issues.related_issue
_id = issues.id
INNER JOIN
issue_links ON issue_links.target
_id = issues.id
WHERE
related_issues.issu
e_id =
#{
@issue
.
id
}
AND issues.deleted_at IS NULL
WHERE
issue_links.sourc
e_id =
#{
@issue
.
id
}
AND issues.deleted_at IS NULL
UNION ALL
UNION ALL
SELECT issues.*,
related_issues.id as related_issue
s_id FROM issues
SELECT issues.*,
issue_links.id as issue_link
s_id FROM issues
INNER JOIN
related_issues ON related_issues.issu
e_id = issues.id
INNER JOIN
issue_links ON issue_links.sourc
e_id = issues.id
WHERE
related_issues.related_issue
_id =
#{
@issue
.
id
}
AND issues.deleted_at IS NULL
WHERE
issue_links.target
_id =
#{
@issue
.
id
}
AND issues.deleted_at IS NULL
ORDER BY
related_issue
s_id
ORDER BY
issue_link
s_id
SQL
SQL
)
)
...
@@ -45,12 +45,12 @@ module RelatedIssues
...
@@ -45,12 +45,12 @@ module RelatedIssues
end
end
def
destroy_relation_path
(
issue
)
def
destroy_relation_path
(
issue
)
return
unless
Ability
.
allowed?
(
@current_user
,
:admin_
related_issue
,
issue
.
project
)
return
unless
Ability
.
allowed?
(
@current_user
,
:admin_
issue_link
,
issue
.
project
)
namespace_project_issue_
related_issue
_path
(
issue
.
project
.
namespace
,
namespace_project_issue_
link
_path
(
issue
.
project
.
namespace
,
issue
.
project
,
issue
.
project
,
issue
.
iid
,
issue
.
iid
,
issue
.
related_issue
s_id
)
issue
.
issue_link
s_id
)
end
end
end
end
end
end
config/locales/en.yml
View file @
91a735d4
...
@@ -3,6 +3,11 @@
...
@@ -3,6 +3,11 @@
en
:
en
:
hello
:
"
Hello
world"
hello
:
"
Hello
world"
activerecord
:
attributes
:
issue_link
:
source
:
Source issue
target
:
Target issue
errors
:
errors
:
messages
:
messages
:
label_already_exists_at_group_level
:
"
already
exists
at
group
level
for
%{group}.
Please
choose
another
one."
label_already_exists_at_group_level
:
"
already
exists
at
group
level
for
%{group}.
Please
choose
another
one."
...
...
config/routes/project.rb
View file @
91a735d4
...
@@ -312,7 +312,7 @@ constraints(ProjectUrlConstrainer.new) do
...
@@ -312,7 +312,7 @@ constraints(ProjectUrlConstrainer.new) do
post
:export_csv
post
:export_csv
end
end
resources
:
related_issues
,
only:
[
:index
,
:create
,
:destroy
]
resources
:
issue_links
,
only:
[
:index
,
:create
,
:destroy
],
as:
'links'
,
path:
'links'
end
end
resources
:project_members
,
except:
[
:show
,
:new
,
:edit
],
constraints:
{
id:
/[a-zA-Z.\/0-9_\-#%+]+/
},
concerns: :access_requestable
do
resources
:project_members
,
except:
[
:show
,
:new
,
:edit
],
constraints:
{
id:
/[a-zA-Z.\/0-9_\-#%+]+/
},
concerns: :access_requestable
do
...
...
spec/controllers/projects/
related_issue
s_controller_spec.rb
→
spec/controllers/projects/
issue_link
s_controller_spec.rb
View file @
91a735d4
require
'rails_helper'
require
'rails_helper'
describe
Projects
::
RelatedIssue
sController
,
type: :controller
do
describe
Projects
::
IssueLink
sController
,
type: :controller
do
let
(
:user
)
{
create
:user
}
let
(
:user
)
{
create
:user
}
let
(
:project
)
{
create
(
:project_empty_repo
)
}
let
(
:project
)
{
create
(
:project_empty_repo
)
}
let
(
:issue
)
{
create
:issue
,
project:
project
}
let
(
:issue
)
{
create
:issue
,
project:
project
}
describe
'GET #index'
do
describe
'GET #index'
do
let
(
:service
)
{
double
(
RelatedIssue
s
::
ListService
,
execute:
service_response
)
}
let
(
:service
)
{
double
(
IssueLink
s
::
ListService
,
execute:
service_response
)
}
let
(
:service_response
)
{
[{
'foo'
=>
'bar'
}]
}
let
(
:service_response
)
{
[{
'foo'
=>
'bar'
}]
}
before
do
before
do
project
.
team
<<
[
user
,
:guest
]
project
.
team
<<
[
user
,
:guest
]
sign_in
user
sign_in
user
allow
(
RelatedIssue
s
::
ListService
).
to
receive
(
:new
)
allow
(
IssueLink
s
::
ListService
).
to
receive
(
:new
)
.
with
(
issue
,
user
)
.
with
(
issue
,
user
)
.
and_return
(
service
)
.
and_return
(
service
)
end
end
...
@@ -32,8 +32,8 @@ describe Projects::RelatedIssuesController, type: :controller do
...
@@ -32,8 +32,8 @@ describe Projects::RelatedIssuesController, type: :controller do
end
end
describe
'POST #create'
do
describe
'POST #create'
do
let
(
:service
)
{
double
(
RelatedIssue
s
::
CreateService
,
execute:
service_response
)
}
let
(
:service
)
{
double
(
IssueLink
s
::
CreateService
,
execute:
service_response
)
}
let
(
:list_service
)
{
double
(
RelatedIssue
s
::
ListService
,
execute:
list_service_response
)
}
let
(
:list_service
)
{
double
(
IssueLink
s
::
ListService
,
execute:
list_service_response
)
}
let
(
:service_response
)
{
{
message:
'yay'
,
status: :success
}
}
let
(
:service_response
)
{
{
message:
'yay'
,
status: :success
}
}
let
(
:list_service_response
)
{
[{
'foo'
=>
'bar'
}]
}
let
(
:list_service_response
)
{
[{
'foo'
=>
'bar'
}]
}
let
(
:issue_references
)
{
double
}
let
(
:issue_references
)
{
double
}
...
@@ -43,11 +43,11 @@ describe Projects::RelatedIssuesController, type: :controller do
...
@@ -43,11 +43,11 @@ describe Projects::RelatedIssuesController, type: :controller do
project
.
team
<<
[
user
,
user_role
]
project
.
team
<<
[
user
,
user_role
]
sign_in
user
sign_in
user
allow
(
RelatedIssue
s
::
ListService
).
to
receive
(
:new
)
allow
(
IssueLink
s
::
ListService
).
to
receive
(
:new
)
.
with
(
issue
,
user
)
.
with
(
issue
,
user
)
.
and_return
(
list_service
)
.
and_return
(
list_service
)
allow
(
RelatedIssue
s
::
CreateService
).
to
receive
(
:new
)
allow
(
IssueLink
s
::
CreateService
).
to
receive
(
:new
)
.
with
(
issue
,
user
,
{
issue_references:
issue_references
})
.
with
(
issue
,
user
,
{
issue_references:
issue_references
})
.
and_return
(
service
)
.
and_return
(
service
)
end
end
...
@@ -90,9 +90,9 @@ describe Projects::RelatedIssuesController, type: :controller do
...
@@ -90,9 +90,9 @@ describe Projects::RelatedIssuesController, type: :controller do
describe
'DELETE #destroy'
do
describe
'DELETE #destroy'
do
let
(
:referenced_issue
)
{
create
:issue
,
project:
project
}
let
(
:referenced_issue
)
{
create
:issue
,
project:
project
}
let
(
:
related_issue
)
{
create
:related_issue
,
related_issue
:
referenced_issue
}
let
(
:
issue_link
)
{
create
:issue_link
,
target
:
referenced_issue
}
let
(
:service
)
{
double
(
RelatedIssue
s
::
DestroyService
,
execute:
service_response
)
}
let
(
:service
)
{
double
(
IssueLink
s
::
DestroyService
,
execute:
service_response
)
}
let
(
:list_service
)
{
double
(
RelatedIssue
s
::
ListService
,
execute:
list_service_response
)
}
let
(
:list_service
)
{
double
(
IssueLink
s
::
ListService
,
execute:
list_service_response
)
}
let
(
:service_response
)
{
{
'message'
=>
'yay'
}
}
let
(
:service_response
)
{
{
'message'
=>
'yay'
}
}
let
(
:list_service_response
)
{
[{
'foo'
=>
'bar'
}]
}
let
(
:list_service_response
)
{
[{
'foo'
=>
'bar'
}]
}
let
(
:current_project_user_role
)
{
:developer
}
let
(
:current_project_user_role
)
{
:developer
}
...
@@ -101,7 +101,7 @@ describe Projects::RelatedIssuesController, type: :controller do
...
@@ -101,7 +101,7 @@ describe Projects::RelatedIssuesController, type: :controller do
delete
:destroy
,
namespace_id:
issue
.
project
.
namespace
,
delete
:destroy
,
namespace_id:
issue
.
project
.
namespace
,
project_id:
issue
.
project
,
project_id:
issue
.
project
,
issue_id:
issue
,
issue_id:
issue
,
id:
related_issue
,
id:
issue_link
,
format: :json
format: :json
end
end
...
@@ -109,12 +109,12 @@ describe Projects::RelatedIssuesController, type: :controller do
...
@@ -109,12 +109,12 @@ describe Projects::RelatedIssuesController, type: :controller do
project
.
team
<<
[
user
,
current_project_user_role
]
project
.
team
<<
[
user
,
current_project_user_role
]
sign_in
user
sign_in
user
allow
(
RelatedIssue
s
::
ListService
).
to
receive
(
:new
)
allow
(
IssueLink
s
::
ListService
).
to
receive
(
:new
)
.
with
(
issue
,
user
)
.
with
(
issue
,
user
)
.
and_return
(
list_service
)
.
and_return
(
list_service
)
allow
(
RelatedIssue
s
::
DestroyService
).
to
receive
(
:new
)
allow
(
IssueLink
s
::
DestroyService
).
to
receive
(
:new
)
.
with
(
related_issue
,
user
)
.
with
(
issue_link
,
user
)
.
and_return
(
service
)
.
and_return
(
service
)
end
end
...
...
spec/factories/issue_links.rb
0 → 100644
View file @
91a735d4
FactoryGirl
.
define
do
factory
:issue_link
do
source
factory: :issue
target
factory: :issue
end
end
spec/factories/related_issues.rb
deleted
100644 → 0
View file @
7afdb317
FactoryGirl
.
define
do
factory
:related_issue
do
issue
related_issue
factory: :issue
end
end
spec/models/
related_issue
_spec.rb
→
spec/models/
issue_link
_spec.rb
View file @
91a735d4
require
'spec_helper'
require
'spec_helper'
describe
RelatedIssue
do
describe
IssueLink
do
describe
'Associations'
do
describe
'Associations'
do
it
{
is_expected
.
to
belong_to
(
:
issue
)
}
it
{
is_expected
.
to
belong_to
(
:
source
).
class_name
(
'Issue'
)
}
it
{
is_expected
.
to
belong_to
(
:
related_issue
).
class_name
(
'Issue'
)
}
it
{
is_expected
.
to
belong_to
(
:
target
).
class_name
(
'Issue'
)
}
end
end
describe
'Validation'
do
describe
'Validation'
do
subject
{
create
:
related_issue
}
subject
{
create
:
issue_link
}
it
{
is_expected
.
to
validate_presence_of
(
:
issu
e
)
}
it
{
is_expected
.
to
validate_presence_of
(
:
sourc
e
)
}
it
{
is_expected
.
to
validate_presence_of
(
:
related_issue
)
}
it
{
is_expected
.
to
validate_presence_of
(
:
target
)
}
it
do
it
do
is_expected
.
to
validate_uniqueness_of
(
:
issu
e
)
is_expected
.
to
validate_uniqueness_of
(
:
sourc
e
)
.
scoped_to
(
:
related_issue
_id
)
.
scoped_to
(
:
target
_id
)
.
with_message
(
/already related/
)
.
with_message
(
/already related/
)
end
end
context
'self relation'
do
context
'self relation'
do
it
'invalidates object'
do
it
'invalidates object'
do
issue
=
create
:issue
issue
=
create
:issue
related_issue
=
build
:related_issue
,
issue:
issue
,
related_issue
:
issue
issue_link
=
build
:issue_link
,
source:
issue
,
target
:
issue
expect
(
related_issue
).
to
be_invalid
expect
(
issue_link
).
to
be_invalid
expect
(
related_issue
.
errors
[
:issu
e
]).
to
include
(
"cannot be related to itself"
)
expect
(
issue_link
.
errors
[
:sourc
e
]).
to
include
(
"cannot be related to itself"
)
end
end
end
end
end
end
...
...
spec/policies/project_policy_spec.rb
View file @
91a735d4
...
@@ -13,7 +13,7 @@ describe ProjectPolicy, models: true do
...
@@ -13,7 +13,7 @@ describe ProjectPolicy, models: true do
let
(
:guest_permissions
)
do
let
(
:guest_permissions
)
do
%i[
%i[
read_project read_board read_list read_wiki read_issue read_label
read_project read_board read_list read_wiki read_issue read_label
read_
related_issue
read_milestone read_project_snippet read_project_member
read_
issue_link
read_milestone read_project_snippet read_project_member
read_note create_project create_issue create_note
read_note create_project create_issue create_note
upload_file
upload_file
]
]
...
@@ -22,7 +22,7 @@ describe ProjectPolicy, models: true do
...
@@ -22,7 +22,7 @@ describe ProjectPolicy, models: true do
let
(
:reporter_permissions
)
do
let
(
:reporter_permissions
)
do
%i[
%i[
download_code fork_project create_project_snippet update_issue
download_code fork_project create_project_snippet update_issue
admin_issue admin_label admin_
related_issue
admin_list read_commit_status read_build
admin_issue admin_label admin_
issue_link
admin_list read_commit_status read_build
read_container_image read_pipeline read_environment read_deployment
read_container_image read_pipeline read_environment read_deployment
read_merge_request download_wiki_code
read_merge_request download_wiki_code
]
]
...
@@ -71,7 +71,7 @@ describe ProjectPolicy, models: true do
...
@@ -71,7 +71,7 @@ describe ProjectPolicy, models: true do
let
(
:auditor_permissions
)
do
let
(
:auditor_permissions
)
do
%i[
%i[
download_code download_wiki_code read_project read_board read_list
download_code download_wiki_code read_project read_board read_list
read_wiki read_issue read_label read_
related_issue
read_milestone read_project_snippet
read_wiki read_issue read_label read_
issue_link
read_milestone read_project_snippet
read_project_member read_note read_cycle_analytics read_pipeline
read_project_member read_note read_cycle_analytics read_pipeline
read_build read_commit_status read_container_image read_environment
read_build read_commit_status read_container_image read_environment
read_deployment read_merge_request read_pages
read_deployment read_merge_request read_pages
...
...
spec/services/
related_issue
s/create_service_spec.rb
→
spec/services/
issue_link
s/create_service_spec.rb
View file @
91a735d4
require
'spec_helper'
require
'spec_helper'
describe
RelatedIssue
s
::
CreateService
,
service:
true
do
describe
IssueLink
s
::
CreateService
,
service:
true
do
describe
'#execute'
do
describe
'#execute'
do
let
(
:namespace
)
{
create
:namespace
}
let
(
:namespace
)
{
create
:namespace
}
let
(
:project
)
{
create
:empty_project
,
namespace:
namespace
}
let
(
:project
)
{
create
:empty_project
,
namespace:
namespace
}
...
@@ -36,7 +36,7 @@ describe RelatedIssues::CreateService, service: true do
...
@@ -36,7 +36,7 @@ describe RelatedIssues::CreateService, service: true do
end
end
it
'no relationship is created'
do
it
'no relationship is created'
do
expect
{
subject
}.
not_to
change
(
RelatedIssue
,
:count
)
expect
{
subject
}.
not_to
change
(
IssueLink
,
:count
)
end
end
end
end
...
@@ -52,7 +52,7 @@ describe RelatedIssues::CreateService, service: true do
...
@@ -52,7 +52,7 @@ describe RelatedIssues::CreateService, service: true do
end
end
it
'no relationship is created'
do
it
'no relationship is created'
do
expect
{
subject
}.
not_to
change
(
RelatedIssue
,
:count
)
expect
{
subject
}.
not_to
change
(
IssueLink
,
:count
)
end
end
end
end
...
@@ -73,10 +73,10 @@ describe RelatedIssues::CreateService, service: true do
...
@@ -73,10 +73,10 @@ describe RelatedIssues::CreateService, service: true do
end
end
it
'creates relationships'
do
it
'creates relationships'
do
expect
{
subject
}.
to
change
(
RelatedIssue
,
:count
).
from
(
0
).
to
(
2
)
expect
{
subject
}.
to
change
(
IssueLink
,
:count
).
from
(
0
).
to
(
2
)
expect
(
RelatedIssue
.
first
).
to
have_attributes
(
issue:
issue
,
related_issue
:
issue_a
)
expect
(
IssueLink
.
first
).
to
have_attributes
(
source:
issue
,
target
:
issue_a
)
expect
(
RelatedIssue
.
last
).
to
have_attributes
(
issue:
issue
,
related_issue
:
another_project_issue
)
expect
(
IssueLink
.
last
).
to
have_attributes
(
source:
issue
,
target
:
another_project_issue
)
end
end
it
'returns success message with Issue reference'
do
it
'returns success message with Issue reference'
do
...
@@ -138,7 +138,7 @@ describe RelatedIssues::CreateService, service: true do
...
@@ -138,7 +138,7 @@ describe RelatedIssues::CreateService, service: true do
let
(
:issue_b
)
{
create
:issue
,
project:
project
}
let
(
:issue_b
)
{
create
:issue
,
project:
project
}
before
do
before
do
create
:
related_issue
,
issue:
issue
,
related_issue
:
issue_a
create
:
issue_link
,
source:
issue
,
target
:
issue_a
end
end
let
(
:params
)
do
let
(
:params
)
do
...
@@ -146,11 +146,11 @@ describe RelatedIssues::CreateService, service: true do
...
@@ -146,11 +146,11 @@ describe RelatedIssues::CreateService, service: true do
end
end
it
'returns error'
do
it
'returns error'
do
is_expected
.
to
eq
(
message:
"Validation failed:
I
ssue is already related"
,
status: :error
,
http_status:
401
)
is_expected
.
to
eq
(
message:
"Validation failed:
Source i
ssue is already related"
,
status: :error
,
http_status:
401
)
end
end
it
'no relation is created'
do
it
'no relation is created'
do
expect
{
subject
}.
not_to
change
(
RelatedIssue
,
:count
)
expect
{
subject
}.
not_to
change
(
IssueLink
,
:count
)
end
end
end
end
end
end
...
...
spec/services/
related_issue
s/destroy_service_spec.rb
→
spec/services/
issue_link
s/destroy_service_spec.rb
View file @
91a735d4
require
'spec_helper'
require
'spec_helper'
describe
RelatedIssue
s
::
DestroyService
,
service:
true
do
describe
IssueLink
s
::
DestroyService
,
service:
true
do
describe
'#execute'
do
describe
'#execute'
do
let
(
:user
)
{
create
:user
}
let
(
:user
)
{
create
:user
}
let!
(
:
related_issue
)
{
create
:related_issue
}
let!
(
:
issue_link
)
{
create
:issue_link
}
subject
{
described_class
.
new
(
related_issue
,
user
).
execute
}
subject
{
described_class
.
new
(
issue_link
,
user
).
execute
}
it
'removes related issue'
do
it
'removes related issue'
do
expect
{
subject
}.
to
change
(
RelatedIssue
,
:count
).
from
(
1
).
to
(
0
)
expect
{
subject
}.
to
change
(
IssueLink
,
:count
).
from
(
1
).
to
(
0
)
end
end
it
'creates notes'
do
it
'creates notes'
do
# Two-way notes creation
# Two-way notes creation
expect
(
SystemNoteService
).
to
receive
(
:unrelate_issue
)
expect
(
SystemNoteService
).
to
receive
(
:unrelate_issue
)
.
with
(
related_issue
.
issue
,
related_issue
.
related_issue
,
user
)
.
with
(
issue_link
.
source
,
issue_link
.
target
,
user
)
expect
(
SystemNoteService
).
to
receive
(
:unrelate_issue
)
expect
(
SystemNoteService
).
to
receive
(
:unrelate_issue
)
.
with
(
related_issue
.
related_issue
,
related_issue
.
issu
e
,
user
)
.
with
(
issue_link
.
target
,
issue_link
.
sourc
e
,
user
)
subject
subject
end
end
...
...
spec/services/
related_issue
s/list_service_spec.rb
→
spec/services/
issue_link
s/list_service_spec.rb
View file @
91a735d4
require
'spec_helper'
require
'spec_helper'
describe
RelatedIssue
s
::
ListService
,
service:
true
do
describe
IssueLink
s
::
ListService
,
service:
true
do
let
(
:user
)
{
create
:user
}
let
(
:user
)
{
create
:user
}
let
(
:project
)
{
create
(
:project_empty_repo
)
}
let
(
:project
)
{
create
(
:project_empty_repo
)
}
let
(
:issue
)
{
create
:issue
,
project:
project
}
let
(
:issue
)
{
create
:issue
,
project:
project
}
...
@@ -17,22 +17,22 @@ describe RelatedIssues::ListService, service: true do
...
@@ -17,22 +17,22 @@ describe RelatedIssues::ListService, service: true do
let
(
:issue_c
)
{
create
:issue
,
project:
project
}
let
(
:issue_c
)
{
create
:issue
,
project:
project
}
let
(
:issue_d
)
{
create
:issue
,
project:
project
}
let
(
:issue_d
)
{
create
:issue
,
project:
project
}
let!
(
:
related_issue
_c
)
do
let!
(
:
issue_link
_c
)
do
create
(
:
related_issue
,
id:
999
,
create
(
:
issue_link
,
id:
999
,
issu
e:
issue_d
,
sourc
e:
issue_d
,
related_issue
:
issue
)
target
:
issue
)
end
end
let!
(
:
related_issue
_b
)
do
let!
(
:
issue_link
_b
)
do
create
(
:
related_issue
,
id:
998
,
create
(
:
issue_link
,
id:
998
,
issu
e:
issue
,
sourc
e:
issue
,
related_issue
:
issue_c
)
target
:
issue_c
)
end
end
let!
(
:
related_issue
_a
)
do
let!
(
:
issue_link
_a
)
do
create
(
:
related_issue
,
id:
997
,
create
(
:
issue_link
,
id:
997
,
issu
e:
issue
,
sourc
e:
issue
,
related_issue
:
issue_b
)
target
:
issue_b
)
end
end
it
'verifies number of queries'
do
it
'verifies number of queries'
do
...
@@ -52,7 +52,7 @@ describe RelatedIssues::ListService, service: true do
...
@@ -52,7 +52,7 @@ describe RelatedIssues::ListService, service: true do
path:
"/
#{
project
.
full_path
}
/issues/
#{
issue_b
.
iid
}
"
,
path:
"/
#{
project
.
full_path
}
/issues/
#{
issue_b
.
iid
}
"
,
project_path:
issue_b
.
project
.
path
,
project_path:
issue_b
.
project
.
path
,
namespace_full_path:
issue_b
.
project
.
namespace
.
full_path
,
namespace_full_path:
issue_b
.
project
.
namespace
.
full_path
,
destroy_relation_path:
"/
#{
project
.
full_path
}
/issues/
#{
issue_b
.
iid
}
/
related_issues/
#{
related_issue
_a
.
id
}
"
destroy_relation_path:
"/
#{
project
.
full_path
}
/issues/
#{
issue_b
.
iid
}
/
links/
#{
issue_link
_a
.
id
}
"
}
}
)
)
...
@@ -65,7 +65,7 @@ describe RelatedIssues::ListService, service: true do
...
@@ -65,7 +65,7 @@ describe RelatedIssues::ListService, service: true do
path:
"/
#{
project
.
full_path
}
/issues/
#{
issue_c
.
iid
}
"
,
path:
"/
#{
project
.
full_path
}
/issues/
#{
issue_c
.
iid
}
"
,
project_path:
issue_c
.
project
.
path
,
project_path:
issue_c
.
project
.
path
,
namespace_full_path:
issue_c
.
project
.
namespace
.
full_path
,
namespace_full_path:
issue_c
.
project
.
namespace
.
full_path
,
destroy_relation_path:
"/
#{
project
.
full_path
}
/issues/
#{
issue_c
.
iid
}
/
related_issues/
#{
related_issue
_b
.
id
}
"
destroy_relation_path:
"/
#{
project
.
full_path
}
/issues/
#{
issue_c
.
iid
}
/
links/
#{
issue_link
_b
.
id
}
"
}
}
)
)
...
@@ -78,7 +78,7 @@ describe RelatedIssues::ListService, service: true do
...
@@ -78,7 +78,7 @@ describe RelatedIssues::ListService, service: true do
path:
"/
#{
project
.
full_path
}
/issues/
#{
issue_d
.
iid
}
"
,
path:
"/
#{
project
.
full_path
}
/issues/
#{
issue_d
.
iid
}
"
,
project_path:
issue_d
.
project
.
path
,
project_path:
issue_d
.
project
.
path
,
namespace_full_path:
issue_d
.
project
.
namespace
.
full_path
,
namespace_full_path:
issue_d
.
project
.
namespace
.
full_path
,
destroy_relation_path:
"/
#{
project
.
full_path
}
/issues/
#{
issue_d
.
iid
}
/
related_issues/
#{
related_issue
_c
.
id
}
"
destroy_relation_path:
"/
#{
project
.
full_path
}
/issues/
#{
issue_d
.
iid
}
/
links/
#{
issue_link
_c
.
id
}
"
}
}
)
)
end
end
...
@@ -87,8 +87,8 @@ describe RelatedIssues::ListService, service: true do
...
@@ -87,8 +87,8 @@ describe RelatedIssues::ListService, service: true do
context
'referencing issue with removed relationships'
do
context
'referencing issue with removed relationships'
do
context
'when referenced a deleted issue'
do
context
'when referenced a deleted issue'
do
let
(
:issue_b
)
{
create
:issue
,
project:
project
}
let
(
:issue_b
)
{
create
:issue
,
project:
project
}
let!
(
:
related_issue
)
do
let!
(
:
issue_link
)
do
create
(
:
related_issue
,
issue:
issue
,
related_issue
:
issue_b
)
create
(
:
issue_link
,
source:
issue
,
target
:
issue_b
)
end
end
it
'ignores issue'
do
it
'ignores issue'
do
...
@@ -100,8 +100,8 @@ describe RelatedIssues::ListService, service: true do
...
@@ -100,8 +100,8 @@ describe RelatedIssues::ListService, service: true do
context
'when referenced an issue with deleted project'
do
context
'when referenced an issue with deleted project'
do
let
(
:issue_b
)
{
create
:issue
,
project:
project
}
let
(
:issue_b
)
{
create
:issue
,
project:
project
}
let!
(
:
related_issue
)
do
let!
(
:
issue_link
)
do
create
(
:
related_issue
,
issue:
issue
,
related_issue
:
issue_b
)
create
(
:
issue_link
,
source:
issue
,
target
:
issue_b
)
end
end
it
'ignores issue'
do
it
'ignores issue'
do
...
@@ -113,8 +113,8 @@ describe RelatedIssues::ListService, service: true do
...
@@ -113,8 +113,8 @@ describe RelatedIssues::ListService, service: true do
context
'when referenced an issue with deleted namespace'
do
context
'when referenced an issue with deleted namespace'
do
let
(
:issue_b
)
{
create
:issue
,
project:
project
}
let
(
:issue_b
)
{
create
:issue
,
project:
project
}
let!
(
:
related_issue
)
do
let!
(
:
issue_link
)
do
create
(
:
related_issue
,
issue:
issue
,
related_issue
:
issue_b
)
create
(
:
issue_link
,
source:
issue
,
target
:
issue_b
)
end
end
it
'ignores issue'
do
it
'ignores issue'
do
...
@@ -127,8 +127,8 @@ describe RelatedIssues::ListService, service: true do
...
@@ -127,8 +127,8 @@ describe RelatedIssues::ListService, service: true do
context
'user cannot see relations'
do
context
'user cannot see relations'
do
context
'when user cannot see the referenced issue'
do
context
'when user cannot see the referenced issue'
do
let!
(
:
related_issue
)
do
let!
(
:
issue_link
)
do
create
(
:
related_issue
,
issu
e:
issue
)
create
(
:
issue_link
,
sourc
e:
issue
)
end
end
it
'returns an empty list'
do
it
'returns an empty list'
do
...
@@ -137,8 +137,8 @@ describe RelatedIssues::ListService, service: true do
...
@@ -137,8 +137,8 @@ describe RelatedIssues::ListService, service: true do
end
end
context
'when user cannot see the issue that referenced'
do
context
'when user cannot see the issue that referenced'
do
let!
(
:
related_issue
)
do
let!
(
:
issue_link
)
do
create
(
:
related_issue
,
related_issue
:
issue
)
create
(
:
issue_link
,
target
:
issue
)
end
end
it
'returns an empty list'
do
it
'returns an empty list'
do
...
@@ -148,8 +148,8 @@ describe RelatedIssues::ListService, service: true do
...
@@ -148,8 +148,8 @@ describe RelatedIssues::ListService, service: true do
end
end
context
'remove relations'
do
context
'remove relations'
do
let!
(
:
related_issue
)
do
let!
(
:
issue_link
)
do
create
(
:
related_issue
,
issue:
issue
,
related_issue
:
referenced_issue
)
create
(
:
issue_link
,
source:
issue
,
target
:
referenced_issue
)
end
end
context
'when user can admin related issues on one project'
do
context
'when user can admin related issues on one project'
do
...
@@ -171,7 +171,7 @@ describe RelatedIssues::ListService, service: true do
...
@@ -171,7 +171,7 @@ describe RelatedIssues::ListService, service: true do
it
'returns related issue destroy relation path'
do
it
'returns related issue destroy relation path'
do
expect
(
subject
.
first
[
:destroy_relation_path
])
expect
(
subject
.
first
[
:destroy_relation_path
])
.
to
eq
(
"/
#{
project
.
full_path
}
/issues/
#{
referenced_issue
.
iid
}
/
related_issues/
#{
related_issue
.
id
}
"
)
.
to
eq
(
"/
#{
project
.
full_path
}
/issues/
#{
referenced_issue
.
iid
}
/
links/
#{
issue_link
.
id
}
"
)
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