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