annotate .svn/pristine/76/7627b3e96063b3b2d9ab37b36a7671517dc19460.svn-base @ 1384:b51b5ae3734c luisf

Merge
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Fri, 20 Sep 2013 19:04:25 +0100
parents 038ba2d95de8
children
rev   line source
Chris@1296 1 # Redmine - project management software
Chris@1296 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
Chris@1296 3 #
Chris@1296 4 # This program is free software; you can redistribute it and/or
Chris@1296 5 # modify it under the terms of the GNU General Public License
Chris@1296 6 # as published by the Free Software Foundation; either version 2
Chris@1296 7 # of the License, or (at your option) any later version.
Chris@1296 8 #
Chris@1296 9 # This program is distributed in the hope that it will be useful,
Chris@1296 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1296 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1296 12 # GNU General Public License for more details.
Chris@1296 13 #
Chris@1296 14 # You should have received a copy of the GNU General Public License
Chris@1296 15 # along with this program; if not, write to the Free Software
Chris@1296 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1296 17
Chris@1296 18 require File.expand_path('../../test_helper', __FILE__)
Chris@1296 19 require 'issue_categories_controller'
Chris@1296 20
Chris@1296 21 # Re-raise errors caught by the controller.
Chris@1296 22 class IssueCategoriesController; def rescue_action(e) raise e end; end
Chris@1296 23
Chris@1296 24 class IssueCategoriesControllerTest < ActionController::TestCase
Chris@1296 25 fixtures :projects, :users, :members, :member_roles, :roles, :enabled_modules, :issue_categories,
Chris@1296 26 :issues
Chris@1296 27
Chris@1296 28 def setup
Chris@1296 29 @controller = IssueCategoriesController.new
Chris@1296 30 @request = ActionController::TestRequest.new
Chris@1296 31 @response = ActionController::TestResponse.new
Chris@1296 32 User.current = nil
Chris@1296 33 @request.session[:user_id] = 2
Chris@1296 34 end
Chris@1296 35
Chris@1296 36 def test_new
Chris@1296 37 @request.session[:user_id] = 2 # manager
Chris@1296 38 get :new, :project_id => '1'
Chris@1296 39 assert_response :success
Chris@1296 40 assert_template 'new'
Chris@1296 41 assert_select 'input[name=?]', 'issue_category[name]'
Chris@1296 42 end
Chris@1296 43
Chris@1296 44 def test_new_from_issue_form
Chris@1296 45 @request.session[:user_id] = 2 # manager
Chris@1296 46 xhr :get, :new, :project_id => '1'
Chris@1296 47
Chris@1296 48 assert_response :success
Chris@1296 49 assert_template 'new'
Chris@1296 50 assert_equal 'text/javascript', response.content_type
Chris@1296 51 end
Chris@1296 52
Chris@1296 53 def test_create
Chris@1296 54 @request.session[:user_id] = 2 # manager
Chris@1296 55 assert_difference 'IssueCategory.count' do
Chris@1296 56 post :create, :project_id => '1', :issue_category => {:name => 'New category'}
Chris@1296 57 end
Chris@1296 58 assert_redirected_to '/projects/ecookbook/settings/categories'
Chris@1296 59 category = IssueCategory.find_by_name('New category')
Chris@1296 60 assert_not_nil category
Chris@1296 61 assert_equal 1, category.project_id
Chris@1296 62 end
Chris@1296 63
Chris@1296 64 def test_create_failure
Chris@1296 65 @request.session[:user_id] = 2
Chris@1296 66 post :create, :project_id => '1', :issue_category => {:name => ''}
Chris@1296 67 assert_response :success
Chris@1296 68 assert_template 'new'
Chris@1296 69 end
Chris@1296 70
Chris@1296 71 def test_create_from_issue_form
Chris@1296 72 @request.session[:user_id] = 2 # manager
Chris@1296 73 assert_difference 'IssueCategory.count' do
Chris@1296 74 xhr :post, :create, :project_id => '1', :issue_category => {:name => 'New category'}
Chris@1296 75 end
Chris@1296 76 category = IssueCategory.first(:order => 'id DESC')
Chris@1296 77 assert_equal 'New category', category.name
Chris@1296 78
Chris@1296 79 assert_response :success
Chris@1296 80 assert_template 'create'
Chris@1296 81 assert_equal 'text/javascript', response.content_type
Chris@1296 82 end
Chris@1296 83
Chris@1296 84 def test_create_from_issue_form_with_failure
Chris@1296 85 @request.session[:user_id] = 2 # manager
Chris@1296 86 assert_no_difference 'IssueCategory.count' do
Chris@1296 87 xhr :post, :create, :project_id => '1', :issue_category => {:name => ''}
Chris@1296 88 end
Chris@1296 89
Chris@1296 90 assert_response :success
Chris@1296 91 assert_template 'new'
Chris@1296 92 assert_equal 'text/javascript', response.content_type
Chris@1296 93 end
Chris@1296 94
Chris@1296 95 def test_edit
Chris@1296 96 @request.session[:user_id] = 2
Chris@1296 97 get :edit, :id => 2
Chris@1296 98 assert_response :success
Chris@1296 99 assert_template 'edit'
Chris@1296 100 assert_select 'input[name=?][value=?]', 'issue_category[name]', 'Recipes'
Chris@1296 101 end
Chris@1296 102
Chris@1296 103 def test_update
Chris@1296 104 assert_no_difference 'IssueCategory.count' do
Chris@1296 105 put :update, :id => 2, :issue_category => { :name => 'Testing' }
Chris@1296 106 end
Chris@1296 107 assert_redirected_to '/projects/ecookbook/settings/categories'
Chris@1296 108 assert_equal 'Testing', IssueCategory.find(2).name
Chris@1296 109 end
Chris@1296 110
Chris@1296 111 def test_update_failure
Chris@1296 112 put :update, :id => 2, :issue_category => { :name => '' }
Chris@1296 113 assert_response :success
Chris@1296 114 assert_template 'edit'
Chris@1296 115 end
Chris@1296 116
Chris@1296 117 def test_update_not_found
Chris@1296 118 put :update, :id => 97, :issue_category => { :name => 'Testing' }
Chris@1296 119 assert_response 404
Chris@1296 120 end
Chris@1296 121
Chris@1296 122 def test_destroy_category_not_in_use
Chris@1296 123 delete :destroy, :id => 2
Chris@1296 124 assert_redirected_to '/projects/ecookbook/settings/categories'
Chris@1296 125 assert_nil IssueCategory.find_by_id(2)
Chris@1296 126 end
Chris@1296 127
Chris@1296 128 def test_destroy_category_in_use
Chris@1296 129 delete :destroy, :id => 1
Chris@1296 130 assert_response :success
Chris@1296 131 assert_template 'destroy'
Chris@1296 132 assert_not_nil IssueCategory.find_by_id(1)
Chris@1296 133 end
Chris@1296 134
Chris@1296 135 def test_destroy_category_in_use_with_reassignment
Chris@1296 136 issue = Issue.find(:first, :conditions => {:category_id => 1})
Chris@1296 137 delete :destroy, :id => 1, :todo => 'reassign', :reassign_to_id => 2
Chris@1296 138 assert_redirected_to '/projects/ecookbook/settings/categories'
Chris@1296 139 assert_nil IssueCategory.find_by_id(1)
Chris@1296 140 # check that the issue was reassign
Chris@1296 141 assert_equal 2, issue.reload.category_id
Chris@1296 142 end
Chris@1296 143
Chris@1296 144 def test_destroy_category_in_use_without_reassignment
Chris@1296 145 issue = Issue.find(:first, :conditions => {:category_id => 1})
Chris@1296 146 delete :destroy, :id => 1, :todo => 'nullify'
Chris@1296 147 assert_redirected_to '/projects/ecookbook/settings/categories'
Chris@1296 148 assert_nil IssueCategory.find_by_id(1)
Chris@1296 149 # check that the issue category was nullified
Chris@1296 150 assert_nil issue.reload.category_id
Chris@1296 151 end
Chris@1296 152 end