Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

versions_controller_test.rb 9.3KB

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