summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2010-12-04 13:02:14 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2010-12-04 13:02:14 +0000
commit915748204965bb7f9704b55554e30f091934138e (patch)
tree03a0e543b2b68bf885a0f5477ffd55b714ef072f
parent88e593ee027b1fc1bdfa63b6ab76b0ae51ec6295 (diff)
downloadredmine-915748204965bb7f9704b55554e30f091934138e.tar.gz
redmine-915748204965bb7f9704b55554e30f091934138e.zip
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
-rw-r--r--app/helpers/issues_helper.rb14
-rw-r--r--app/views/issues/show.apit2
-rw-r--r--test/integration/api_test/issues_test.rb54
3 files changed, 70 insertions, 0 deletions
diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb
index 321041b7c..ce23668ef 100644
--- a/app/helpers/issues_helper.rb
+++ b/app/helpers/issues_helper.rb
@@ -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)
diff --git a/app/views/issues/show.apit b/app/views/issues/show.apit
index 224026d1f..001cabe11 100644
--- a/app/views/issues/show.apit
+++ b/app/views/issues/show.apit
@@ -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)
diff --git a/test/integration/api_test/issues_test.rb b/test/integration/api_test/issues_test.rb
index d7bc785c0..0ef9de8e2 100644
--- a/test/integration/api_test/issues_test.rb
+++ b/test/integration/api_test/issues_test.rb
@@ -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,