Adds subtasks to GET /issues/:id API (#5338).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4465 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
88e593ee02
commit
9157482049
|
@ -189,6 +189,20 @@ module IssuesHelper
|
|||
end
|
||||
end
|
||||
|
||||
# Renders issue children recursively
|
||||
def render_api_issue_children(issue, api)
|
||||
return if issue.leaf?
|
||||
api.array :children do
|
||||
issue.children.each do |child|
|
||||
api.issue(:id => child.id) do
|
||||
api.tracker(:id => child.tracker_id, :name => child.tracker.name) unless child.tracker.nil?
|
||||
api.subject child.subject
|
||||
render_api_issue_children(child, api)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def issues_to_csv(issues, project = nil)
|
||||
ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
|
||||
decimal_separator = l(:general_csv_decimal_separator)
|
||||
|
|
|
@ -29,6 +29,8 @@ api.issue do
|
|||
api.created_on @issue.created_on
|
||||
api.updated_on @issue.updated_on
|
||||
|
||||
render_api_issue_children(@issue, api)
|
||||
|
||||
api.array :relations do
|
||||
@issue.relations.select {|r| r.other_issue(@issue).visible? }.each do |relation|
|
||||
api.relation(:id => relation.id, :issue_id => relation.other_issue(@issue).id, :relation_type => relation.relation_type_for(@issue), :delay => relation.delay)
|
||||
|
|
|
@ -89,6 +89,60 @@ class ApiTest::IssuesTest < ActionController::IntegrationTest
|
|||
context "/issues/6.json" do
|
||||
should_allow_api_authentication(:get, "/issues/6.json")
|
||||
end
|
||||
|
||||
context "GET /issues/:id" do
|
||||
context "with subtasks" do
|
||||
setup do
|
||||
@c1 = Issue.generate!(:status_id => 1, :subject => "child c1", :tracker_id => 1, :project_id => 1, :parent_issue_id => 1)
|
||||
@c2 = Issue.generate!(:status_id => 1, :subject => "child c2", :tracker_id => 1, :project_id => 1, :parent_issue_id => 1)
|
||||
@c3 = Issue.generate!(:status_id => 1, :subject => "child c3", :tracker_id => 1, :project_id => 1, :parent_issue_id => @c1.id)
|
||||
end
|
||||
|
||||
context ".xml" do
|
||||
should "display children" do
|
||||
get '/issues/1.xml'
|
||||
|
||||
assert_tag :tag => 'issue',
|
||||
:child => {
|
||||
:tag => 'children',
|
||||
:children => {:count => 2},
|
||||
:child => {
|
||||
:tag => 'issue',
|
||||
:attributes => {:id => @c1.id.to_s},
|
||||
:child => {
|
||||
:tag => 'subject',
|
||||
:content => 'child c1',
|
||||
:sibling => {
|
||||
:tag => 'children',
|
||||
:children => {:count => 1},
|
||||
:child => {
|
||||
:tag => 'issue',
|
||||
:attributes => {:id => @c3.id.to_s}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
context ".json" do
|
||||
should "display children" do
|
||||
get '/issues/1.json'
|
||||
|
||||
json = ActiveSupport::JSON.decode(response.body)
|
||||
assert_equal([
|
||||
{
|
||||
'id' => @c1.id, 'subject' => 'child c1', 'tracker' => {'id' => 1, 'name' => 'Bug'},
|
||||
'children' => [{ 'id' => @c3.id, 'subject' => 'child c3', 'tracker' => {'id' => 1, 'name' => 'Bug'} }]
|
||||
},
|
||||
{ 'id' => @c2.id, 'subject' => 'child c2', 'tracker' => {'id' => 1, 'name' => 'Bug'} }
|
||||
],
|
||||
json['issue']['children'])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "POST /issues.xml" do
|
||||
should_allow_api_authentication(:post,
|
||||
|
|
Loading…
Reference in New Issue