Project

General

Profile

Feature #21757 » feature-21757_trunk_r15148.patch

Takenori TAKAKI, 2016-03-01 07:20

View differences:

app/views/issues/show.api.rsb
17 17
  api.done_ratio @issue.done_ratio
18 18
  api.is_private @issue.is_private
19 19
  api.estimated_hours @issue.estimated_hours
20
  api.spent_hours(@issue.spent_hours) if User.current.allowed_to?(:view_time_entries, @project)
20
  api.total_estimated_hours @issue.total_estimated_hours
21
  if User.current.allowed_to?(:view_time_entries, @project)
22
    api.spent_hours(@issue.spent_hours)
23
    api.total_spent_hours(@issue.total_spent_hours)
24
  end
21 25

  
22 26
  render_api_custom_values @issue.visible_custom_field_values, api
23 27

  
test/integration/api_test/issues_test.rb
350 350
    end
351 351
  end
352 352

  
353
  test "GET /issues/:id.xml should contains total_estimated_hours and total_spent_hours" do
354
    parent = Issue.find(3)
355
    child = Issue.generate!(:parent_issue_id => parent.id, :estimated_hours => 3.0)
356
    TimeEntry.create!(:project => child.project, :issue => child, :user => child.author, :spent_on => child.author.today,
357
                      :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first.id)
358
    get '/issues/3.xml'
359

  
360
    assert_equal 'application/xml', response.content_type
361
    assert_select 'issue' do
362
      assert_select 'estimated_hours',       parent.estimated_hours.to_s
363
      assert_select 'total_estimated_hours', (parent.estimated_hours.to_f + 3.0).to_s
364
      assert_select 'spent_hours',           parent.spent_hours.to_s
365
      assert_select 'total_spent_hours',     (parent.spent_hours.to_f + 2.5).to_s
366
    end
367
  end
368

  
369
  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
370
    parent = Issue.find(3)
371
    child = Issue.generate!(:parent_issue_id => parent.id, :estimated_hours => 3.0)
372
    # remove permission!
373
    Role.anonymous.remove_permission! :view_time_entries
374
    #Role.all.each { |role| role.remove_permission! :view_time_entries }
375
    get '/issues/3.xml'
376

  
377
    assert_equal 'application/xml', response.content_type
378
    assert_select 'issue' do
379
      assert_select 'estimated_hours',       parent.estimated_hours.to_s
380
      assert_select 'total_estimated_hours', (parent.estimated_hours.to_f + 3.0).to_s
381
      assert_select 'spent_hours',           false
382
      assert_select 'total_spent_hours',     false
383
    end
384
  end
385

  
386
  test "GET /issues/:id.json should contains total_estimated_hours and total_spent_hours" do
387
    parent = Issue.find(3)
388
    child = Issue.generate!(:parent_issue_id => parent.id, :estimated_hours => 3.0)
389
    TimeEntry.create!(:project => child.project, :issue => child, :user => child.author, :spent_on => child.author.today,
390
                      :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first.id)
391
    get '/issues/3.json'
392

  
393
    assert_equal 'application/json', response.content_type
394
    json = ActiveSupport::JSON.decode(response.body)
395
    assert_equal parent.estimated_hours, json['issue']['estimated_hours']
396
    assert_equal (parent.estimated_hours.to_f + 3.0), json['issue']['total_estimated_hours']
397
    assert_equal parent.spent_hours, json['issue']['spent_hours']
398
    assert_equal (parent.spent_hours.to_f + 2.5), json['issue']['total_spent_hours']
399
  end
400

  
401
  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
402
    parent = Issue.find(3)
403
    child = Issue.generate!(:parent_issue_id => parent.id, :estimated_hours => 3.0)
404
    # remove permission!
405
    Role.anonymous.remove_permission! :view_time_entries
406
    #Role.all.each { |role| role.remove_permission! :view_time_entries }
407
    get '/issues/3.json'
408

  
409
    assert_equal 'application/json', response.content_type
410
    json = ActiveSupport::JSON.decode(response.body)
411
    assert_equal parent.estimated_hours, json['issue']['estimated_hours']
412
    assert_equal (parent.estimated_hours.to_f + 3.0), json['issue']['total_estimated_hours']
413
    assert_equal nil, json['issue']['spent_hours']
414
    assert_equal nil, json['issue']['total_spent_hours']
415
  end
416

  
353 417
  test "POST /issues.xml should create an issue with the attributes" do
354 418

  
355 419
payload = <<-XML
(2-2/2)