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 7.3KB

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