To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / test / functional / .svn / text-base / issue_categories_controller_test.rb.svn-base @ 441:cbce1fd3b1b7
History | View | Annotate | Download (3.42 KB)
| 1 |
# Redmine - project management software |
|---|---|
| 2 |
# Copyright (C) 2006-2009 Jean-Philippe Lang |
| 3 |
# |
| 4 |
# This program is free software; you can redistribute it and/or |
| 5 |
# modify it under the terms of the GNU General Public License |
| 6 |
# as published by the Free Software Foundation; either version 2 |
| 7 |
# of the License, or (at your option) any later version. |
| 8 |
# |
| 9 |
# This program is distributed in the hope that it will be useful, |
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
# GNU General Public License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU General Public License |
| 15 |
# along with this program; if not, write to the Free Software |
| 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 |
|
| 18 |
require File.expand_path('../../test_helper', __FILE__)
|
| 19 |
require 'issue_categories_controller' |
| 20 |
|
| 21 |
# Re-raise errors caught by the controller. |
| 22 |
class IssueCategoriesController; def rescue_action(e) raise e end; end |
| 23 |
|
| 24 |
class IssueCategoriesControllerTest < ActionController::TestCase |
| 25 |
fixtures :projects, :users, :members, :member_roles, :roles, :enabled_modules, :issue_categories |
| 26 |
|
| 27 |
def setup |
| 28 |
@controller = IssueCategoriesController.new |
| 29 |
@request = ActionController::TestRequest.new |
| 30 |
@response = ActionController::TestResponse.new |
| 31 |
User.current = nil |
| 32 |
@request.session[:user_id] = 2 |
| 33 |
end |
| 34 |
|
| 35 |
def test_get_new |
| 36 |
@request.session[:user_id] = 2 # manager |
| 37 |
get :new, :project_id => '1' |
| 38 |
assert_response :success |
| 39 |
assert_template 'new' |
| 40 |
end |
| 41 |
|
| 42 |
def test_post_new |
| 43 |
@request.session[:user_id] = 2 # manager |
| 44 |
assert_difference 'IssueCategory.count' do |
| 45 |
post :new, :project_id => '1', :category => {:name => 'New category'}
|
| 46 |
end |
| 47 |
assert_redirected_to '/projects/ecookbook/settings/categories' |
| 48 |
category = IssueCategory.find_by_name('New category')
|
| 49 |
assert_not_nil category |
| 50 |
assert_equal 1, category.project_id |
| 51 |
end |
| 52 |
|
| 53 |
def test_post_edit |
| 54 |
assert_no_difference 'IssueCategory.count' do |
| 55 |
post :edit, :id => 2, :category => { :name => 'Testing' }
|
| 56 |
end |
| 57 |
assert_redirected_to '/projects/ecookbook/settings/categories' |
| 58 |
assert_equal 'Testing', IssueCategory.find(2).name |
| 59 |
end |
| 60 |
|
| 61 |
def test_edit_not_found |
| 62 |
post :edit, :id => 97, :category => { :name => 'Testing' }
|
| 63 |
assert_response 404 |
| 64 |
end |
| 65 |
|
| 66 |
def test_destroy_category_not_in_use |
| 67 |
post :destroy, :id => 2 |
| 68 |
assert_redirected_to '/projects/ecookbook/settings/categories' |
| 69 |
assert_nil IssueCategory.find_by_id(2) |
| 70 |
end |
| 71 |
|
| 72 |
def test_destroy_category_in_use |
| 73 |
post :destroy, :id => 1 |
| 74 |
assert_response :success |
| 75 |
assert_template 'destroy' |
| 76 |
assert_not_nil IssueCategory.find_by_id(1) |
| 77 |
end |
| 78 |
|
| 79 |
def test_destroy_category_in_use_with_reassignment |
| 80 |
issue = Issue.find(:first, :conditions => {:category_id => 1})
|
| 81 |
post :destroy, :id => 1, :todo => 'reassign', :reassign_to_id => 2 |
| 82 |
assert_redirected_to '/projects/ecookbook/settings/categories' |
| 83 |
assert_nil IssueCategory.find_by_id(1) |
| 84 |
# check that the issue was reassign |
| 85 |
assert_equal 2, issue.reload.category_id |
| 86 |
end |
| 87 |
|
| 88 |
def test_destroy_category_in_use_without_reassignment |
| 89 |
issue = Issue.find(:first, :conditions => {:category_id => 1})
|
| 90 |
post :destroy, :id => 1, :todo => 'nullify' |
| 91 |
assert_redirected_to '/projects/ecookbook/settings/categories' |
| 92 |
assert_nil IssueCategory.find_by_id(1) |
| 93 |
# check that the issue category was nullified |
| 94 |
assert_nil issue.reload.category_id |
| 95 |
end |
| 96 |
end |