]> source.dussan.org Git - redmine.git/commitdiff
Total spent hours and estimated hours need to be get via REST (#21757).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 19 Mar 2016 09:05:12 +0000 (09:05 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 19 Mar 2016 09:05:12 +0000 (09:05 +0000)
Patch by Takenori TAKAKI.

git-svn-id: http://svn.redmine.org/redmine/trunk@15254 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/views/issues/show.api.rsb
test/integration/api_test/issues_test.rb

index 577a885c2d12a49ce51e357340420a29462abcf8..072709e57c26fdad399f7008169dd3dffa521e76 100644 (file)
@@ -17,7 +17,11 @@ api.issue do
   api.done_ratio @issue.done_ratio
   api.is_private @issue.is_private
   api.estimated_hours @issue.estimated_hours
-  api.spent_hours(@issue.spent_hours) if User.current.allowed_to?(:view_time_entries, @project)
+  api.total_estimated_hours @issue.total_estimated_hours
+  if User.current.allowed_to?(:view_time_entries, @project)
+    api.spent_hours(@issue.spent_hours)
+    api.total_spent_hours(@issue.total_spent_hours)
+  end
 
   render_api_custom_values @issue.visible_custom_field_values, api
 
index 97483171f61d31c2dd2a101d45651f02f50c451e..8b23dccc812744a67bf59acbef5121216a185611 100644 (file)
@@ -350,6 +350,70 @@ class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base
     end
   end
 
+  test "GET /issues/:id.xml should contains total_estimated_hours and total_spent_hours" do
+    parent = Issue.find(3)
+    child = Issue.generate!(:parent_issue_id => parent.id, :estimated_hours => 3.0)
+    TimeEntry.create!(:project => child.project, :issue => child, :user => child.author, :spent_on => child.author.today,
+                      :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first.id)
+    get '/issues/3.xml'
+
+    assert_equal 'application/xml', response.content_type
+    assert_select 'issue' do
+      assert_select 'estimated_hours',       parent.estimated_hours.to_s
+      assert_select 'total_estimated_hours', (parent.estimated_hours.to_f + 3.0).to_s
+      assert_select 'spent_hours',           parent.spent_hours.to_s
+      assert_select 'total_spent_hours',     (parent.spent_hours.to_f + 2.5).to_s
+    end
+  end
+
+  test "GET /issues/:id.xml should contains total_estimated_hours, and should not contains spent_hours and total_spent_hours when permission does not exists" do
+    parent = Issue.find(3)
+    child = Issue.generate!(:parent_issue_id => parent.id, :estimated_hours => 3.0)
+    # remove permission!
+    Role.anonymous.remove_permission! :view_time_entries
+    #Role.all.each { |role| role.remove_permission! :view_time_entries }
+    get '/issues/3.xml'
+
+    assert_equal 'application/xml', response.content_type
+    assert_select 'issue' do
+      assert_select 'estimated_hours',       parent.estimated_hours.to_s
+      assert_select 'total_estimated_hours', (parent.estimated_hours.to_f + 3.0).to_s
+      assert_select 'spent_hours',           false
+      assert_select 'total_spent_hours',     false
+    end
+  end
+
+  test "GET /issues/:id.json should contains total_estimated_hours and total_spent_hours" do
+    parent = Issue.find(3)
+    child = Issue.generate!(:parent_issue_id => parent.id, :estimated_hours => 3.0)
+    TimeEntry.create!(:project => child.project, :issue => child, :user => child.author, :spent_on => child.author.today,
+                      :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first.id)
+    get '/issues/3.json'
+
+    assert_equal 'application/json', response.content_type
+    json = ActiveSupport::JSON.decode(response.body)
+    assert_equal parent.estimated_hours, json['issue']['estimated_hours']
+    assert_equal (parent.estimated_hours.to_f + 3.0), json['issue']['total_estimated_hours']
+    assert_equal parent.spent_hours, json['issue']['spent_hours']
+    assert_equal (parent.spent_hours.to_f + 2.5), json['issue']['total_spent_hours']
+  end
+
+  test "GET /issues/:id.json should contains total_estimated_hours, and should not contains spent_hours and total_spent_hours when permission does not exists" do
+    parent = Issue.find(3)
+    child = Issue.generate!(:parent_issue_id => parent.id, :estimated_hours => 3.0)
+    # remove permission!
+    Role.anonymous.remove_permission! :view_time_entries
+    #Role.all.each { |role| role.remove_permission! :view_time_entries }
+    get '/issues/3.json'
+
+    assert_equal 'application/json', response.content_type
+    json = ActiveSupport::JSON.decode(response.body)
+    assert_equal parent.estimated_hours, json['issue']['estimated_hours']
+    assert_equal (parent.estimated_hours.to_f + 3.0), json['issue']['total_estimated_hours']
+    assert_equal nil, json['issue']['spent_hours']
+    assert_equal nil, json['issue']['total_spent_hours']
+  end
+
   test "POST /issues.xml should create an issue with the attributes" do
 
 payload = <<-XML