annotate .svn/pristine/dd/dd3fc580b46d142a6812688ff323c2b6855b5a85.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents 622f24f53b42
children
rev   line source
Chris@1295 1 # Redmine - project management software
Chris@1295 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
Chris@1295 3 #
Chris@1295 4 # This program is free software; you can redistribute it and/or
Chris@1295 5 # modify it under the terms of the GNU General Public License
Chris@1295 6 # as published by the Free Software Foundation; either version 2
Chris@1295 7 # of the License, or (at your option) any later version.
Chris@1295 8 #
Chris@1295 9 # This program is distributed in the hope that it will be useful,
Chris@1295 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1295 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1295 12 # GNU General Public License for more details.
Chris@1295 13 #
Chris@1295 14 # You should have received a copy of the GNU General Public License
Chris@1295 15 # along with this program; if not, write to the Free Software
Chris@1295 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1295 17
Chris@1295 18 require File.expand_path('../../test_helper', __FILE__)
Chris@1295 19
Chris@1295 20 class EnumerationsControllerTest < ActionController::TestCase
Chris@1295 21 fixtures :enumerations, :issues, :users
Chris@1295 22
Chris@1295 23 def setup
Chris@1295 24 @request.session[:user_id] = 1 # admin
Chris@1295 25 end
Chris@1295 26
Chris@1295 27 def test_index
Chris@1295 28 get :index
Chris@1295 29 assert_response :success
Chris@1295 30 assert_template 'index'
Chris@1295 31 end
Chris@1295 32
Chris@1295 33 def test_index_should_require_admin
Chris@1295 34 @request.session[:user_id] = nil
Chris@1295 35 get :index
Chris@1295 36 assert_response 302
Chris@1295 37 end
Chris@1295 38
Chris@1295 39 def test_new
Chris@1295 40 get :new, :type => 'IssuePriority'
Chris@1295 41 assert_response :success
Chris@1295 42 assert_template 'new'
Chris@1295 43 assert_kind_of IssuePriority, assigns(:enumeration)
Chris@1295 44 assert_tag 'input', :attributes => {:name => 'enumeration[type]', :value => 'IssuePriority'}
Chris@1295 45 assert_tag 'input', :attributes => {:name => 'enumeration[name]'}
Chris@1295 46 end
Chris@1295 47
Chris@1295 48 def test_new_with_invalid_type_should_respond_with_404
Chris@1295 49 get :new, :type => 'UnknownType'
Chris@1295 50 assert_response 404
Chris@1295 51 end
Chris@1295 52
Chris@1295 53 def test_create
Chris@1295 54 assert_difference 'IssuePriority.count' do
Chris@1295 55 post :create, :enumeration => {:type => 'IssuePriority', :name => 'Lowest'}
Chris@1295 56 end
Chris@1295 57 assert_redirected_to '/enumerations'
Chris@1295 58 e = IssuePriority.find_by_name('Lowest')
Chris@1295 59 assert_not_nil e
Chris@1295 60 end
Chris@1295 61
Chris@1295 62 def test_create_with_failure
Chris@1295 63 assert_no_difference 'IssuePriority.count' do
Chris@1295 64 post :create, :enumeration => {:type => 'IssuePriority', :name => ''}
Chris@1295 65 end
Chris@1295 66 assert_response :success
Chris@1295 67 assert_template 'new'
Chris@1295 68 end
Chris@1295 69
Chris@1295 70 def test_edit
Chris@1295 71 get :edit, :id => 6
Chris@1295 72 assert_response :success
Chris@1295 73 assert_template 'edit'
Chris@1295 74 assert_tag 'input', :attributes => {:name => 'enumeration[name]', :value => 'High'}
Chris@1295 75 end
Chris@1295 76
Chris@1295 77 def test_edit_invalid_should_respond_with_404
Chris@1295 78 get :edit, :id => 999
Chris@1295 79 assert_response 404
Chris@1295 80 end
Chris@1295 81
Chris@1295 82 def test_update
Chris@1295 83 assert_no_difference 'IssuePriority.count' do
Chris@1295 84 put :update, :id => 6, :enumeration => {:type => 'IssuePriority', :name => 'New name'}
Chris@1295 85 end
Chris@1295 86 assert_redirected_to '/enumerations'
Chris@1295 87 e = IssuePriority.find(6)
Chris@1295 88 assert_equal 'New name', e.name
Chris@1295 89 end
Chris@1295 90
Chris@1295 91 def test_update_with_failure
Chris@1295 92 assert_no_difference 'IssuePriority.count' do
Chris@1295 93 put :update, :id => 6, :enumeration => {:type => 'IssuePriority', :name => ''}
Chris@1295 94 end
Chris@1295 95 assert_response :success
Chris@1295 96 assert_template 'edit'
Chris@1295 97 end
Chris@1295 98
Chris@1295 99 def test_destroy_enumeration_not_in_use
Chris@1295 100 assert_difference 'IssuePriority.count', -1 do
Chris@1295 101 delete :destroy, :id => 7
Chris@1295 102 end
Chris@1295 103 assert_redirected_to :controller => 'enumerations', :action => 'index'
Chris@1295 104 assert_nil Enumeration.find_by_id(7)
Chris@1295 105 end
Chris@1295 106
Chris@1295 107 def test_destroy_enumeration_in_use
Chris@1295 108 assert_no_difference 'IssuePriority.count' do
Chris@1295 109 delete :destroy, :id => 4
Chris@1295 110 end
Chris@1295 111 assert_response :success
Chris@1295 112 assert_template 'destroy'
Chris@1295 113 assert_not_nil Enumeration.find_by_id(4)
Chris@1295 114 assert_select 'select[name=reassign_to_id]' do
Chris@1295 115 assert_select 'option[value=6]', :text => 'High'
Chris@1295 116 end
Chris@1295 117 end
Chris@1295 118
Chris@1295 119 def test_destroy_enumeration_in_use_with_reassignment
Chris@1295 120 issue = Issue.where(:priority_id => 4).first
Chris@1295 121 assert_difference 'IssuePriority.count', -1 do
Chris@1295 122 delete :destroy, :id => 4, :reassign_to_id => 6
Chris@1295 123 end
Chris@1295 124 assert_redirected_to :controller => 'enumerations', :action => 'index'
Chris@1295 125 assert_nil Enumeration.find_by_id(4)
Chris@1295 126 # check that the issue was reassign
Chris@1295 127 assert_equal 6, issue.reload.priority_id
Chris@1295 128 end
Chris@1295 129 end