annotate .svn/pristine/54/547682ef5ea0e2a3da7440949449d21631f7fc4b.svn-base @ 929:5f33065ddc4b redmine-1.3

Update to Redmine SVN rev 9414 on 1.3-stable branch
author Chris Cannam
date Wed, 27 Jun 2012 14:54:18 +0100
parents cbb26bc654de
children
rev   line source
Chris@909 1 # Redmine - project management software
Chris@909 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@909 3 #
Chris@909 4 # This program is free software; you can redistribute it and/or
Chris@909 5 # modify it under the terms of the GNU General Public License
Chris@909 6 # as published by the Free Software Foundation; either version 2
Chris@909 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@909 9 # This program is distributed in the hope that it will be useful,
Chris@909 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@909 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@909 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@909 14 # You should have received a copy of the GNU General Public License
Chris@909 15 # along with this program; if not, write to the Free Software
Chris@909 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@909 17
Chris@909 18 require File.expand_path('../../test_helper', __FILE__)
Chris@909 19 require 'trackers_controller'
Chris@909 20
Chris@909 21 # Re-raise errors caught by the controller.
Chris@909 22 class TrackersController; def rescue_action(e) raise e end; end
Chris@909 23
Chris@909 24 class TrackersControllerTest < ActionController::TestCase
Chris@909 25 fixtures :trackers, :projects, :projects_trackers, :users, :issues, :custom_fields
Chris@909 26
Chris@909 27 def setup
Chris@909 28 @controller = TrackersController.new
Chris@909 29 @request = ActionController::TestRequest.new
Chris@909 30 @response = ActionController::TestResponse.new
Chris@909 31 User.current = nil
Chris@909 32 @request.session[:user_id] = 1 # admin
Chris@909 33 end
Chris@909 34
Chris@909 35 def test_index
Chris@909 36 get :index
Chris@909 37 assert_response :success
Chris@909 38 assert_template 'index'
Chris@909 39 end
Chris@909 40
Chris@909 41 def test_index_by_anonymous_should_redirect_to_login_form
Chris@909 42 @request.session[:user_id] = nil
Chris@909 43 get :index
Chris@909 44 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Ftrackers'
Chris@909 45 end
Chris@909 46
Chris@909 47 def test_index_by_user_should_respond_with_406
Chris@909 48 @request.session[:user_id] = 2
Chris@909 49 get :index
Chris@909 50 assert_response 406
Chris@909 51 end
Chris@909 52
Chris@909 53 def test_new
Chris@909 54 get :new
Chris@909 55 assert_response :success
Chris@909 56 assert_template 'new'
Chris@909 57 end
Chris@909 58
Chris@909 59 def test_create
Chris@909 60 assert_difference 'Tracker.count' do
Chris@909 61 post :create, :tracker => { :name => 'New tracker', :project_ids => ['1', '', ''], :custom_field_ids => ['1', '6', ''] }
Chris@909 62 end
Chris@909 63 assert_redirected_to :action => 'index'
Chris@909 64 tracker = Tracker.first(:order => 'id DESC')
Chris@909 65 assert_equal 'New tracker', tracker.name
Chris@909 66 assert_equal [1], tracker.project_ids.sort
Chris@909 67 assert_equal [1, 6], tracker.custom_field_ids
Chris@909 68 assert_equal 0, tracker.workflows.count
Chris@909 69 end
Chris@909 70
Chris@909 71 def test_create_new_with_workflow_copy
Chris@909 72 assert_difference 'Tracker.count' do
Chris@909 73 post :create, :tracker => { :name => 'New tracker' }, :copy_workflow_from => 1
Chris@909 74 end
Chris@909 75 assert_redirected_to :action => 'index'
Chris@909 76 tracker = Tracker.find_by_name('New tracker')
Chris@909 77 assert_equal 0, tracker.projects.count
Chris@909 78 assert_equal Tracker.find(1).workflows.count, tracker.workflows.count
Chris@909 79 end
Chris@909 80
Chris@909 81 def test_create_new_failure
Chris@909 82 assert_no_difference 'Tracker.count' do
Chris@909 83 post :create, :tracker => { :name => '', :project_ids => ['1', '', ''], :custom_field_ids => ['1', '6', ''] }
Chris@909 84 end
Chris@909 85 assert_response :success
Chris@909 86 assert_template 'new'
Chris@909 87 end
Chris@909 88
Chris@909 89 def test_edit
Chris@909 90 Tracker.find(1).project_ids = [1, 3]
Chris@909 91
Chris@909 92 get :edit, :id => 1
Chris@909 93 assert_response :success
Chris@909 94 assert_template 'edit'
Chris@909 95
Chris@909 96 assert_tag :input, :attributes => { :name => 'tracker[project_ids][]',
Chris@909 97 :value => '1',
Chris@909 98 :checked => 'checked' }
Chris@909 99
Chris@909 100 assert_tag :input, :attributes => { :name => 'tracker[project_ids][]',
Chris@909 101 :value => '2',
Chris@909 102 :checked => nil }
Chris@909 103
Chris@909 104 assert_tag :input, :attributes => { :name => 'tracker[project_ids][]',
Chris@909 105 :value => '',
Chris@909 106 :type => 'hidden'}
Chris@909 107 end
Chris@909 108
Chris@909 109 def test_update
Chris@909 110 put :update, :id => 1, :tracker => { :name => 'Renamed',
Chris@909 111 :project_ids => ['1', '2', ''] }
Chris@909 112 assert_redirected_to :action => 'index'
Chris@909 113 assert_equal [1, 2], Tracker.find(1).project_ids.sort
Chris@909 114 end
Chris@909 115
Chris@909 116 def test_update_without_projects
Chris@909 117 put :update, :id => 1, :tracker => { :name => 'Renamed',
Chris@909 118 :project_ids => [''] }
Chris@909 119 assert_redirected_to :action => 'index'
Chris@909 120 assert Tracker.find(1).project_ids.empty?
Chris@909 121 end
Chris@909 122
Chris@909 123 def test_move_lower
Chris@909 124 tracker = Tracker.find_by_position(1)
Chris@909 125 put :update, :id => 1, :tracker => { :move_to => 'lower' }
Chris@909 126 assert_equal 2, tracker.reload.position
Chris@909 127 end
Chris@909 128
Chris@909 129 def test_destroy
Chris@909 130 tracker = Tracker.create!(:name => 'Destroyable')
Chris@909 131 assert_difference 'Tracker.count', -1 do
Chris@909 132 delete :destroy, :id => tracker.id
Chris@909 133 end
Chris@909 134 assert_redirected_to :action => 'index'
Chris@909 135 assert_nil flash[:error]
Chris@909 136 end
Chris@909 137
Chris@909 138 def test_destroy_tracker_in_use
Chris@909 139 assert_no_difference 'Tracker.count' do
Chris@909 140 delete :destroy, :id => 1
Chris@909 141 end
Chris@909 142 assert_redirected_to :action => 'index'
Chris@909 143 assert_not_nil flash[:error]
Chris@909 144 end
Chris@909 145 end