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
fd1b9e88
Commit
fd1b9e88
authored
Apr 24, 2017
by
Oswaldo Ferreira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial RelatedIssuesController#index
parent
8a5b4e2f
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
132 additions
and
0 deletions
+132
-0
app/controllers/projects/related_issues_controller.rb
app/controllers/projects/related_issues_controller.rb
+45
-0
config/routes/project.rb
config/routes/project.rb
+2
-0
spec/controllers/projects/related_issues_controller_spec.rb
spec/controllers/projects/related_issues_controller_spec.rb
+79
-0
spec/factories/related_issues.rb
spec/factories/related_issues.rb
+6
-0
No files found.
app/controllers/projects/related_issues_controller.rb
0 → 100644
View file @
fd1b9e88
module
Projects
class
RelatedIssuesController
<
ApplicationController
include
IssuesHelper
before_action
:authorize_read_issue!
,
only:
[
:index
]
def
index
render
json:
serialize_as_json
end
def
create
end
private
# TODO: Move to service class
def
serialize_as_json
related_issues
.
map
do
|
related_issue
|
referenced_issue
=
related_issue
.
related_issue
==
issue
?
related_issue
.
issue
:
related_issue
.
related_issue
{
title:
referenced_issue
.
title
,
state:
referenced_issue
.
state
,
reference:
referenced_issue
.
to_reference
(
@project
),
path:
url_for_issue
(
referenced_issue
.
iid
,
@project
,
only_path:
true
),
}
end
end
def
related_issues
RelatedIssue
.
where
(
"issue_id =
#{
issue
.
id
}
OR related_issue_id =
#{
issue
.
id
}
"
)
.
preload
(
:related_issue
,
:issue
)
.
order
(
:created_at
)
end
def
issue
@issue
||=
IssuesFinder
.
new
(
current_user
,
project_id:
project
.
id
)
.
execute
.
where
(
iid:
params
[
:issue_id
])
.
first!
end
end
end
config/routes/project.rb
View file @
fd1b9e88
...
@@ -311,6 +311,8 @@ constraints(ProjectUrlConstrainer.new) do
...
@@ -311,6 +311,8 @@ constraints(ProjectUrlConstrainer.new) do
post
:bulk_update
post
:bulk_update
post
:export_csv
post
:export_csv
end
end
resources
:related_issues
,
only:
[
:index
,
:create
]
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_issues_controller_spec.rb
0 → 100644
View file @
fd1b9e88
require
'rails_helper'
describe
Projects
::
RelatedIssuesController
,
type: :controller
do
let
(
:user
)
{
create
:user
}
let
(
:project
)
{
create
(
:project_empty_repo
)
}
let
(
:issue
)
{
create
:issue
,
project:
project
}
describe
"GET #index"
do
let
(
:issue_b
)
{
create
:issue
,
project:
project
}
let
(
:issue_c
)
{
create
:issue
,
project:
project
}
let
(
:issue_d
)
{
create
:issue
,
project:
project
}
let!
(
:related_issue_a
)
do
create
(
:related_issue
,
issue:
issue
,
related_issue:
issue_b
,
created_at:
2
.
days
.
ago
)
end
let!
(
:related_issue_b
)
do
create
(
:related_issue
,
issue:
issue
,
related_issue:
issue_c
,
created_at:
1
.
day
.
ago
)
end
let!
(
:related_issue_c
)
do
create
(
:related_issue
,
issue:
issue_d
,
related_issue:
issue
,
created_at:
Date
.
today
)
end
it
"returns related issues JSON"
do
sign_in
user
project
.
team
<<
[
user
,
:developer
]
get
:index
,
namespace_id:
issue
.
project
.
namespace
,
project_id:
issue
.
project
,
issue_id:
issue
,
format: :json
expect
(
json_response
.
size
).
to
eq
(
3
)
expect
(
json_response
[
0
]).
to
eq
(
{
"title"
=>
issue_b
.
title
,
"state"
=>
issue_b
.
state
,
"reference"
=>
issue_b
.
to_reference
(
project
),
"path"
=>
"/
#{
project
.
full_path
}
/issues/
#{
issue_b
.
iid
}
"
}
)
expect
(
json_response
[
1
]).
to
eq
(
{
"title"
=>
issue_c
.
title
,
"state"
=>
issue_c
.
state
,
"reference"
=>
issue_c
.
to_reference
(
project
),
"path"
=>
"/
#{
project
.
full_path
}
/issues/
#{
issue_c
.
iid
}
"
}
)
expect
(
json_response
[
2
]).
to
eq
(
{
"title"
=>
issue_d
.
title
,
"state"
=>
issue_d
.
state
,
"reference"
=>
issue_d
.
to_reference
(
project
),
"path"
=>
"/
#{
project
.
full_path
}
/issues/
#{
issue_d
.
iid
}
"
}
)
end
end
xdescribe
"GET #create"
do
it
"returns http success"
do
get
:create
expect
(
response
).
to
have_http_status
(
:success
)
end
end
end
spec/factories/related_issues.rb
0 → 100644
View file @
fd1b9e88
FactoryGirl
.
define
do
factory
:related_issue
do
issue
related_issue
factory: :issue
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