Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

versions_controller_test.rb 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2023 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 VersionsControllerTest < Redmine::ControllerTest
  20. fixtures :projects, :enabled_modules,
  21. :trackers, :projects_trackers,
  22. :versions, :issue_statuses, :issue_categories, :enumerations,
  23. :issues,
  24. :users, :email_addresses,
  25. :roles, :members, :member_roles
  26. def setup
  27. User.current = nil
  28. end
  29. def test_index
  30. get :index, :params => {:project_id => 1}
  31. assert_response :success
  32. # Version with no date set appears
  33. assert_select 'h3', :text => "#{Version.find(3).name}"
  34. assert_select 'span[class=?]', 'badge badge-status-open', :text => 'open'
  35. # Completed version doesn't appear
  36. assert_select 'h3', :text => Version.find(1).name, :count => 0
  37. # Context menu on issues
  38. assert_select "form[data-cm-url=?]", '/issues/context_menu'
  39. assert_select "div#sidebar" do
  40. # Tracker checkboxes
  41. assert_select 'input[type=hidden][name=?]', 'tracker_ids[]'
  42. assert_select 'input[type=checkbox][name=?]', 'tracker_ids[]', 3
  43. # Links to versions anchors
  44. assert_select 'a[href=?]', '#2.0'
  45. # Links to completed versions in the sidebar
  46. assert_select 'a[href=?]', '/versions/1'
  47. end
  48. end
  49. def test_index_with_completed_versions
  50. get :index, :params => {:project_id => 1, :completed => 1}
  51. assert_response :success
  52. # Version with no date set appears
  53. assert_select 'h3', :text => Version.find(3).name
  54. # Completed version appears
  55. assert_select 'h3', :text => Version.find(1).name
  56. end
  57. def test_index_with_tracker_ids
  58. (1..3).each do |tracker_id|
  59. Issue.generate! :project_id => 1, :fixed_version_id => 3, :tracker_id => tracker_id
  60. end
  61. get :index, :params => {:project_id => 1, :tracker_ids => [1, 3]}
  62. assert_response :success
  63. assert_select 'a.issue.tracker-1'
  64. assert_select 'a.issue.tracker-2', 0
  65. assert_select 'a.issue.tracker-3'
  66. end
  67. def test_index_showing_subprojects_versions
  68. version_name = "Subproject version"
  69. Version.create!(:project => Project.find(3), :name => version_name)
  70. get :index, :params => {:project_id => 1, :with_subprojects => 1}
  71. assert_response :success
  72. # Shared version
  73. assert_select 'h3', :text => Version.find(4).name
  74. # Subproject version
  75. assert_select 'h3', :text => /#{version_name}/
  76. end
  77. def test_index_should_prepend_shared_versions
  78. get :index, :params => {:project_id => 1}
  79. assert_response :success
  80. assert_select '#sidebar' do
  81. assert_select 'a[href=?]', '#2.0', :text => '2.0'
  82. assert_select 'a[href=?]', '#subproject1-2.0', :text => 'eCookbook Subproject 1 - 2.0'
  83. end
  84. assert_select '#content' do
  85. assert_select 'a[name=?]', '2.0', :text => '2.0'
  86. assert_select 'a[name=?]', 'subproject1-2.0', :text => 'eCookbook Subproject 1 - 2.0'
  87. end
  88. end
  89. def test_index_should_show_issue_assignee
  90. with_settings :gravatar_enabled => '1' do
  91. Issue.generate!(:project_id => 3, :fixed_version_id => 4, :assigned_to => User.find_by_login('jsmith'))
  92. Issue.generate!(:project_id => 3, :fixed_version_id => 4)
  93. get :index, :params => {:project_id => 3}
  94. assert_response :success
  95. assert_select 'table.related-issues' do
  96. assert_select 'tr.issue', :count => 2 do
  97. assert_select 'img.gravatar[title=?]', 'Assignee: John Smith', :count => 1
  98. end
  99. end
  100. end
  101. end
  102. def test_show
  103. with_settings :gravatar_enabled => '0' do
  104. get :show, :params => {:id => 2}
  105. assert_response :success
  106. assert_select 'h2', :text => /1.0/
  107. assert_select 'span[class=?]', 'badge badge-status-locked', :text => 'locked'
  108. # no issue avatar when gravatar is disabled
  109. assert_select 'img.gravatar', :count => 0
  110. end
  111. end
  112. def test_show_should_show_issue_assignee
  113. with_settings :gravatar_enabled => '1' do
  114. get :show, :params => {:id => 2}
  115. assert_response :success
  116. assert_select 'table.related-issues' do
  117. assert_select 'tr.issue td.assigned_to', :count => 2 do
  118. assert_select 'img.gravatar[title=?]', 'Assignee: Dave Lopper', :count => 1
  119. end
  120. end
  121. end
  122. end
  123. def test_show_issue_calculations_should_take_into_account_only_visible_issues
  124. issue_9 = Issue.find(9)
  125. issue_9.fixed_version_id = 4
  126. issue_9.estimated_hours = 3
  127. issue_9.save!
  128. issue_13 = Issue.find(13)
  129. issue_13.fixed_version_id = 4
  130. issue_13.estimated_hours = 2
  131. issue_13.save!
  132. @request.session[:user_id] = 7
  133. get :show, :params => {:id => 4}
  134. assert_response :success
  135. assert_select 'p.progress-info' do
  136. assert_select 'a', :text => '1 issue'
  137. assert_select 'a', :text => '1 open'
  138. end
  139. assert_select '.time-tracking td.total-hours a:first-child', :text => '2:00 hours'
  140. end
  141. def test_show_should_link_to_spent_time_on_version
  142. version = Version.generate!
  143. issue = Issue.generate(:fixed_version => version)
  144. TimeEntry.generate!(:issue => issue, :hours => 7.2)
  145. get :show, :params => {:id => version.id}
  146. assert_response :success
  147. assert_select '.total-hours', :text => '7:12 hours'
  148. assert_select '.total-hours a[href=?]', "/projects/ecookbook/time_entries?issue.fixed_version_id=#{version.id}&set_filter=1"
  149. end
  150. def test_show_should_display_nil_counts
  151. with_settings :default_language => 'en' do
  152. get :show, :params => {:id => 2, :status_by => 'category'}
  153. assert_response :success
  154. assert_select 'div#status_by' do
  155. assert_select 'select[name=status_by]' do
  156. assert_select 'option[value=category][selected=selected]'
  157. end
  158. assert_select 'a', :text => 'none'
  159. end
  160. end
  161. end
  162. def test_show_should_round_down_progress_percentages
  163. issue = Issue.find(12)
  164. issue.estimated_hours = 40
  165. issue.save!
  166. with_settings :default_language => 'en' do
  167. get :show, :params => {:id => 2}
  168. assert_response :success
  169. assert_select 'div.version-overview' do
  170. assert_select 'table.progress-98' do
  171. assert_select 'td[class=closed][title=?]', 'closed: 98%'
  172. assert_select 'td[class=done][title=?]', '% Done: 99%'
  173. end
  174. assert_select 'p[class=percent]', :text => '99%'
  175. end
  176. end
  177. end
  178. def test_show_should_display_link_to_new_issue
  179. @request.session[:user_id] = 1
  180. get :show, :params => {:id => 3}
  181. assert_response :success
  182. assert_select 'a.icon.icon-add', :text => 'New issue'
  183. end
  184. def test_new
  185. @request.session[:user_id] = 2
  186. get :new, :params => {:project_id => '1'}
  187. assert_response :success
  188. assert_select 'input[name=?]', 'version[name]'
  189. assert_select 'select[name=?]', 'version[status]', false
  190. end
  191. def test_new_from_issue_form
  192. @request.session[:user_id] = 2
  193. get :new, :params => {:project_id => '1'}, :xhr => true
  194. assert_response :success
  195. assert_equal 'text/javascript', response.media_type
  196. end
  197. def test_create
  198. @request.session[:user_id] = 2 # manager
  199. assert_difference 'Version.count' do
  200. post :create, :params => {:project_id => '1', :version => {:name => 'test_add_version'}}
  201. end
  202. assert_redirected_to '/projects/ecookbook/settings/versions'
  203. version = Version.find_by_name('test_add_version')
  204. assert_not_nil version
  205. assert_equal 1, version.project_id
  206. end
  207. def test_create_from_issue_form
  208. @request.session[:user_id] = 2
  209. assert_difference 'Version.count' do
  210. post :create, :params => {:project_id => '1', :version => {:name => 'test_add_version_from_issue_form'}}, :xhr => true
  211. end
  212. version = Version.find_by_name('test_add_version_from_issue_form')
  213. assert_not_nil version
  214. assert_equal 1, version.project_id
  215. assert_response :success
  216. assert_equal 'text/javascript', response.media_type
  217. assert_include 'test_add_version_from_issue_form', response.body
  218. end
  219. def test_create_from_issue_form_with_failure
  220. @request.session[:user_id] = 2
  221. assert_no_difference 'Version.count' do
  222. post :create, :params => {:project_id => '1', :version => {:name => ''}}, :xhr => true
  223. end
  224. assert_response :success
  225. assert_equal 'text/javascript', response.media_type
  226. end
  227. def test_get_edit
  228. @request.session[:user_id] = 2
  229. get :edit, :params => {:id => 2}
  230. assert_response :success
  231. version = Version.find(2)
  232. assert_select 'select[name=?]', 'version[status]' do
  233. assert_select 'option[value=?][selected="selected"]', version.status
  234. end
  235. assert_select 'input[name=?][value=?]', 'version[name]', version.name
  236. end
  237. def test_close_completed
  238. Version.update_all("status = 'open'")
  239. @request.session[:user_id] = 2
  240. put :close_completed, :params => {:project_id => 'ecookbook'}
  241. assert_redirected_to :controller => 'projects', :action => 'settings',
  242. :tab => 'versions', :id => 'ecookbook'
  243. assert_not_nil Version.find_by_status('closed')
  244. end
  245. def test_post_update
  246. @request.session[:user_id] = 2
  247. put :update, :params => {
  248. :id => 2,
  249. :version => {
  250. :name => 'New version name',
  251. :effective_date => Date.today.strftime("%Y-%m-%d")
  252. }
  253. }
  254. assert_redirected_to :controller => 'projects', :action => 'settings',
  255. :tab => 'versions', :id => 'ecookbook'
  256. version = Version.find(2)
  257. assert_equal 'New version name', version.name
  258. assert_equal Date.today, version.effective_date
  259. end
  260. def test_post_update_with_validation_failure
  261. @request.session[:user_id] = 2
  262. put :update, :params => {
  263. :id => 2,
  264. :version => {
  265. :name => '',
  266. :effective_date => Date.today.strftime("%Y-%m-%d")
  267. }
  268. }
  269. assert_response :success
  270. assert_select_error /Name cannot be blank/
  271. end
  272. def test_destroy
  273. @request.session[:user_id] = 2
  274. assert_difference 'Version.count', -1 do
  275. delete :destroy, :params => {:id => 3}
  276. end
  277. assert_redirected_to :controller => 'projects', :action => 'settings',
  278. :tab => 'versions', :id => 'ecookbook'
  279. assert_nil Version.find_by_id(3)
  280. end
  281. def test_destroy_version_in_use_should_fail
  282. @request.session[:user_id] = 2
  283. assert_no_difference 'Version.count' do
  284. delete :destroy, :params => {:id => 2}
  285. end
  286. assert_redirected_to :controller => 'projects', :action => 'settings',
  287. :tab => 'versions', :id => 'ecookbook'
  288. assert flash[:error].include?('Unable to delete version')
  289. assert Version.find_by_id(2)
  290. end
  291. def test_issue_status_by
  292. get :status_by, :params => {:id => 2}, :xhr => true
  293. assert_response :success
  294. end
  295. def test_issue_status_by_status
  296. get :status_by, :params => {:id => 2, :status_by => 'status'}, :xhr => true
  297. assert_response :success
  298. assert_include 'Assigned', response.body
  299. assert_include 'Closed', response.body
  300. end
  301. end