annotate test/functional/trackers_controller_test.rb @ 1082:997f6d7738f7 bug_531

In repo controller entry action, show the page for the file even if it's binary (so user still has access to history etc links). This makes it possible to use the entry action as the default when a file is clicked on
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 22 Nov 2012 18:04:17 +0000
parents 5f33065ddc4b
children 433d4f72a19b
rev   line source
Chris@0 1 # Redmine - project management software
Chris@909 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@119 18 require File.expand_path('../../test_helper', __FILE__)
Chris@0 19 require 'trackers_controller'
Chris@0 20
Chris@0 21 # Re-raise errors caught by the controller.
Chris@0 22 class TrackersController; def rescue_action(e) raise e end; end
Chris@0 23
Chris@0 24 class TrackersControllerTest < ActionController::TestCase
Chris@0 25 fixtures :trackers, :projects, :projects_trackers, :users, :issues, :custom_fields
Chris@909 26
Chris@0 27 def setup
Chris@0 28 @controller = TrackersController.new
Chris@0 29 @request = ActionController::TestRequest.new
Chris@0 30 @response = ActionController::TestResponse.new
Chris@0 31 User.current = nil
Chris@0 32 @request.session[:user_id] = 1 # admin
Chris@0 33 end
Chris@909 34
Chris@0 35 def test_index
Chris@0 36 get :index
Chris@0 37 assert_response :success
Chris@0 38 assert_template 'index'
Chris@0 39 end
Chris@0 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@0 54 get :new
Chris@0 55 assert_response :success
Chris@0 56 assert_template 'new'
Chris@0 57 end
Chris@0 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@0 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@0 66 assert_equal [1], tracker.project_ids.sort
Chris@929 67 assert_equal [1, 6], tracker.custom_field_ids.sort
Chris@0 68 assert_equal 0, tracker.workflows.count
Chris@0 69 end
Chris@0 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@0 75 assert_redirected_to :action => 'index'
Chris@0 76 tracker = Tracker.find_by_name('New tracker')
Chris@0 77 assert_equal 0, tracker.projects.count
Chris@0 78 assert_equal Tracker.find(1).workflows.count, tracker.workflows.count
Chris@0 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@0 90 Tracker.find(1).project_ids = [1, 3]
Chris@909 91
Chris@0 92 get :edit, :id => 1
Chris@0 93 assert_response :success
Chris@0 94 assert_template 'edit'
Chris@909 95
Chris@0 96 assert_tag :input, :attributes => { :name => 'tracker[project_ids][]',
Chris@0 97 :value => '1',
Chris@0 98 :checked => 'checked' }
Chris@909 99
Chris@0 100 assert_tag :input, :attributes => { :name => 'tracker[project_ids][]',
Chris@0 101 :value => '2',
Chris@0 102 :checked => nil }
Chris@909 103
Chris@0 104 assert_tag :input, :attributes => { :name => 'tracker[project_ids][]',
Chris@0 105 :value => '',
Chris@0 106 :type => 'hidden'}
Chris@0 107 end
Chris@0 108
Chris@909 109 def test_update
Chris@909 110 put :update, :id => 1, :tracker => { :name => 'Renamed',
Chris@0 111 :project_ids => ['1', '2', ''] }
Chris@0 112 assert_redirected_to :action => 'index'
Chris@0 113 assert_equal [1, 2], Tracker.find(1).project_ids.sort
Chris@0 114 end
Chris@0 115
Chris@909 116 def test_update_without_projects
Chris@909 117 put :update, :id => 1, :tracker => { :name => 'Renamed',
Chris@0 118 :project_ids => [''] }
Chris@0 119 assert_redirected_to :action => 'index'
Chris@0 120 assert Tracker.find(1).project_ids.empty?
Chris@0 121 end
Chris@909 122
Chris@0 123 def test_move_lower
Chris@0 124 tracker = Tracker.find_by_position(1)
Chris@909 125 put :update, :id => 1, :tracker => { :move_to => 'lower' }
Chris@0 126 assert_equal 2, tracker.reload.position
Chris@0 127 end
Chris@909 128
Chris@0 129 def test_destroy
Chris@0 130 tracker = Tracker.create!(:name => 'Destroyable')
Chris@0 131 assert_difference 'Tracker.count', -1 do
Chris@909 132 delete :destroy, :id => tracker.id
Chris@0 133 end
Chris@0 134 assert_redirected_to :action => 'index'
Chris@0 135 assert_nil flash[:error]
Chris@0 136 end
Chris@909 137
Chris@0 138 def test_destroy_tracker_in_use
Chris@0 139 assert_no_difference 'Tracker.count' do
Chris@909 140 delete :destroy, :id => 1
Chris@0 141 end
Chris@0 142 assert_redirected_to :action => 'index'
Chris@0 143 assert_not_nil flash[:error]
Chris@0 144 end
Chris@0 145 end