You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gantts_controller_test.rb 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2014 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. require File.expand_path('../../test_helper', __FILE__)
  18. class GanttsControllerTest < ActionController::TestCase
  19. fixtures :projects, :trackers, :issue_statuses, :issues,
  20. :enumerations, :users, :issue_categories,
  21. :projects_trackers,
  22. :roles,
  23. :member_roles,
  24. :members,
  25. :enabled_modules,
  26. :versions
  27. def test_gantt_should_work
  28. i2 = Issue.find(2)
  29. i2.update_attribute(:due_date, 1.month.from_now)
  30. get :show, :project_id => 1
  31. assert_response :success
  32. assert_template 'gantts/show'
  33. assert_not_nil assigns(:gantt)
  34. # Issue with start and due dates
  35. i = Issue.find(1)
  36. assert_not_nil i.due_date
  37. assert_select "div a.issue", /##{i.id}/
  38. # Issue with on a targeted version should not be in the events but loaded in the html
  39. i = Issue.find(2)
  40. assert_select "div a.issue", /##{i.id}/
  41. end
  42. def test_gantt_should_work_without_issue_due_dates
  43. Issue.update_all("due_date = NULL")
  44. get :show, :project_id => 1
  45. assert_response :success
  46. assert_template 'gantts/show'
  47. assert_not_nil assigns(:gantt)
  48. end
  49. def test_gantt_should_work_without_issue_and_version_due_dates
  50. Issue.update_all("due_date = NULL")
  51. Version.update_all("effective_date = NULL")
  52. get :show, :project_id => 1
  53. assert_response :success
  54. assert_template 'gantts/show'
  55. assert_not_nil assigns(:gantt)
  56. end
  57. def test_gantt_should_work_cross_project
  58. get :show
  59. assert_response :success
  60. assert_template 'gantts/show'
  61. assert_not_nil assigns(:gantt)
  62. assert_not_nil assigns(:gantt).query
  63. assert_nil assigns(:gantt).project
  64. end
  65. def test_gantt_should_not_disclose_private_projects
  66. get :show
  67. assert_response :success
  68. assert_template 'gantts/show'
  69. assert_tag 'a', :content => /eCookbook/
  70. # Root private project
  71. assert_no_tag 'a', {:content => /OnlineStore/}
  72. # Private children of a public project
  73. assert_no_tag 'a', :content => /Private child of eCookbook/
  74. end
  75. def test_gantt_should_display_relations
  76. IssueRelation.delete_all
  77. issue1 = Issue.generate!(:start_date => 1.day.from_now.to_date, :due_date => 3.day.from_now.to_date)
  78. issue2 = Issue.generate!(:start_date => 1.day.from_now.to_date, :due_date => 3.day.from_now.to_date)
  79. IssueRelation.create!(:issue_from => issue1, :issue_to => issue2, :relation_type => 'precedes')
  80. get :show
  81. assert_response :success
  82. relations = assigns(:gantt).relations
  83. assert_kind_of Hash, relations
  84. assert relations.present?
  85. assert_select 'div.task_todo[id=?][data-rels*=?]', "task-todo-issue-#{issue1.id}", issue2.id.to_s
  86. assert_select 'div.task_todo[id=?]:not([data-rels])', "task-todo-issue-#{issue2.id}"
  87. end
  88. def test_gantt_should_export_to_pdf
  89. get :show, :project_id => 1, :format => 'pdf'
  90. assert_response :success
  91. assert_equal 'application/pdf', @response.content_type
  92. assert @response.body.starts_with?('%PDF')
  93. assert_not_nil assigns(:gantt)
  94. end
  95. def test_gantt_should_export_to_pdf_cross_project
  96. get :show, :format => 'pdf'
  97. assert_response :success
  98. assert_equal 'application/pdf', @response.content_type
  99. assert @response.body.starts_with?('%PDF')
  100. assert_not_nil assigns(:gantt)
  101. end
  102. if Object.const_defined?(:Magick)
  103. def test_gantt_should_export_to_png
  104. get :show, :project_id => 1, :format => 'png'
  105. assert_response :success
  106. assert_equal 'image/png', @response.content_type
  107. end
  108. end
  109. end