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