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