comparison test/functional/versions_controller_test.rb @ 1464:261b3d9a4903 redmine-2.4

Update to Redmine 2.4 branch rev 12663
author Chris Cannam
date Tue, 14 Jan 2014 14:37:42 +0000
parents 433d4f72a19b
children e248c7af89ec
comparison
equal deleted inserted replaced
1296:038ba2d95de8 1464:261b3d9a4903
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
14 # You should have received a copy of the GNU General Public License 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 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. 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 require File.expand_path('../../test_helper', __FILE__) 18 require File.expand_path('../../test_helper', __FILE__)
19 require 'versions_controller'
20
21 # Re-raise errors caught by the controller.
22 class VersionsController; def rescue_action(e) raise e end; end
23 19
24 class VersionsControllerTest < ActionController::TestCase 20 class VersionsControllerTest < ActionController::TestCase
25 fixtures :projects, :versions, :issues, :users, :roles, :members, :member_roles, :enabled_modules, :issue_statuses, :issue_categories 21 fixtures :projects, :versions, :issues, :users, :roles, :members,
22 :member_roles, :enabled_modules, :issue_statuses,
23 :issue_categories
26 24
27 def setup 25 def setup
28 @controller = VersionsController.new
29 @request = ActionController::TestRequest.new
30 @response = ActionController::TestResponse.new
31 User.current = nil 26 User.current = nil
32 end 27 end
33 28
34 def test_index 29 def test_index
35 get :index, :project_id => 1 30 get :index, :project_id => 1
40 assert assigns(:versions).include?(Version.find(3)) 35 assert assigns(:versions).include?(Version.find(3))
41 # Completed version doesn't appear 36 # Completed version doesn't appear
42 assert !assigns(:versions).include?(Version.find(1)) 37 assert !assigns(:versions).include?(Version.find(1))
43 # Context menu on issues 38 # Context menu on issues
44 assert_select "script", :text => Regexp.new(Regexp.escape("contextMenuInit('/issues/context_menu')")) 39 assert_select "script", :text => Regexp.new(Regexp.escape("contextMenuInit('/issues/context_menu')"))
45 # Links to versions anchors 40 assert_select "div#sidebar" do
46 assert_tag 'a', :attributes => {:href => '#2.0'}, 41 # Links to versions anchors
47 :ancestor => {:tag => 'div', :attributes => {:id => 'sidebar'}} 42 assert_select 'a[href=?]', '#2.0'
48 # Links to completed versions in the sidebar 43 # Links to completed versions in the sidebar
49 assert_tag 'a', :attributes => {:href => '/versions/1'}, 44 assert_select 'a[href=?]', '/versions/1'
50 :ancestor => {:tag => 'div', :attributes => {:id => 'sidebar'}} 45 end
51 end 46 end
52 47
53 def test_index_with_completed_versions 48 def test_index_with_completed_versions
54 get :index, :project_id => 1, :completed => 1 49 get :index, :project_id => 1, :completed => 1
55 assert_response :success 50 assert_response :success
176 171
177 def test_close_completed 172 def test_close_completed
178 Version.update_all("status = 'open'") 173 Version.update_all("status = 'open'")
179 @request.session[:user_id] = 2 174 @request.session[:user_id] = 2
180 put :close_completed, :project_id => 'ecookbook' 175 put :close_completed, :project_id => 'ecookbook'
181 assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' 176 assert_redirected_to :controller => 'projects', :action => 'settings',
177 :tab => 'versions', :id => 'ecookbook'
182 assert_not_nil Version.find_by_status('closed') 178 assert_not_nil Version.find_by_status('closed')
183 end 179 end
184 180
185 def test_post_update 181 def test_post_update
186 @request.session[:user_id] = 2 182 @request.session[:user_id] = 2
187 put :update, :id => 2, 183 put :update, :id => 2,
188 :version => { :name => 'New version name', 184 :version => {:name => 'New version name',
189 :effective_date => Date.today.strftime("%Y-%m-%d")} 185 :effective_date => Date.today.strftime("%Y-%m-%d")}
190 assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' 186 assert_redirected_to :controller => 'projects', :action => 'settings',
187 :tab => 'versions', :id => 'ecookbook'
191 version = Version.find(2) 188 version = Version.find(2)
192 assert_equal 'New version name', version.name 189 assert_equal 'New version name', version.name
193 assert_equal Date.today, version.effective_date 190 assert_equal Date.today, version.effective_date
194 end 191 end
195 192
205 def test_destroy 202 def test_destroy
206 @request.session[:user_id] = 2 203 @request.session[:user_id] = 2
207 assert_difference 'Version.count', -1 do 204 assert_difference 'Version.count', -1 do
208 delete :destroy, :id => 3 205 delete :destroy, :id => 3
209 end 206 end
210 assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' 207 assert_redirected_to :controller => 'projects', :action => 'settings',
208 :tab => 'versions', :id => 'ecookbook'
211 assert_nil Version.find_by_id(3) 209 assert_nil Version.find_by_id(3)
212 end 210 end
213 211
214 def test_destroy_version_in_use_should_fail 212 def test_destroy_version_in_use_should_fail
215 @request.session[:user_id] = 2 213 @request.session[:user_id] = 2
216 assert_no_difference 'Version.count' do 214 assert_no_difference 'Version.count' do
217 delete :destroy, :id => 2 215 delete :destroy, :id => 2
218 end 216 end
219 assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' 217 assert_redirected_to :controller => 'projects', :action => 'settings',
218 :tab => 'versions', :id => 'ecookbook'
220 assert flash[:error].match(/Unable to delete version/) 219 assert flash[:error].match(/Unable to delete version/)
221 assert Version.find_by_id(2) 220 assert Version.find_by_id(2)
222 end 221 end
223 222
224 def test_issue_status_by 223 def test_issue_status_by