annotate .svn/pristine/1c/1c4e880a5c075a9e228087794274845b57f2a7a4.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

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