@@ -1,110 +1,120 | |||
|
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 | |
|
20 | 20 | class EnumerationsControllerTest < ActionController::TestCase |
|
21 | 21 | fixtures :enumerations, :issues, :users |
|
22 | 22 | |
|
23 | 23 | def setup |
|
24 | 24 | @request.session[:user_id] = 1 # admin |
|
25 | 25 | end |
|
26 | 26 | |
|
27 | 27 | def test_index |
|
28 | 28 | get :index |
|
29 | 29 | assert_response :success |
|
30 | 30 | assert_template 'index' |
|
31 | 31 | end |
|
32 | 32 | |
|
33 | 33 | def test_new |
|
34 | 34 | get :new, :type => 'IssuePriority' |
|
35 | 35 | assert_response :success |
|
36 | 36 | assert_template 'new' |
|
37 | 37 | assert_kind_of IssuePriority, assigns(:enumeration) |
|
38 | 38 | assert_tag 'input', :attributes => {:name => 'enumeration[type]', :value => 'IssuePriority'} |
|
39 | 39 | assert_tag 'input', :attributes => {:name => 'enumeration[name]'} |
|
40 | 40 | end |
|
41 | 41 | |
|
42 | def test_new_with_invalid_type_should_respond_with_404 | |
|
43 | get :new, :type => 'UnknownType' | |
|
44 | assert_response 404 | |
|
45 | end | |
|
46 | ||
|
42 | 47 | def test_create |
|
43 | 48 | assert_difference 'IssuePriority.count' do |
|
44 | 49 | post :create, :enumeration => {:type => 'IssuePriority', :name => 'Lowest'} |
|
45 | 50 | end |
|
46 | 51 | assert_redirected_to '/enumerations?type=IssuePriority' |
|
47 | 52 | e = IssuePriority.first(:order => 'id DESC') |
|
48 | 53 | assert_equal 'Lowest', e.name |
|
49 | 54 | end |
|
50 | 55 | |
|
51 | 56 | def test_create_with_failure |
|
52 | 57 | assert_no_difference 'IssuePriority.count' do |
|
53 | 58 | post :create, :enumeration => {:type => 'IssuePriority', :name => ''} |
|
54 | 59 | end |
|
55 | 60 | assert_response :success |
|
56 | 61 | assert_template 'new' |
|
57 | 62 | end |
|
58 | 63 | |
|
59 | 64 | def test_edit |
|
60 | 65 | get :edit, :id => 6 |
|
61 | 66 | assert_response :success |
|
62 | 67 | assert_template 'edit' |
|
63 | 68 | assert_tag 'input', :attributes => {:name => 'enumeration[name]', :value => 'High'} |
|
64 | 69 | end |
|
65 | 70 | |
|
71 | def test_edit_invalid_should_respond_with_404 | |
|
72 | get :edit, :id => 999 | |
|
73 | assert_response 404 | |
|
74 | end | |
|
75 | ||
|
66 | 76 | def test_update |
|
67 | 77 | assert_no_difference 'IssuePriority.count' do |
|
68 | 78 | put :update, :id => 6, :enumeration => {:type => 'IssuePriority', :name => 'New name'} |
|
69 | 79 | end |
|
70 | 80 | assert_redirected_to '/enumerations?type=IssuePriority' |
|
71 | 81 | e = IssuePriority.find(6) |
|
72 | 82 | assert_equal 'New name', e.name |
|
73 | 83 | end |
|
74 | 84 | |
|
75 | 85 | def test_update_with_failure |
|
76 | 86 | assert_no_difference 'IssuePriority.count' do |
|
77 | 87 | put :update, :id => 6, :enumeration => {:type => 'IssuePriority', :name => ''} |
|
78 | 88 | end |
|
79 | 89 | assert_response :success |
|
80 | 90 | assert_template 'edit' |
|
81 | 91 | end |
|
82 | 92 | |
|
83 | 93 | def test_destroy_enumeration_not_in_use |
|
84 | 94 | assert_difference 'IssuePriority.count', -1 do |
|
85 | 95 | delete :destroy, :id => 7 |
|
86 | 96 | end |
|
87 | 97 | assert_redirected_to :controller => 'enumerations', :action => 'index' |
|
88 | 98 | assert_nil Enumeration.find_by_id(7) |
|
89 | 99 | end |
|
90 | 100 | |
|
91 | 101 | def test_destroy_enumeration_in_use |
|
92 | 102 | assert_no_difference 'IssuePriority.count' do |
|
93 | 103 | delete :destroy, :id => 4 |
|
94 | 104 | end |
|
95 | 105 | assert_response :success |
|
96 | 106 | assert_template 'destroy' |
|
97 | 107 | assert_not_nil Enumeration.find_by_id(4) |
|
98 | 108 | end |
|
99 | 109 | |
|
100 | 110 | def test_destroy_enumeration_in_use_with_reassignment |
|
101 | 111 | issue = Issue.find(:first, :conditions => {:priority_id => 4}) |
|
102 | 112 | assert_difference 'IssuePriority.count', -1 do |
|
103 | 113 | delete :destroy, :id => 4, :reassign_to_id => 6 |
|
104 | 114 | end |
|
105 | 115 | assert_redirected_to :controller => 'enumerations', :action => 'index' |
|
106 | 116 | assert_nil Enumeration.find_by_id(4) |
|
107 | 117 | # check that the issue was reassign |
|
108 | 118 | assert_equal 6, issue.reload.priority_id |
|
109 | 119 | end |
|
110 | 120 | end |
@@ -1,178 +1,183 | |||
|
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 | |
|
20 | 20 | class RolesControllerTest < ActionController::TestCase |
|
21 | 21 | fixtures :roles, :users, :members, :member_roles, :workflows, :trackers |
|
22 | 22 | |
|
23 | 23 | def setup |
|
24 | 24 | User.current = nil |
|
25 | 25 | @request.session[:user_id] = 1 # admin |
|
26 | 26 | end |
|
27 | 27 | |
|
28 | 28 | def test_index |
|
29 | 29 | get :index |
|
30 | 30 | assert_response :success |
|
31 | 31 | assert_template 'index' |
|
32 | 32 | |
|
33 | 33 | assert_not_nil assigns(:roles) |
|
34 | 34 | assert_equal Role.find(:all, :order => 'builtin, position'), assigns(:roles) |
|
35 | 35 | |
|
36 | 36 | assert_tag :tag => 'a', :attributes => { :href => '/roles/1/edit' }, |
|
37 | 37 | :content => 'Manager' |
|
38 | 38 | end |
|
39 | 39 | |
|
40 | 40 | def test_new |
|
41 | 41 | get :new |
|
42 | 42 | assert_response :success |
|
43 | 43 | assert_template 'new' |
|
44 | 44 | end |
|
45 | 45 | |
|
46 | 46 | def test_create_with_validaton_failure |
|
47 | 47 | post :create, :role => {:name => '', |
|
48 | 48 | :permissions => ['add_issues', 'edit_issues', 'log_time', ''], |
|
49 | 49 | :assignable => '0'} |
|
50 | 50 | |
|
51 | 51 | assert_response :success |
|
52 | 52 | assert_template 'new' |
|
53 | 53 | assert_tag :tag => 'div', :attributes => { :id => 'errorExplanation' } |
|
54 | 54 | end |
|
55 | 55 | |
|
56 | 56 | def test_create_without_workflow_copy |
|
57 | 57 | post :create, :role => {:name => 'RoleWithoutWorkflowCopy', |
|
58 | 58 | :permissions => ['add_issues', 'edit_issues', 'log_time', ''], |
|
59 | 59 | :assignable => '0'} |
|
60 | 60 | |
|
61 | 61 | assert_redirected_to '/roles' |
|
62 | 62 | role = Role.find_by_name('RoleWithoutWorkflowCopy') |
|
63 | 63 | assert_not_nil role |
|
64 | 64 | assert_equal [:add_issues, :edit_issues, :log_time], role.permissions |
|
65 | 65 | assert !role.assignable? |
|
66 | 66 | end |
|
67 | 67 | |
|
68 | 68 | def test_create_with_workflow_copy |
|
69 | 69 | post :create, :role => {:name => 'RoleWithWorkflowCopy', |
|
70 | 70 | :permissions => ['add_issues', 'edit_issues', 'log_time', ''], |
|
71 | 71 | :assignable => '0'}, |
|
72 | 72 | :copy_workflow_from => '1' |
|
73 | 73 | |
|
74 | 74 | assert_redirected_to '/roles' |
|
75 | 75 | role = Role.find_by_name('RoleWithWorkflowCopy') |
|
76 | 76 | assert_not_nil role |
|
77 | 77 | assert_equal Role.find(1).workflows.size, role.workflows.size |
|
78 | 78 | end |
|
79 | 79 | |
|
80 | 80 | def test_edit |
|
81 | 81 | get :edit, :id => 1 |
|
82 | 82 | assert_response :success |
|
83 | 83 | assert_template 'edit' |
|
84 | 84 | assert_equal Role.find(1), assigns(:role) |
|
85 | 85 | end |
|
86 | 86 | |
|
87 | def test_edit_invalid_should_respond_with_404 | |
|
88 | get :edit, :id => 999 | |
|
89 | assert_response 404 | |
|
90 | end | |
|
91 | ||
|
87 | 92 | def test_update |
|
88 | 93 | put :update, :id => 1, |
|
89 | 94 | :role => {:name => 'Manager', |
|
90 | 95 | :permissions => ['edit_project', ''], |
|
91 | 96 | :assignable => '0'} |
|
92 | 97 | |
|
93 | 98 | assert_redirected_to '/roles' |
|
94 | 99 | role = Role.find(1) |
|
95 | 100 | assert_equal [:edit_project], role.permissions |
|
96 | 101 | end |
|
97 | 102 | |
|
98 | 103 | def test_update_with_failure |
|
99 | 104 | put :update, :id => 1, :role => {:name => ''} |
|
100 | 105 | assert_response :success |
|
101 | 106 | assert_template 'edit' |
|
102 | 107 | end |
|
103 | 108 | |
|
104 | 109 | def test_destroy |
|
105 | 110 | r = Role.create!(:name => 'ToBeDestroyed', :permissions => [:view_wiki_pages]) |
|
106 | 111 | |
|
107 | 112 | delete :destroy, :id => r |
|
108 | 113 | assert_redirected_to '/roles' |
|
109 | 114 | assert_nil Role.find_by_id(r.id) |
|
110 | 115 | end |
|
111 | 116 | |
|
112 | 117 | def test_destroy_role_in_use |
|
113 | 118 | delete :destroy, :id => 1 |
|
114 | 119 | assert_redirected_to '/roles' |
|
115 | 120 | assert_equal 'This role is in use and cannot be deleted.', flash[:error] |
|
116 | 121 | assert_not_nil Role.find_by_id(1) |
|
117 | 122 | end |
|
118 | 123 | |
|
119 | 124 | def test_get_permissions |
|
120 | 125 | get :permissions |
|
121 | 126 | assert_response :success |
|
122 | 127 | assert_template 'permissions' |
|
123 | 128 | |
|
124 | 129 | assert_not_nil assigns(:roles) |
|
125 | 130 | assert_equal Role.find(:all, :order => 'builtin, position'), assigns(:roles) |
|
126 | 131 | |
|
127 | 132 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
128 | 133 | :name => 'permissions[3][]', |
|
129 | 134 | :value => 'add_issues', |
|
130 | 135 | :checked => 'checked' } |
|
131 | 136 | |
|
132 | 137 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
133 | 138 | :name => 'permissions[3][]', |
|
134 | 139 | :value => 'delete_issues', |
|
135 | 140 | :checked => nil } |
|
136 | 141 | end |
|
137 | 142 | |
|
138 | 143 | def test_post_permissions |
|
139 | 144 | post :permissions, :permissions => { '0' => '', '1' => ['edit_issues'], '3' => ['add_issues', 'delete_issues']} |
|
140 | 145 | assert_redirected_to '/roles' |
|
141 | 146 | |
|
142 | 147 | assert_equal [:edit_issues], Role.find(1).permissions |
|
143 | 148 | assert_equal [:add_issues, :delete_issues], Role.find(3).permissions |
|
144 | 149 | assert Role.find(2).permissions.empty? |
|
145 | 150 | end |
|
146 | 151 | |
|
147 | 152 | def test_clear_all_permissions |
|
148 | 153 | post :permissions, :permissions => { '0' => '' } |
|
149 | 154 | assert_redirected_to '/roles' |
|
150 | 155 | assert Role.find(1).permissions.empty? |
|
151 | 156 | end |
|
152 | 157 | |
|
153 | 158 | def test_move_highest |
|
154 | 159 | put :update, :id => 3, :role => {:move_to => 'highest'} |
|
155 | 160 | assert_redirected_to '/roles' |
|
156 | 161 | assert_equal 1, Role.find(3).position |
|
157 | 162 | end |
|
158 | 163 | |
|
159 | 164 | def test_move_higher |
|
160 | 165 | position = Role.find(3).position |
|
161 | 166 | put :update, :id => 3, :role => {:move_to => 'higher'} |
|
162 | 167 | assert_redirected_to '/roles' |
|
163 | 168 | assert_equal position - 1, Role.find(3).position |
|
164 | 169 | end |
|
165 | 170 | |
|
166 | 171 | def test_move_lower |
|
167 | 172 | position = Role.find(2).position |
|
168 | 173 | put :update, :id => 2, :role => {:move_to => 'lower'} |
|
169 | 174 | assert_redirected_to '/roles' |
|
170 | 175 | assert_equal position + 1, Role.find(2).position |
|
171 | 176 | end |
|
172 | 177 | |
|
173 | 178 | def test_move_lowest |
|
174 | 179 | put :update, :id => 2, :role => {:move_to => 'lowest'} |
|
175 | 180 | assert_redirected_to '/roles' |
|
176 | 181 | assert_equal Role.count, Role.find(2).position |
|
177 | 182 | end |
|
178 | 183 | end |
General Comments 0
You need to be logged in to leave comments.
Login now