annotate .svn/pristine/51/514f8aeb54e3381fa2badbe487c0d7fd6bad2fd0.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 IssueCategoriesControllerTest < ActionController::TestCase
Chris@1295 21 fixtures :projects, :users, :members, :member_roles, :roles, :enabled_modules, :issue_categories,
Chris@1295 22 :issues
Chris@1295 23
Chris@1295 24 def setup
Chris@1295 25 User.current = nil
Chris@1295 26 @request.session[:user_id] = 2
Chris@1295 27 end
Chris@1295 28
Chris@1295 29 def test_new
Chris@1295 30 @request.session[:user_id] = 2 # manager
Chris@1295 31 get :new, :project_id => '1'
Chris@1295 32 assert_response :success
Chris@1295 33 assert_template 'new'
Chris@1295 34 assert_select 'input[name=?]', 'issue_category[name]'
Chris@1295 35 end
Chris@1295 36
Chris@1295 37 def test_new_from_issue_form
Chris@1295 38 @request.session[:user_id] = 2 # manager
Chris@1295 39 xhr :get, :new, :project_id => '1'
Chris@1295 40
Chris@1295 41 assert_response :success
Chris@1295 42 assert_template 'new'
Chris@1295 43 assert_equal 'text/javascript', response.content_type
Chris@1295 44 end
Chris@1295 45
Chris@1295 46 def test_create
Chris@1295 47 @request.session[:user_id] = 2 # manager
Chris@1295 48 assert_difference 'IssueCategory.count' do
Chris@1295 49 post :create, :project_id => '1', :issue_category => {:name => 'New category'}
Chris@1295 50 end
Chris@1295 51 assert_redirected_to '/projects/ecookbook/settings/categories'
Chris@1295 52 category = IssueCategory.find_by_name('New category')
Chris@1295 53 assert_not_nil category
Chris@1295 54 assert_equal 1, category.project_id
Chris@1295 55 end
Chris@1295 56
Chris@1295 57 def test_create_failure
Chris@1295 58 @request.session[:user_id] = 2
Chris@1295 59 post :create, :project_id => '1', :issue_category => {:name => ''}
Chris@1295 60 assert_response :success
Chris@1295 61 assert_template 'new'
Chris@1295 62 end
Chris@1295 63
Chris@1295 64 def test_create_from_issue_form
Chris@1295 65 @request.session[:user_id] = 2 # manager
Chris@1295 66 assert_difference 'IssueCategory.count' do
Chris@1295 67 xhr :post, :create, :project_id => '1', :issue_category => {:name => 'New category'}
Chris@1295 68 end
Chris@1295 69 category = IssueCategory.first(:order => 'id DESC')
Chris@1295 70 assert_equal 'New category', category.name
Chris@1295 71
Chris@1295 72 assert_response :success
Chris@1295 73 assert_template 'create'
Chris@1295 74 assert_equal 'text/javascript', response.content_type
Chris@1295 75 end
Chris@1295 76
Chris@1295 77 def test_create_from_issue_form_with_failure
Chris@1295 78 @request.session[:user_id] = 2 # manager
Chris@1295 79 assert_no_difference 'IssueCategory.count' do
Chris@1295 80 xhr :post, :create, :project_id => '1', :issue_category => {:name => ''}
Chris@1295 81 end
Chris@1295 82
Chris@1295 83 assert_response :success
Chris@1295 84 assert_template 'new'
Chris@1295 85 assert_equal 'text/javascript', response.content_type
Chris@1295 86 end
Chris@1295 87
Chris@1295 88 def test_edit
Chris@1295 89 @request.session[:user_id] = 2
Chris@1295 90 get :edit, :id => 2
Chris@1295 91 assert_response :success
Chris@1295 92 assert_template 'edit'
Chris@1295 93 assert_select 'input[name=?][value=?]', 'issue_category[name]', 'Recipes'
Chris@1295 94 end
Chris@1295 95
Chris@1295 96 def test_update
Chris@1295 97 assert_no_difference 'IssueCategory.count' do
Chris@1295 98 put :update, :id => 2, :issue_category => { :name => 'Testing' }
Chris@1295 99 end
Chris@1295 100 assert_redirected_to '/projects/ecookbook/settings/categories'
Chris@1295 101 assert_equal 'Testing', IssueCategory.find(2).name
Chris@1295 102 end
Chris@1295 103
Chris@1295 104 def test_update_failure
Chris@1295 105 put :update, :id => 2, :issue_category => { :name => '' }
Chris@1295 106 assert_response :success
Chris@1295 107 assert_template 'edit'
Chris@1295 108 end
Chris@1295 109
Chris@1295 110 def test_update_not_found
Chris@1295 111 put :update, :id => 97, :issue_category => { :name => 'Testing' }
Chris@1295 112 assert_response 404
Chris@1295 113 end
Chris@1295 114
Chris@1295 115 def test_destroy_category_not_in_use
Chris@1295 116 delete :destroy, :id => 2
Chris@1295 117 assert_redirected_to '/projects/ecookbook/settings/categories'
Chris@1295 118 assert_nil IssueCategory.find_by_id(2)
Chris@1295 119 end
Chris@1295 120
Chris@1295 121 def test_destroy_category_in_use
Chris@1295 122 delete :destroy, :id => 1
Chris@1295 123 assert_response :success
Chris@1295 124 assert_template 'destroy'
Chris@1295 125 assert_not_nil IssueCategory.find_by_id(1)
Chris@1295 126 end
Chris@1295 127
Chris@1295 128 def test_destroy_category_in_use_with_reassignment
Chris@1295 129 issue = Issue.where(:category_id => 1).first
Chris@1295 130 delete :destroy, :id => 1, :todo => 'reassign', :reassign_to_id => 2
Chris@1295 131 assert_redirected_to '/projects/ecookbook/settings/categories'
Chris@1295 132 assert_nil IssueCategory.find_by_id(1)
Chris@1295 133 # check that the issue was reassign
Chris@1295 134 assert_equal 2, issue.reload.category_id
Chris@1295 135 end
Chris@1295 136
Chris@1295 137 def test_destroy_category_in_use_without_reassignment
Chris@1295 138 issue = Issue.where(:category_id => 1).first
Chris@1295 139 delete :destroy, :id => 1, :todo => 'nullify'
Chris@1295 140 assert_redirected_to '/projects/ecookbook/settings/categories'
Chris@1295 141 assert_nil IssueCategory.find_by_id(1)
Chris@1295 142 # check that the issue category was nullified
Chris@1295 143 assert_nil issue.reload.category_id
Chris@1295 144 end
Chris@1295 145 end