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.

reports_controller_test.rb 11KB

Converted routing and urls to follow the Rails REST convention. Patch supplied by commits from Gerrit Kaiser on Github. Existing routes will still work (backwards compatible) but any new urls will be generated using the new routing rules. Changes listed below: * made the URLs for some project tabs and project settings follow the new rails RESTful conventions of /collection/:id/subcollection/:sub_id * prettier URL for project roadmap * more nice project URLs * use GET for filtering form * prettified URLs used on issues tab * custom route for activity atom feeds * prettier repository urls * fixed broken route definition * fixed failing tests for issuecontroller that were hardcoding the url string * more RESTful routes for boards and messages * RESTful routes for wiki pages * RESTful routes for documents * moved old routes that are retained for compatibility to the bottom and grouped them together * added RESTful URIs for issues * RESTfulness for the news section * fixed route order * changed hardcoded URLs in tests * fixed badly written tests * fixed forgotten parameter in routes * changed hardcoded URLS to new scheme * changed project add url to the standard POST to collection * create new issue by POSTing to collection * changed hardcoded URLs in integrations tests * made project add form work again * restful routes for project deletion * prettier routes for project (un)archival * made routes table more readable * fixed note quoting * user routing * fixed bug * always sort by GET * Fixed: cross-project issue list should not show issues of projects for which the issue tracking module was disabled. * prettified URLs used on issues tab * urls for time log * fixed reply routing * eliminate revision query paremeter for diff and entry actions * fixed test failures with hard-coded urls * ensure ajax links always use get * refactored ajax link generation into separate method #1901 git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2317 e93f8b46-1217-0410-a6f0-8f06a7374b81
15 years ago
Converted routing and urls to follow the Rails REST convention. Patch supplied by commits from Gerrit Kaiser on Github. Existing routes will still work (backwards compatible) but any new urls will be generated using the new routing rules. Changes listed below: * made the URLs for some project tabs and project settings follow the new rails RESTful conventions of /collection/:id/subcollection/:sub_id * prettier URL for project roadmap * more nice project URLs * use GET for filtering form * prettified URLs used on issues tab * custom route for activity atom feeds * prettier repository urls * fixed broken route definition * fixed failing tests for issuecontroller that were hardcoding the url string * more RESTful routes for boards and messages * RESTful routes for wiki pages * RESTful routes for documents * moved old routes that are retained for compatibility to the bottom and grouped them together * added RESTful URIs for issues * RESTfulness for the news section * fixed route order * changed hardcoded URLs in tests * fixed badly written tests * fixed forgotten parameter in routes * changed hardcoded URLS to new scheme * changed project add url to the standard POST to collection * create new issue by POSTing to collection * changed hardcoded URLs in integrations tests * made project add form work again * restful routes for project deletion * prettier routes for project (un)archival * made routes table more readable * fixed note quoting * user routing * fixed bug * always sort by GET * Fixed: cross-project issue list should not show issues of projects for which the issue tracking module was disabled. * prettified URLs used on issues tab * urls for time log * fixed reply routing * eliminate revision query paremeter for diff and entry actions * fixed test failures with hard-coded urls * ensure ajax links always use get * refactored ajax link generation into separate method #1901 git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2317 e93f8b46-1217-0410-a6f0-8f06a7374b81
15 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006- Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. require_relative '../test_helper'
  19. class ReportsControllerTest < Redmine::ControllerTest
  20. fixtures :projects, :trackers, :issue_statuses, :issues,
  21. :enumerations, :users, :issue_categories,
  22. :projects_trackers,
  23. :roles,
  24. :member_roles,
  25. :members,
  26. :enabled_modules,
  27. :versions,
  28. :workflows
  29. def test_get_issue_report
  30. get(
  31. :issue_report,
  32. :params => {
  33. :id => 1
  34. }
  35. )
  36. assert_response :success
  37. end
  38. def test_issue_report_with_subprojects_issues
  39. project = Project.find(1)
  40. tracker = project.trackers.find_by(:name => 'Support request')
  41. project.trackers.delete(tracker)
  42. with_settings :display_subprojects_issues => '1' do
  43. get(
  44. :issue_report,
  45. :params => {
  46. :id => 1
  47. }
  48. )
  49. assert_response :success
  50. # Count subprojects issues
  51. assert_select 'table.list tbody :nth-child(1):first' do
  52. assert_select 'td', :text => 'Bug'
  53. assert_select ':nth-child(2)', :text => '5' # open
  54. assert_select ':nth-child(3)', :text => '3' # closed
  55. assert_select ':nth-child(4)', :text => '8' # total
  56. end
  57. assert_select 'table.issue-report td.name', :text => 'Support request', :count => 1
  58. end
  59. end
  60. def test_issue_report_without_subprojects_issues
  61. project = Project.find(1)
  62. tracker = project.trackers.find_by(:name => 'Support request')
  63. project.trackers.delete(tracker)
  64. with_settings :display_subprojects_issues => '0' do
  65. get(
  66. :issue_report,
  67. :params => {
  68. :id => 1
  69. }
  70. )
  71. assert_response :success
  72. # Do not count subprojects issues
  73. assert_select 'table.list tbody :nth-child(1):first' do
  74. assert_select 'td', :text => 'Bug'
  75. assert_select ':nth-child(2)', :text => '3' # open
  76. assert_select ':nth-child(3)', :text => '3' # closed
  77. assert_select ':nth-child(4)', :text => '6' # total
  78. end
  79. assert_select 'table.issue-report td.name', :text => 'Support request', :count => 0
  80. end
  81. end
  82. def test_get_issue_report_details
  83. %w(tracker version priority category assigned_to author subproject).each do |detail|
  84. get(
  85. :issue_report_details,
  86. :params => {
  87. :id => 1,
  88. :detail => detail
  89. }
  90. )
  91. assert_response :success
  92. end
  93. end
  94. def test_get_issue_report_details_by_tracker_should_show_only_statuses_used_by_the_project
  95. WorkflowTransition.delete_all
  96. WorkflowTransition.create(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 5)
  97. WorkflowTransition.create(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
  98. WorkflowTransition.create(:role_id => 1, :tracker_id => 1, :old_status_id => 2, :new_status_id => 5)
  99. WorkflowTransition.create(:role_id => 1, :tracker_id => 2, :old_status_id => 1, :new_status_id => 6)
  100. WorkflowTransition.create(:role_id => 1, :tracker_id => 2, :old_status_id => 3, :new_status_id => 3)
  101. with_settings :display_subprojects_issues => '0' do
  102. get(:issue_report_details, :params => {:id => 1, :detail => 'tracker'})
  103. end
  104. assert_response :success
  105. assert_select 'table.list tbody :nth-child(1)' do
  106. assert_select 'td', :text => 'Bug'
  107. assert_select ':nth-child(2)', :text => '3' # status:1
  108. assert_select ':nth-child(3)', :text => '-' # status:2
  109. assert_select ':nth-child(4)', :text => '-' # status:4
  110. assert_select ':nth-child(5)', :text => '3' # status:5
  111. assert_select ':nth-child(6)', :text => '-' # status:6
  112. assert_select ':nth-child(7)', :text => '3' # open
  113. assert_select ':nth-child(8)', :text => '3' # closed
  114. assert_select ':nth-child(9)', :text => '6' # total
  115. end
  116. end
  117. def test_get_issue_report_details_by_tracker_with_subprojects_issues
  118. project = Project.find(1)
  119. tracker = project.trackers.find_by(:name => 'Support request')
  120. project.trackers.delete(tracker)
  121. with_settings :display_subprojects_issues => '1' do
  122. get(
  123. :issue_report_details,
  124. :params => {
  125. :id => 1,
  126. :detail => 'tracker'
  127. }
  128. )
  129. assert_response :success
  130. # Count subprojects issues
  131. assert_select 'table.list tbody :nth-child(1)' do
  132. assert_select 'td', :text => 'Bug'
  133. assert_select ':nth-child(2)', :text => '5' # status:1
  134. assert_select ':nth-child(3)', :text => '-' # status:2
  135. assert_select ':nth-child(4)', :text => '-' # status:3
  136. assert_select ':nth-child(5)', :text => '-' # status:4
  137. assert_select ':nth-child(6)', :text => '3' # status:5
  138. assert_select ':nth-child(7)', :text => '-' # status:6
  139. assert_select ':nth-child(8)', :text => '5' # open
  140. assert_select ':nth-child(9)', :text => '3' # closed
  141. assert_select ':nth-child(10)', :text => '8' # total
  142. end
  143. assert_select 'table.issue-report-detailed td.name', :text => 'Support request', :count => 1
  144. end
  145. end
  146. def test_get_issue_report_details_by_tracker_without_subprojects_issues
  147. project = Project.find(1)
  148. tracker = project.trackers.find_by(:name => 'Support request')
  149. project.trackers.delete(tracker)
  150. with_settings :display_subprojects_issues => '0' do
  151. get :issue_report_details, :params => {
  152. :id => 1,
  153. :detail => 'tracker'
  154. }
  155. assert_response :success
  156. # Do not count subprojects issues
  157. assert_select 'table.list tbody :nth-child(1)' do
  158. assert_select 'td', :text => 'Bug'
  159. assert_select ':nth-child(2)', :text => '3' # status:1
  160. assert_select ':nth-child(3)', :text => '-' # status:2
  161. assert_select ':nth-child(4)', :text => '-' # status:3
  162. assert_select ':nth-child(5)', :text => '-' # status:4
  163. assert_select ':nth-child(6)', :text => '3' # status:5
  164. assert_select ':nth-child(7)', :text => '-' # status:6
  165. assert_select ':nth-child(8)', :text => '3' # open
  166. assert_select ':nth-child(9)', :text => '3' # closed
  167. assert_select ':nth-child(10)', :text => '6' # total
  168. end
  169. assert_select 'table.issue-report td.name', :text => 'Support request', :count => 0
  170. end
  171. end
  172. def test_get_issue_report_details_by_tracker_should_show_issue_count
  173. Issue.delete_all
  174. Issue.generate!(:tracker_id => 1)
  175. Issue.generate!(:tracker_id => 1)
  176. Issue.generate!(:tracker_id => 1, :status_id => 5)
  177. Issue.generate!(:tracker_id => 2)
  178. get(
  179. :issue_report_details,
  180. :params => {
  181. :id => 1,
  182. :detail => 'tracker'
  183. }
  184. )
  185. assert_select 'table.list tbody :nth-child(1)' do
  186. assert_select 'td', :text => 'Bug'
  187. assert_select ':nth-child(2)', :text => '2' # status:1
  188. assert_select ':nth-child(3)', :text => '-' # status:2
  189. assert_select ':nth-child(8)', :text => '2' # open
  190. assert_select ':nth-child(9)', :text => '1' # closed
  191. assert_select ':nth-child(10)', :text => '3' # total
  192. end
  193. end
  194. def test_get_issue_report_details_by_assignee_should_show_non_assigned_issue_count
  195. Issue.delete_all
  196. Issue.generate!
  197. Issue.generate!
  198. Issue.generate!(:status_id => 5)
  199. Issue.generate!(:assigned_to_id => 2)
  200. get(
  201. :issue_report_details,
  202. :params => {
  203. :id => 1,
  204. :detail => 'assigned_to'
  205. }
  206. )
  207. assert_select 'table.list tbody :last-child' do
  208. assert_select 'td', :text => "[#{I18n.t(:label_none)}]"
  209. assert_select ':nth-child(2)', :text => '2' # status:1
  210. assert_select ':nth-child(6)', :text => '1' # status:5
  211. assert_select ':nth-child(8)', :text => '2' # open
  212. assert_select ':nth-child(9)', :text => '1' # closed
  213. assert_select ':nth-child(10)', :text => '3' # total
  214. end
  215. end
  216. def test_get_issue_report_details_with_an_invalid_detail
  217. get(
  218. :issue_report_details,
  219. :params => {
  220. :id => 1,
  221. :detail => 'invalid'
  222. }
  223. )
  224. assert_response :not_found
  225. end
  226. def test_issue_report_details_should_csv_export
  227. %w(tracker version priority category assigned_to author subproject).each do |detail|
  228. get(
  229. :issue_report_details,
  230. params: {
  231. id: 1,
  232. detail: detail,
  233. format: 'csv'
  234. }
  235. )
  236. assert_response :success
  237. assert_equal 'text/csv; header=present', response.media_type
  238. end
  239. end
  240. def test_issue_report_details_with_tracker_detail_should_csv_export
  241. project = Project.find(1)
  242. tracker = project.trackers.find_by(:name => 'Support request')
  243. project.trackers.delete(tracker)
  244. with_settings :display_subprojects_issues => '1' do
  245. get(
  246. :issue_report_details,
  247. params: {
  248. id: 1,
  249. detail: 'tracker',
  250. format: 'csv'
  251. }
  252. )
  253. assert_response :success
  254. assert_equal 'text/csv; header=present', response.media_type
  255. lines = response.body.chomp.split("\n")
  256. # Number of lines
  257. rows = Project.find(1).rolled_up_trackers(true).visible
  258. assert_equal rows.size + 1, lines.size
  259. # Header
  260. assert_equal '"",New,Assigned,Resolved,Feedback,Closed,Rejected,open,closed,Total', lines.first
  261. # Details
  262. to_test = [
  263. 'Bug,5,0,0,0,3,0,5,3,8',
  264. 'Feature request,0,1,0,0,0,0,1,0,1',
  265. 'Support request,0,0,0,0,0,0,0,0,0'
  266. ]
  267. to_test.each do |expected|
  268. assert_includes lines, expected
  269. end
  270. end
  271. end
  272. def test_issue_report_details_with_assigned_to_detail_should_csv_export
  273. Issue.delete_all
  274. Issue.generate!
  275. Issue.generate!
  276. Issue.generate!(:status_id => 5)
  277. Issue.generate!(:assigned_to_id => 2)
  278. with_settings :issue_group_assignment => '1' do
  279. get(
  280. :issue_report_details,
  281. params: {
  282. id: 1,
  283. detail: 'assigned_to',
  284. format: 'csv'
  285. }
  286. )
  287. assert_response :success
  288. assert_equal 'text/csv; header=present', response.media_type
  289. lines = response.body.chomp.split("\n")
  290. # Number of lines
  291. rows = Project.find(1).principals.sorted + [I18n.t(:label_none)]
  292. assert_equal rows.size + 1, lines.size
  293. # Header
  294. assert_equal '"",New,Assigned,Resolved,Feedback,Closed,Rejected,open,closed,Total', lines.first
  295. # Details
  296. to_test = [
  297. 'Dave Lopper,0,0,0,0,0,0,0,0,0',
  298. 'John Smith,1,0,0,0,0,0,1,0,1',
  299. '[none] ,2,0,0,0,1,0,2,1,3'
  300. ]
  301. to_test.each do |expected|
  302. assert_includes lines, expected
  303. end
  304. end
  305. end
  306. end