@@ -1,145 +1,145 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2013 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2013 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 |
|
19 | |||
20 | class IssueCategoriesControllerTest < ActionController::TestCase |
|
20 | class IssueCategoriesControllerTest < ActionController::TestCase | |
21 | fixtures :projects, :users, :members, :member_roles, :roles, :enabled_modules, :issue_categories, |
|
21 | fixtures :projects, :users, :members, :member_roles, :roles, :enabled_modules, :issue_categories, | |
22 | :issues |
|
22 | :issues | |
23 |
|
23 | |||
24 | def setup |
|
24 | def setup | |
25 | User.current = nil |
|
25 | User.current = nil | |
26 | @request.session[:user_id] = 2 |
|
26 | @request.session[:user_id] = 2 | |
27 | end |
|
27 | end | |
28 |
|
28 | |||
29 | def test_new |
|
29 | def test_new | |
30 | @request.session[:user_id] = 2 # manager |
|
30 | @request.session[:user_id] = 2 # manager | |
31 | get :new, :project_id => '1' |
|
31 | get :new, :project_id => '1' | |
32 | assert_response :success |
|
32 | assert_response :success | |
33 | assert_template 'new' |
|
33 | assert_template 'new' | |
34 | assert_select 'input[name=?]', 'issue_category[name]' |
|
34 | assert_select 'input[name=?]', 'issue_category[name]' | |
35 | end |
|
35 | end | |
36 |
|
36 | |||
37 | def test_new_from_issue_form |
|
37 | def test_new_from_issue_form | |
38 | @request.session[:user_id] = 2 # manager |
|
38 | @request.session[:user_id] = 2 # manager | |
39 | xhr :get, :new, :project_id => '1' |
|
39 | xhr :get, :new, :project_id => '1' | |
40 |
|
40 | |||
41 | assert_response :success |
|
41 | assert_response :success | |
42 | assert_template 'new' |
|
42 | assert_template 'new' | |
43 | assert_equal 'text/javascript', response.content_type |
|
43 | assert_equal 'text/javascript', response.content_type | |
44 | end |
|
44 | end | |
45 |
|
45 | |||
46 | def test_create |
|
46 | def test_create | |
47 | @request.session[:user_id] = 2 # manager |
|
47 | @request.session[:user_id] = 2 # manager | |
48 | assert_difference 'IssueCategory.count' do |
|
48 | assert_difference 'IssueCategory.count' do | |
49 | post :create, :project_id => '1', :issue_category => {:name => 'New category'} |
|
49 | post :create, :project_id => '1', :issue_category => {:name => 'New category'} | |
50 | end |
|
50 | end | |
51 | assert_redirected_to '/projects/ecookbook/settings/categories' |
|
51 | assert_redirected_to '/projects/ecookbook/settings/categories' | |
52 | category = IssueCategory.find_by_name('New category') |
|
52 | category = IssueCategory.find_by_name('New category') | |
53 | assert_not_nil category |
|
53 | assert_not_nil category | |
54 | assert_equal 1, category.project_id |
|
54 | assert_equal 1, category.project_id | |
55 | end |
|
55 | end | |
56 |
|
56 | |||
57 | def test_create_failure |
|
57 | def test_create_failure | |
58 | @request.session[:user_id] = 2 |
|
58 | @request.session[:user_id] = 2 | |
59 | post :create, :project_id => '1', :issue_category => {:name => ''} |
|
59 | post :create, :project_id => '1', :issue_category => {:name => ''} | |
60 | assert_response :success |
|
60 | assert_response :success | |
61 | assert_template 'new' |
|
61 | assert_template 'new' | |
62 | end |
|
62 | end | |
63 |
|
63 | |||
64 | def test_create_from_issue_form |
|
64 | def test_create_from_issue_form | |
65 | @request.session[:user_id] = 2 # manager |
|
65 | @request.session[:user_id] = 2 # manager | |
66 | assert_difference 'IssueCategory.count' do |
|
66 | assert_difference 'IssueCategory.count' do | |
67 | xhr :post, :create, :project_id => '1', :issue_category => {:name => 'New category'} |
|
67 | xhr :post, :create, :project_id => '1', :issue_category => {:name => 'New category'} | |
68 | end |
|
68 | end | |
69 |
category = IssueCategory. |
|
69 | category = IssueCategory.order('id DESC').first | |
70 | assert_equal 'New category', category.name |
|
70 | assert_equal 'New category', category.name | |
71 |
|
71 | |||
72 | assert_response :success |
|
72 | assert_response :success | |
73 | assert_template 'create' |
|
73 | assert_template 'create' | |
74 | assert_equal 'text/javascript', response.content_type |
|
74 | assert_equal 'text/javascript', response.content_type | |
75 | end |
|
75 | end | |
76 |
|
76 | |||
77 | def test_create_from_issue_form_with_failure |
|
77 | def test_create_from_issue_form_with_failure | |
78 | @request.session[:user_id] = 2 # manager |
|
78 | @request.session[:user_id] = 2 # manager | |
79 | assert_no_difference 'IssueCategory.count' do |
|
79 | assert_no_difference 'IssueCategory.count' do | |
80 | xhr :post, :create, :project_id => '1', :issue_category => {:name => ''} |
|
80 | xhr :post, :create, :project_id => '1', :issue_category => {:name => ''} | |
81 | end |
|
81 | end | |
82 |
|
82 | |||
83 | assert_response :success |
|
83 | assert_response :success | |
84 | assert_template 'new' |
|
84 | assert_template 'new' | |
85 | assert_equal 'text/javascript', response.content_type |
|
85 | assert_equal 'text/javascript', response.content_type | |
86 | end |
|
86 | end | |
87 |
|
87 | |||
88 | def test_edit |
|
88 | def test_edit | |
89 | @request.session[:user_id] = 2 |
|
89 | @request.session[:user_id] = 2 | |
90 | get :edit, :id => 2 |
|
90 | get :edit, :id => 2 | |
91 | assert_response :success |
|
91 | assert_response :success | |
92 | assert_template 'edit' |
|
92 | assert_template 'edit' | |
93 | assert_select 'input[name=?][value=?]', 'issue_category[name]', 'Recipes' |
|
93 | assert_select 'input[name=?][value=?]', 'issue_category[name]', 'Recipes' | |
94 | end |
|
94 | end | |
95 |
|
95 | |||
96 | def test_update |
|
96 | def test_update | |
97 | assert_no_difference 'IssueCategory.count' do |
|
97 | assert_no_difference 'IssueCategory.count' do | |
98 | put :update, :id => 2, :issue_category => { :name => 'Testing' } |
|
98 | put :update, :id => 2, :issue_category => { :name => 'Testing' } | |
99 | end |
|
99 | end | |
100 | assert_redirected_to '/projects/ecookbook/settings/categories' |
|
100 | assert_redirected_to '/projects/ecookbook/settings/categories' | |
101 | assert_equal 'Testing', IssueCategory.find(2).name |
|
101 | assert_equal 'Testing', IssueCategory.find(2).name | |
102 | end |
|
102 | end | |
103 |
|
103 | |||
104 | def test_update_failure |
|
104 | def test_update_failure | |
105 | put :update, :id => 2, :issue_category => { :name => '' } |
|
105 | put :update, :id => 2, :issue_category => { :name => '' } | |
106 | assert_response :success |
|
106 | assert_response :success | |
107 | assert_template 'edit' |
|
107 | assert_template 'edit' | |
108 | end |
|
108 | end | |
109 |
|
109 | |||
110 | def test_update_not_found |
|
110 | def test_update_not_found | |
111 | put :update, :id => 97, :issue_category => { :name => 'Testing' } |
|
111 | put :update, :id => 97, :issue_category => { :name => 'Testing' } | |
112 | assert_response 404 |
|
112 | assert_response 404 | |
113 | end |
|
113 | end | |
114 |
|
114 | |||
115 | def test_destroy_category_not_in_use |
|
115 | def test_destroy_category_not_in_use | |
116 | delete :destroy, :id => 2 |
|
116 | delete :destroy, :id => 2 | |
117 | assert_redirected_to '/projects/ecookbook/settings/categories' |
|
117 | assert_redirected_to '/projects/ecookbook/settings/categories' | |
118 | assert_nil IssueCategory.find_by_id(2) |
|
118 | assert_nil IssueCategory.find_by_id(2) | |
119 | end |
|
119 | end | |
120 |
|
120 | |||
121 | def test_destroy_category_in_use |
|
121 | def test_destroy_category_in_use | |
122 | delete :destroy, :id => 1 |
|
122 | delete :destroy, :id => 1 | |
123 | assert_response :success |
|
123 | assert_response :success | |
124 | assert_template 'destroy' |
|
124 | assert_template 'destroy' | |
125 | assert_not_nil IssueCategory.find_by_id(1) |
|
125 | assert_not_nil IssueCategory.find_by_id(1) | |
126 | end |
|
126 | end | |
127 |
|
127 | |||
128 | def test_destroy_category_in_use_with_reassignment |
|
128 | def test_destroy_category_in_use_with_reassignment | |
129 | issue = Issue.where(:category_id => 1).first |
|
129 | issue = Issue.where(:category_id => 1).first | |
130 | delete :destroy, :id => 1, :todo => 'reassign', :reassign_to_id => 2 |
|
130 | delete :destroy, :id => 1, :todo => 'reassign', :reassign_to_id => 2 | |
131 | assert_redirected_to '/projects/ecookbook/settings/categories' |
|
131 | assert_redirected_to '/projects/ecookbook/settings/categories' | |
132 | assert_nil IssueCategory.find_by_id(1) |
|
132 | assert_nil IssueCategory.find_by_id(1) | |
133 | # check that the issue was reassign |
|
133 | # check that the issue was reassign | |
134 | assert_equal 2, issue.reload.category_id |
|
134 | assert_equal 2, issue.reload.category_id | |
135 | end |
|
135 | end | |
136 |
|
136 | |||
137 | def test_destroy_category_in_use_without_reassignment |
|
137 | def test_destroy_category_in_use_without_reassignment | |
138 | issue = Issue.where(:category_id => 1).first |
|
138 | issue = Issue.where(:category_id => 1).first | |
139 | delete :destroy, :id => 1, :todo => 'nullify' |
|
139 | delete :destroy, :id => 1, :todo => 'nullify' | |
140 | assert_redirected_to '/projects/ecookbook/settings/categories' |
|
140 | assert_redirected_to '/projects/ecookbook/settings/categories' | |
141 | assert_nil IssueCategory.find_by_id(1) |
|
141 | assert_nil IssueCategory.find_by_id(1) | |
142 | # check that the issue category was nullified |
|
142 | # check that the issue category was nullified | |
143 | assert_nil issue.reload.category_id |
|
143 | assert_nil issue.reload.category_id | |
144 | end |
|
144 | end | |
145 | end |
|
145 | end |
General Comments 0
You need to be logged in to leave comments.
Login now