Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

versions_controller_test.rb 11KB

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