You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

versions_controller_test.rb 8.4 kB

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

软件技术创新是当今国家整体创新能力的重要基础和发展引擎。近年来,大众参与的软件创新与创业活动已经成为网络时代软件开发和应用的新形态,正在快速改变着全球软件创新模式和软件产业格局。 ...