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.

versions_controller_test.rb 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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 VersionsControllerTest < ActionController::TestCase
  19. fixtures :projects, :versions, :issues, :users, :roles, :members,
  20. :member_roles, :enabled_modules, :issue_statuses,
  21. :issue_categories
  22. def setup
  23. User.current = nil
  24. end
  25. def test_index
  26. get :index, :project_id => 1
  27. assert_response :success
  28. assert_template 'index'
  29. assert_not_nil assigns(:versions)
  30. # Version with no date set appears
  31. assert assigns(:versions).include?(Version.find(3))
  32. # Completed version doesn't appear
  33. assert !assigns(:versions).include?(Version.find(1))
  34. # Context menu on issues
  35. assert_select "script", :text => Regexp.new(Regexp.escape("contextMenuInit('/issues/context_menu')"))
  36. assert_select "div#sidebar" do
  37. # Links to versions anchors
  38. assert_select 'a[href=?]', '#2.0'
  39. # Links to completed versions in the sidebar
  40. assert_select 'a[href=?]', '/versions/1'
  41. end
  42. end
  43. def test_index_with_completed_versions
  44. get :index, :project_id => 1, :completed => 1
  45. assert_response :success
  46. assert_template 'index'
  47. assert_not_nil assigns(:versions)
  48. # Version with no date set appears
  49. assert assigns(:versions).include?(Version.find(3))
  50. # Completed version appears
  51. assert assigns(:versions).include?(Version.find(1))
  52. end
  53. def test_index_with_tracker_ids
  54. get :index, :project_id => 1, :tracker_ids => [1, 3]
  55. assert_response :success
  56. assert_template 'index'
  57. assert_not_nil assigns(:issues_by_version)
  58. assert_nil assigns(:issues_by_version).values.flatten.detect {|issue| issue.tracker_id == 2}
  59. end
  60. def test_index_showing_subprojects_versions
  61. @subproject_version = Version.create!(:project => Project.find(3), :name => "Subproject version")
  62. get :index, :project_id => 1, :with_subprojects => 1
  63. assert_response :success
  64. assert_template 'index'
  65. assert_not_nil assigns(:versions)
  66. assert assigns(:versions).include?(Version.find(4)), "Shared version not found"
  67. assert assigns(:versions).include?(@subproject_version), "Subproject version not found"
  68. end
  69. def test_index_should_prepend_shared_versions
  70. get :index, :project_id => 1
  71. assert_response :success
  72. assert_select '#sidebar' do
  73. assert_select 'a[href=?]', '#2.0', :text => '2.0'
  74. assert_select 'a[href=?]', '#subproject1-2.0', :text => 'eCookbook Subproject 1 - 2.0'
  75. end
  76. assert_select '#content' do
  77. assert_select 'a[name=?]', '2.0', :text => '2.0'
  78. assert_select 'a[name=?]', 'subproject1-2.0', :text => 'eCookbook Subproject 1 - 2.0'
  79. end
  80. end
  81. def test_show
  82. get :show, :id => 2
  83. assert_response :success
  84. assert_template 'show'
  85. assert_not_nil assigns(:version)
  86. assert_tag :tag => 'h2', :content => /1.0/
  87. end
  88. def test_show_should_display_nil_counts
  89. with_settings :default_language => 'en' do
  90. get :show, :id => 2, :status_by => 'category'
  91. assert_response :success
  92. assert_select 'div#status_by' do
  93. assert_select 'select[name=status_by]' do
  94. assert_select 'option[value=category][selected=selected]'
  95. end
  96. assert_select 'a', :text => 'none'
  97. end
  98. end
  99. end
  100. def test_new
  101. @request.session[:user_id] = 2
  102. get :new, :project_id => '1'
  103. assert_response :success
  104. assert_template 'new'
  105. end
  106. def test_new_from_issue_form
  107. @request.session[:user_id] = 2
  108. xhr :get, :new, :project_id => '1'
  109. assert_response :success
  110. assert_template 'new'
  111. assert_equal 'text/javascript', response.content_type
  112. end
  113. def test_create
  114. @request.session[:user_id] = 2 # manager
  115. assert_difference 'Version.count' do
  116. post :create, :project_id => '1', :version => {:name => 'test_add_version'}
  117. end
  118. assert_redirected_to '/projects/ecookbook/settings/versions'
  119. version = Version.find_by_name('test_add_version')
  120. assert_not_nil version
  121. assert_equal 1, version.project_id
  122. end
  123. def test_create_from_issue_form
  124. @request.session[:user_id] = 2
  125. assert_difference 'Version.count' do
  126. xhr :post, :create, :project_id => '1', :version => {:name => 'test_add_version_from_issue_form'}
  127. end
  128. version = Version.find_by_name('test_add_version_from_issue_form')
  129. assert_not_nil version
  130. assert_equal 1, version.project_id
  131. assert_response :success
  132. assert_template 'create'
  133. assert_equal 'text/javascript', response.content_type
  134. assert_include 'test_add_version_from_issue_form', response.body
  135. end
  136. def test_create_from_issue_form_with_failure
  137. @request.session[:user_id] = 2
  138. assert_no_difference 'Version.count' do
  139. xhr :post, :create, :project_id => '1', :version => {:name => ''}
  140. end
  141. assert_response :success
  142. assert_template 'new'
  143. assert_equal 'text/javascript', response.content_type
  144. end
  145. def test_get_edit
  146. @request.session[:user_id] = 2
  147. get :edit, :id => 2
  148. assert_response :success
  149. assert_template 'edit'
  150. end
  151. def test_close_completed
  152. Version.update_all("status = 'open'")
  153. @request.session[:user_id] = 2
  154. put :close_completed, :project_id => 'ecookbook'
  155. assert_redirected_to :controller => 'projects', :action => 'settings',
  156. :tab => 'versions', :id => 'ecookbook'
  157. assert_not_nil Version.find_by_status('closed')
  158. end
  159. def test_post_update
  160. @request.session[:user_id] = 2
  161. put :update, :id => 2,
  162. :version => {:name => 'New version name',
  163. :effective_date => Date.today.strftime("%Y-%m-%d")}
  164. assert_redirected_to :controller => 'projects', :action => 'settings',
  165. :tab => 'versions', :id => 'ecookbook'
  166. version = Version.find(2)
  167. assert_equal 'New version name', version.name
  168. assert_equal Date.today, version.effective_date
  169. end
  170. def test_post_update_with_validation_failure
  171. @request.session[:user_id] = 2
  172. put :update, :id => 2,
  173. :version => { :name => '',
  174. :effective_date => Date.today.strftime("%Y-%m-%d")}
  175. assert_response :success
  176. assert_template 'edit'
  177. end
  178. def test_destroy
  179. @request.session[:user_id] = 2
  180. assert_difference 'Version.count', -1 do
  181. delete :destroy, :id => 3
  182. end
  183. assert_redirected_to :controller => 'projects', :action => 'settings',
  184. :tab => 'versions', :id => 'ecookbook'
  185. assert_nil Version.find_by_id(3)
  186. end
  187. def test_destroy_version_in_use_should_fail
  188. @request.session[:user_id] = 2
  189. assert_no_difference 'Version.count' do
  190. delete :destroy, :id => 2
  191. end
  192. assert_redirected_to :controller => 'projects', :action => 'settings',
  193. :tab => 'versions', :id => 'ecookbook'
  194. assert flash[:error].match(/Unable to delete version/)
  195. assert Version.find_by_id(2)
  196. end
  197. def test_issue_status_by
  198. xhr :get, :status_by, :id => 2
  199. assert_response :success
  200. assert_template 'status_by'
  201. assert_template '_issue_counts'
  202. end
  203. def test_issue_status_by_status
  204. xhr :get, :status_by, :id => 2, :status_by => 'status'
  205. assert_response :success
  206. assert_template 'status_by'
  207. assert_template '_issue_counts'
  208. assert_include 'Assigned', response.body
  209. assert_include 'Closed', response.body
  210. end
  211. end