@@ -1,345 +1,344 | |||||
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 WorkflowsControllerTest < ActionController::TestCase |
|
20 | class WorkflowsControllerTest < ActionController::TestCase | |
21 | fixtures :roles, :trackers, :workflows, :users, :issue_statuses |
|
21 | fixtures :roles, :trackers, :workflows, :users, :issue_statuses | |
22 |
|
22 | |||
23 | def setup |
|
23 | def setup | |
24 | User.current = nil |
|
24 | User.current = nil | |
25 | @request.session[:user_id] = 1 # admin |
|
25 | @request.session[:user_id] = 1 # admin | |
26 | end |
|
26 | end | |
27 |
|
27 | |||
28 | def test_index |
|
28 | def test_index | |
29 | get :index |
|
29 | get :index | |
30 | assert_response :success |
|
30 | assert_response :success | |
31 | assert_template 'index' |
|
31 | assert_template 'index' | |
32 |
|
32 | |||
33 | count = WorkflowTransition.where(:role_id => 1, :tracker_id => 2).count |
|
33 | count = WorkflowTransition.where(:role_id => 1, :tracker_id => 2).count | |
34 | assert_tag :tag => 'a', :content => count.to_s, |
|
34 | assert_tag :tag => 'a', :content => count.to_s, | |
35 | :attributes => { :href => '/workflows/edit?role_id=1&tracker_id=2' } |
|
35 | :attributes => { :href => '/workflows/edit?role_id=1&tracker_id=2' } | |
36 | end |
|
36 | end | |
37 |
|
37 | |||
38 | def test_get_edit |
|
38 | def test_get_edit | |
39 | get :edit |
|
39 | get :edit | |
40 | assert_response :success |
|
40 | assert_response :success | |
41 | assert_template 'edit' |
|
41 | assert_template 'edit' | |
42 | assert_not_nil assigns(:roles) |
|
42 | assert_not_nil assigns(:roles) | |
43 | assert_not_nil assigns(:trackers) |
|
43 | assert_not_nil assigns(:trackers) | |
44 | end |
|
44 | end | |
45 |
|
45 | |||
46 | def test_get_edit_with_role_and_tracker |
|
46 | def test_get_edit_with_role_and_tracker | |
47 | WorkflowTransition.delete_all |
|
47 | WorkflowTransition.delete_all | |
48 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 2, :new_status_id => 3) |
|
48 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 2, :new_status_id => 3) | |
49 | WorkflowTransition.create!(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 5) |
|
49 | WorkflowTransition.create!(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 5) | |
50 |
|
50 | |||
51 | get :edit, :role_id => 2, :tracker_id => 1 |
|
51 | get :edit, :role_id => 2, :tracker_id => 1 | |
52 | assert_response :success |
|
52 | assert_response :success | |
53 | assert_template 'edit' |
|
53 | assert_template 'edit' | |
54 |
|
54 | |||
55 | # used status only |
|
55 | # used status only | |
56 | assert_not_nil assigns(:statuses) |
|
56 | assert_not_nil assigns(:statuses) | |
57 | assert_equal [2, 3, 5], assigns(:statuses).collect(&:id) |
|
57 | assert_equal [2, 3, 5], assigns(:statuses).collect(&:id) | |
58 |
|
58 | |||
59 | # allowed transitions |
|
59 | # allowed transitions | |
60 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
60 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
61 | :name => 'issue_status[3][5][]', |
|
61 | :name => 'issue_status[3][5][]', | |
62 | :value => 'always', |
|
62 | :value => 'always', | |
63 | :checked => 'checked' } |
|
63 | :checked => 'checked' } | |
64 | # not allowed |
|
64 | # not allowed | |
65 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
65 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
66 | :name => 'issue_status[3][2][]', |
|
66 | :name => 'issue_status[3][2][]', | |
67 | :value => 'always', |
|
67 | :value => 'always', | |
68 | :checked => nil } |
|
68 | :checked => nil } | |
69 | # unused |
|
69 | # unused | |
70 | assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
70 | assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
71 | :name => 'issue_status[1][1][]' } |
|
71 | :name => 'issue_status[1][1][]' } | |
72 | end |
|
72 | end | |
73 |
|
73 | |||
74 | def test_get_edit_with_role_and_tracker_and_all_statuses |
|
74 | def test_get_edit_with_role_and_tracker_and_all_statuses | |
75 | WorkflowTransition.delete_all |
|
75 | WorkflowTransition.delete_all | |
76 |
|
76 | |||
77 | get :edit, :role_id => 2, :tracker_id => 1, :used_statuses_only => '0' |
|
77 | get :edit, :role_id => 2, :tracker_id => 1, :used_statuses_only => '0' | |
78 | assert_response :success |
|
78 | assert_response :success | |
79 | assert_template 'edit' |
|
79 | assert_template 'edit' | |
80 |
|
80 | |||
81 | assert_not_nil assigns(:statuses) |
|
81 | assert_not_nil assigns(:statuses) | |
82 | assert_equal IssueStatus.count, assigns(:statuses).size |
|
82 | assert_equal IssueStatus.count, assigns(:statuses).size | |
83 |
|
83 | |||
84 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
84 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
85 | :name => 'issue_status[1][1][]', |
|
85 | :name => 'issue_status[1][1][]', | |
86 | :value => 'always', |
|
86 | :value => 'always', | |
87 | :checked => nil } |
|
87 | :checked => nil } | |
88 | end |
|
88 | end | |
89 |
|
89 | |||
90 | def test_post_edit |
|
90 | def test_post_edit | |
91 | post :edit, :role_id => 2, :tracker_id => 1, |
|
91 | post :edit, :role_id => 2, :tracker_id => 1, | |
92 | :issue_status => { |
|
92 | :issue_status => { | |
93 | '4' => {'5' => ['always']}, |
|
93 | '4' => {'5' => ['always']}, | |
94 | '3' => {'1' => ['always'], '2' => ['always']} |
|
94 | '3' => {'1' => ['always'], '2' => ['always']} | |
95 | } |
|
95 | } | |
96 | assert_redirected_to '/workflows/edit?role_id=2&tracker_id=1' |
|
96 | assert_redirected_to '/workflows/edit?role_id=2&tracker_id=1' | |
97 |
|
97 | |||
98 | assert_equal 3, WorkflowTransition.where(:tracker_id => 1, :role_id => 2).count |
|
98 | assert_equal 3, WorkflowTransition.where(:tracker_id => 1, :role_id => 2).count | |
99 | assert_not_nil WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2).first |
|
99 | assert_not_nil WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2).first | |
100 | assert_nil WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4).first |
|
100 | assert_nil WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4).first | |
101 | end |
|
101 | end | |
102 |
|
102 | |||
103 | def test_post_edit_with_additional_transitions |
|
103 | def test_post_edit_with_additional_transitions | |
104 | post :edit, :role_id => 2, :tracker_id => 1, |
|
104 | post :edit, :role_id => 2, :tracker_id => 1, | |
105 | :issue_status => { |
|
105 | :issue_status => { | |
106 | '4' => {'5' => ['always']}, |
|
106 | '4' => {'5' => ['always']}, | |
107 | '3' => {'1' => ['author'], '2' => ['assignee'], '4' => ['author', 'assignee']} |
|
107 | '3' => {'1' => ['author'], '2' => ['assignee'], '4' => ['author', 'assignee']} | |
108 | } |
|
108 | } | |
109 | assert_redirected_to '/workflows/edit?role_id=2&tracker_id=1' |
|
109 | assert_redirected_to '/workflows/edit?role_id=2&tracker_id=1' | |
110 |
|
110 | |||
111 | assert_equal 4, WorkflowTransition.where(:tracker_id => 1, :role_id => 2).count |
|
111 | assert_equal 4, WorkflowTransition.where(:tracker_id => 1, :role_id => 2).count | |
112 |
|
112 | |||
113 | w = WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 4, :new_status_id => 5).first |
|
113 | w = WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 4, :new_status_id => 5).first | |
114 | assert ! w.author |
|
114 | assert ! w.author | |
115 | assert ! w.assignee |
|
115 | assert ! w.assignee | |
116 | w = WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 1).first |
|
116 | w = WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 1).first | |
117 | assert w.author |
|
117 | assert w.author | |
118 | assert ! w.assignee |
|
118 | assert ! w.assignee | |
119 | w = WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2).first |
|
119 | w = WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2).first | |
120 | assert ! w.author |
|
120 | assert ! w.author | |
121 | assert w.assignee |
|
121 | assert w.assignee | |
122 | w = WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 4).first |
|
122 | w = WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 4).first | |
123 | assert w.author |
|
123 | assert w.author | |
124 | assert w.assignee |
|
124 | assert w.assignee | |
125 | end |
|
125 | end | |
126 |
|
126 | |||
127 | def test_clear_workflow |
|
127 | def test_clear_workflow | |
128 | assert WorkflowTransition.where(:role_id => 1, :tracker_id => 2).count > 0 |
|
128 | assert WorkflowTransition.where(:role_id => 1, :tracker_id => 2).count > 0 | |
129 |
|
129 | |||
130 | post :edit, :role_id => 1, :tracker_id => 2 |
|
130 | post :edit, :role_id => 1, :tracker_id => 2 | |
131 | assert_equal 0, WorkflowTransition.where(:role_id => 1, :tracker_id => 2).count |
|
131 | assert_equal 0, WorkflowTransition.where(:role_id => 1, :tracker_id => 2).count | |
132 | end |
|
132 | end | |
133 |
|
133 | |||
134 | def test_get_permissions |
|
134 | def test_get_permissions | |
135 | get :permissions |
|
135 | get :permissions | |
136 |
|
136 | |||
137 | assert_response :success |
|
137 | assert_response :success | |
138 | assert_template 'permissions' |
|
138 | assert_template 'permissions' | |
139 | assert_not_nil assigns(:roles) |
|
139 | assert_not_nil assigns(:roles) | |
140 | assert_not_nil assigns(:trackers) |
|
140 | assert_not_nil assigns(:trackers) | |
141 | end |
|
141 | end | |
142 |
|
142 | |||
143 | def test_get_permissions_with_role_and_tracker |
|
143 | def test_get_permissions_with_role_and_tracker | |
144 | WorkflowPermission.delete_all |
|
144 | WorkflowPermission.delete_all | |
145 | WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :field_name => 'assigned_to_id', :rule => 'required') |
|
145 | WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :field_name => 'assigned_to_id', :rule => 'required') | |
146 | WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :field_name => 'fixed_version_id', :rule => 'required') |
|
146 | WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :field_name => 'fixed_version_id', :rule => 'required') | |
147 | WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 3, :field_name => 'fixed_version_id', :rule => 'readonly') |
|
147 | WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 3, :field_name => 'fixed_version_id', :rule => 'readonly') | |
148 |
|
148 | |||
149 | get :permissions, :role_id => 1, :tracker_id => 2 |
|
149 | get :permissions, :role_id => 1, :tracker_id => 2 | |
150 | assert_response :success |
|
150 | assert_response :success | |
151 | assert_template 'permissions' |
|
151 | assert_template 'permissions' | |
152 |
|
152 | |||
153 | assert_select 'input[name=role_id][value=1]' |
|
153 | assert_select 'input[name=role_id][value=1]' | |
154 | assert_select 'input[name=tracker_id][value=2]' |
|
154 | assert_select 'input[name=tracker_id][value=2]' | |
155 |
|
155 | |||
156 | # Required field |
|
156 | # Required field | |
157 | assert_select 'select[name=?]', 'permissions[assigned_to_id][2]' do |
|
157 | assert_select 'select[name=?]', 'permissions[assigned_to_id][2]' do | |
158 | assert_select 'option[value=]' |
|
158 | assert_select 'option[value=]' | |
159 | assert_select 'option[value=][selected=selected]', 0 |
|
159 | assert_select 'option[value=][selected=selected]', 0 | |
160 | assert_select 'option[value=readonly]', :text => 'Read-only' |
|
160 | assert_select 'option[value=readonly]', :text => 'Read-only' | |
161 | assert_select 'option[value=readonly][selected=selected]', 0 |
|
161 | assert_select 'option[value=readonly][selected=selected]', 0 | |
162 | assert_select 'option[value=required]', :text => 'Required' |
|
162 | assert_select 'option[value=required]', :text => 'Required' | |
163 | assert_select 'option[value=required][selected=selected]' |
|
163 | assert_select 'option[value=required][selected=selected]' | |
164 | end |
|
164 | end | |
165 |
|
165 | |||
166 | # Read-only field |
|
166 | # Read-only field | |
167 | assert_select 'select[name=?]', 'permissions[fixed_version_id][3]' do |
|
167 | assert_select 'select[name=?]', 'permissions[fixed_version_id][3]' do | |
168 | assert_select 'option[value=]' |
|
168 | assert_select 'option[value=]' | |
169 | assert_select 'option[value=][selected=selected]', 0 |
|
169 | assert_select 'option[value=][selected=selected]', 0 | |
170 | assert_select 'option[value=readonly]', :text => 'Read-only' |
|
170 | assert_select 'option[value=readonly]', :text => 'Read-only' | |
171 | assert_select 'option[value=readonly][selected=selected]' |
|
171 | assert_select 'option[value=readonly][selected=selected]' | |
172 | assert_select 'option[value=required]', :text => 'Required' |
|
172 | assert_select 'option[value=required]', :text => 'Required' | |
173 | assert_select 'option[value=required][selected=selected]', 0 |
|
173 | assert_select 'option[value=required][selected=selected]', 0 | |
174 | end |
|
174 | end | |
175 |
|
175 | |||
176 | # Other field |
|
176 | # Other field | |
177 | assert_select 'select[name=?]', 'permissions[due_date][3]' do |
|
177 | assert_select 'select[name=?]', 'permissions[due_date][3]' do | |
178 | assert_select 'option[value=]' |
|
178 | assert_select 'option[value=]' | |
179 | assert_select 'option[value=][selected=selected]', 0 |
|
179 | assert_select 'option[value=][selected=selected]', 0 | |
180 | assert_select 'option[value=readonly]', :text => 'Read-only' |
|
180 | assert_select 'option[value=readonly]', :text => 'Read-only' | |
181 | assert_select 'option[value=readonly][selected=selected]', 0 |
|
181 | assert_select 'option[value=readonly][selected=selected]', 0 | |
182 | assert_select 'option[value=required]', :text => 'Required' |
|
182 | assert_select 'option[value=required]', :text => 'Required' | |
183 | assert_select 'option[value=required][selected=selected]', 0 |
|
183 | assert_select 'option[value=required][selected=selected]', 0 | |
184 | end |
|
184 | end | |
185 | end |
|
185 | end | |
186 |
|
186 | |||
187 | def test_get_permissions_with_required_custom_field_should_not_show_required_option |
|
187 | def test_get_permissions_with_required_custom_field_should_not_show_required_option | |
188 | cf = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :tracker_ids => [1], :is_required => true) |
|
188 | cf = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :tracker_ids => [1], :is_required => true) | |
189 |
|
189 | |||
190 | get :permissions, :role_id => 1, :tracker_id => 1 |
|
190 | get :permissions, :role_id => 1, :tracker_id => 1 | |
191 | assert_response :success |
|
191 | assert_response :success | |
192 | assert_template 'permissions' |
|
192 | assert_template 'permissions' | |
193 |
|
193 | |||
194 | # Custom field that is always required |
|
194 | # Custom field that is always required | |
195 | # The default option is "(Required)" |
|
195 | # The default option is "(Required)" | |
196 | assert_select 'select[name=?]', "permissions[#{cf.id}][3]" do |
|
196 | assert_select 'select[name=?]', "permissions[#{cf.id}][3]" do | |
197 | assert_select 'option[value=]' |
|
197 | assert_select 'option[value=]' | |
198 | assert_select 'option[value=readonly]', :text => 'Read-only' |
|
198 | assert_select 'option[value=readonly]', :text => 'Read-only' | |
199 | assert_select 'option[value=required]', 0 |
|
199 | assert_select 'option[value=required]', 0 | |
200 | end |
|
200 | end | |
201 | end |
|
201 | end | |
202 |
|
202 | |||
203 | def test_get_permissions_should_disable_hidden_custom_fields |
|
203 | def test_get_permissions_should_disable_hidden_custom_fields | |
204 | cf1 = IssueCustomField.generate!(:tracker_ids => [1], :visible => true) |
|
204 | cf1 = IssueCustomField.generate!(:tracker_ids => [1], :visible => true) | |
205 | cf2 = IssueCustomField.generate!(:tracker_ids => [1], :visible => false, :role_ids => [1]) |
|
205 | cf2 = IssueCustomField.generate!(:tracker_ids => [1], :visible => false, :role_ids => [1]) | |
206 | cf3 = IssueCustomField.generate!(:tracker_ids => [1], :visible => false, :role_ids => [1, 2]) |
|
206 | cf3 = IssueCustomField.generate!(:tracker_ids => [1], :visible => false, :role_ids => [1, 2]) | |
207 |
|
207 | |||
208 | get :permissions, :role_id => 2, :tracker_id => 1 |
|
208 | get :permissions, :role_id => 2, :tracker_id => 1 | |
209 | assert_response :success |
|
209 | assert_response :success | |
210 | assert_template 'permissions' |
|
210 | assert_template 'permissions' | |
211 |
|
211 | |||
212 | assert_select 'select[name=?]:not(.disabled)', "permissions[#{cf1.id}][1]" |
|
212 | assert_select 'select[name=?]:not(.disabled)', "permissions[#{cf1.id}][1]" | |
213 | assert_select 'select[name=?]:not(.disabled)', "permissions[#{cf3.id}][1]" |
|
213 | assert_select 'select[name=?]:not(.disabled)', "permissions[#{cf3.id}][1]" | |
214 |
|
214 | |||
215 | assert_select 'select[name=?][disabled=disabled]', "permissions[#{cf2.id}][1]" do |
|
215 | assert_select 'select[name=?][disabled=disabled]', "permissions[#{cf2.id}][1]" do | |
216 | assert_select 'option[value=][selected=selected]', :text => 'Hidden' |
|
216 | assert_select 'option[value=][selected=selected]', :text => 'Hidden' | |
217 | end |
|
217 | end | |
218 | end |
|
218 | end | |
219 |
|
219 | |||
220 | def test_get_permissions_with_role_and_tracker_and_all_statuses |
|
220 | def test_get_permissions_with_role_and_tracker_and_all_statuses | |
221 | WorkflowTransition.delete_all |
|
221 | WorkflowTransition.delete_all | |
222 |
|
222 | |||
223 | get :permissions, :role_id => 1, :tracker_id => 2, :used_statuses_only => '0' |
|
223 | get :permissions, :role_id => 1, :tracker_id => 2, :used_statuses_only => '0' | |
224 | assert_response :success |
|
224 | assert_response :success | |
225 | assert_equal IssueStatus.sorted.all, assigns(:statuses) |
|
225 | assert_equal IssueStatus.sorted.all, assigns(:statuses) | |
226 | end |
|
226 | end | |
227 |
|
227 | |||
228 | def test_post_permissions |
|
228 | def test_post_permissions | |
229 | WorkflowPermission.delete_all |
|
229 | WorkflowPermission.delete_all | |
230 |
|
230 | |||
231 | post :permissions, :role_id => 1, :tracker_id => 2, :permissions => { |
|
231 | post :permissions, :role_id => 1, :tracker_id => 2, :permissions => { | |
232 | 'assigned_to_id' => {'1' => '', '2' => 'readonly', '3' => ''}, |
|
232 | 'assigned_to_id' => {'1' => '', '2' => 'readonly', '3' => ''}, | |
233 | 'fixed_version_id' => {'1' => 'required', '2' => 'readonly', '3' => ''}, |
|
233 | 'fixed_version_id' => {'1' => 'required', '2' => 'readonly', '3' => ''}, | |
234 | 'due_date' => {'1' => '', '2' => '', '3' => ''}, |
|
234 | 'due_date' => {'1' => '', '2' => '', '3' => ''}, | |
235 | } |
|
235 | } | |
236 | assert_redirected_to '/workflows/permissions?role_id=1&tracker_id=2' |
|
236 | assert_redirected_to '/workflows/permissions?role_id=1&tracker_id=2' | |
237 |
|
237 | |||
238 | workflows = WorkflowPermission.all |
|
238 | workflows = WorkflowPermission.all | |
239 | assert_equal 3, workflows.size |
|
239 | assert_equal 3, workflows.size | |
240 | workflows.each do |workflow| |
|
240 | workflows.each do |workflow| | |
241 | assert_equal 1, workflow.role_id |
|
241 | assert_equal 1, workflow.role_id | |
242 | assert_equal 2, workflow.tracker_id |
|
242 | assert_equal 2, workflow.tracker_id | |
243 | end |
|
243 | end | |
244 | assert workflows.detect {|wf| wf.old_status_id == 2 && wf.field_name == 'assigned_to_id' && wf.rule == 'readonly'} |
|
244 | assert workflows.detect {|wf| wf.old_status_id == 2 && wf.field_name == 'assigned_to_id' && wf.rule == 'readonly'} | |
245 | assert workflows.detect {|wf| wf.old_status_id == 1 && wf.field_name == 'fixed_version_id' && wf.rule == 'required'} |
|
245 | assert workflows.detect {|wf| wf.old_status_id == 1 && wf.field_name == 'fixed_version_id' && wf.rule == 'required'} | |
246 | assert workflows.detect {|wf| wf.old_status_id == 2 && wf.field_name == 'fixed_version_id' && wf.rule == 'readonly'} |
|
246 | assert workflows.detect {|wf| wf.old_status_id == 2 && wf.field_name == 'fixed_version_id' && wf.rule == 'readonly'} | |
247 | end |
|
247 | end | |
248 |
|
248 | |||
249 | def test_post_permissions_should_clear_permissions |
|
249 | def test_post_permissions_should_clear_permissions | |
250 | WorkflowPermission.delete_all |
|
250 | WorkflowPermission.delete_all | |
251 | WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :field_name => 'assigned_to_id', :rule => 'required') |
|
251 | WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :field_name => 'assigned_to_id', :rule => 'required') | |
252 | WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :field_name => 'fixed_version_id', :rule => 'required') |
|
252 | WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :field_name => 'fixed_version_id', :rule => 'required') | |
253 | wf1 = WorkflowPermission.create!(:role_id => 1, :tracker_id => 3, :old_status_id => 2, :field_name => 'fixed_version_id', :rule => 'required') |
|
253 | wf1 = WorkflowPermission.create!(:role_id => 1, :tracker_id => 3, :old_status_id => 2, :field_name => 'fixed_version_id', :rule => 'required') | |
254 | wf2 = WorkflowPermission.create!(:role_id => 2, :tracker_id => 2, :old_status_id => 3, :field_name => 'fixed_version_id', :rule => 'readonly') |
|
254 | wf2 = WorkflowPermission.create!(:role_id => 2, :tracker_id => 2, :old_status_id => 3, :field_name => 'fixed_version_id', :rule => 'readonly') | |
255 |
|
255 | |||
256 | post :permissions, :role_id => 1, :tracker_id => 2 |
|
256 | post :permissions, :role_id => 1, :tracker_id => 2 | |
257 | assert_redirected_to '/workflows/permissions?role_id=1&tracker_id=2' |
|
257 | assert_redirected_to '/workflows/permissions?role_id=1&tracker_id=2' | |
258 |
|
258 | |||
259 | workflows = WorkflowPermission.all |
|
259 | workflows = WorkflowPermission.all | |
260 | assert_equal 2, workflows.size |
|
260 | assert_equal 2, workflows.size | |
261 | assert wf1.reload |
|
261 | assert wf1.reload | |
262 | assert wf2.reload |
|
262 | assert wf2.reload | |
263 | end |
|
263 | end | |
264 |
|
264 | |||
265 | def test_get_copy |
|
265 | def test_get_copy | |
266 | get :copy |
|
266 | get :copy | |
267 | assert_response :success |
|
267 | assert_response :success | |
268 | assert_template 'copy' |
|
268 | assert_template 'copy' | |
269 | assert_select 'select[name=source_tracker_id]' do |
|
269 | assert_select 'select[name=source_tracker_id]' do | |
270 | assert_select 'option[value=1]', :text => 'Bug' |
|
270 | assert_select 'option[value=1]', :text => 'Bug' | |
271 | end |
|
271 | end | |
272 | assert_select 'select[name=source_role_id]' do |
|
272 | assert_select 'select[name=source_role_id]' do | |
273 | assert_select 'option[value=2]', :text => 'Developer' |
|
273 | assert_select 'option[value=2]', :text => 'Developer' | |
274 | end |
|
274 | end | |
275 | assert_select 'select[name=?]', 'target_tracker_ids[]' do |
|
275 | assert_select 'select[name=?]', 'target_tracker_ids[]' do | |
276 | assert_select 'option[value=3]', :text => 'Support request' |
|
276 | assert_select 'option[value=3]', :text => 'Support request' | |
277 | end |
|
277 | end | |
278 | assert_select 'select[name=?]', 'target_role_ids[]' do |
|
278 | assert_select 'select[name=?]', 'target_role_ids[]' do | |
279 | assert_select 'option[value=1]', :text => 'Manager' |
|
279 | assert_select 'option[value=1]', :text => 'Manager' | |
280 | end |
|
280 | end | |
281 | end |
|
281 | end | |
282 |
|
282 | |||
283 | def test_post_copy_one_to_one |
|
283 | def test_post_copy_one_to_one | |
284 | source_transitions = status_transitions(:tracker_id => 1, :role_id => 2) |
|
284 | source_transitions = status_transitions(:tracker_id => 1, :role_id => 2) | |
285 |
|
285 | |||
286 | post :copy, :source_tracker_id => '1', :source_role_id => '2', |
|
286 | post :copy, :source_tracker_id => '1', :source_role_id => '2', | |
287 | :target_tracker_ids => ['3'], :target_role_ids => ['1'] |
|
287 | :target_tracker_ids => ['3'], :target_role_ids => ['1'] | |
288 | assert_response 302 |
|
288 | assert_response 302 | |
289 | assert_equal source_transitions, status_transitions(:tracker_id => 3, :role_id => 1) |
|
289 | assert_equal source_transitions, status_transitions(:tracker_id => 3, :role_id => 1) | |
290 | end |
|
290 | end | |
291 |
|
291 | |||
292 | def test_post_copy_one_to_many |
|
292 | def test_post_copy_one_to_many | |
293 | source_transitions = status_transitions(:tracker_id => 1, :role_id => 2) |
|
293 | source_transitions = status_transitions(:tracker_id => 1, :role_id => 2) | |
294 |
|
294 | |||
295 | post :copy, :source_tracker_id => '1', :source_role_id => '2', |
|
295 | post :copy, :source_tracker_id => '1', :source_role_id => '2', | |
296 | :target_tracker_ids => ['2', '3'], :target_role_ids => ['1', '3'] |
|
296 | :target_tracker_ids => ['2', '3'], :target_role_ids => ['1', '3'] | |
297 | assert_response 302 |
|
297 | assert_response 302 | |
298 | assert_equal source_transitions, status_transitions(:tracker_id => 2, :role_id => 1) |
|
298 | assert_equal source_transitions, status_transitions(:tracker_id => 2, :role_id => 1) | |
299 | assert_equal source_transitions, status_transitions(:tracker_id => 3, :role_id => 1) |
|
299 | assert_equal source_transitions, status_transitions(:tracker_id => 3, :role_id => 1) | |
300 | assert_equal source_transitions, status_transitions(:tracker_id => 2, :role_id => 3) |
|
300 | assert_equal source_transitions, status_transitions(:tracker_id => 2, :role_id => 3) | |
301 | assert_equal source_transitions, status_transitions(:tracker_id => 3, :role_id => 3) |
|
301 | assert_equal source_transitions, status_transitions(:tracker_id => 3, :role_id => 3) | |
302 | end |
|
302 | end | |
303 |
|
303 | |||
304 | def test_post_copy_many_to_many |
|
304 | def test_post_copy_many_to_many | |
305 | source_t2 = status_transitions(:tracker_id => 2, :role_id => 2) |
|
305 | source_t2 = status_transitions(:tracker_id => 2, :role_id => 2) | |
306 | source_t3 = status_transitions(:tracker_id => 3, :role_id => 2) |
|
306 | source_t3 = status_transitions(:tracker_id => 3, :role_id => 2) | |
307 |
|
307 | |||
308 | post :copy, :source_tracker_id => 'any', :source_role_id => '2', |
|
308 | post :copy, :source_tracker_id => 'any', :source_role_id => '2', | |
309 | :target_tracker_ids => ['2', '3'], :target_role_ids => ['1', '3'] |
|
309 | :target_tracker_ids => ['2', '3'], :target_role_ids => ['1', '3'] | |
310 | assert_response 302 |
|
310 | assert_response 302 | |
311 | assert_equal source_t2, status_transitions(:tracker_id => 2, :role_id => 1) |
|
311 | assert_equal source_t2, status_transitions(:tracker_id => 2, :role_id => 1) | |
312 | assert_equal source_t3, status_transitions(:tracker_id => 3, :role_id => 1) |
|
312 | assert_equal source_t3, status_transitions(:tracker_id => 3, :role_id => 1) | |
313 | assert_equal source_t2, status_transitions(:tracker_id => 2, :role_id => 3) |
|
313 | assert_equal source_t2, status_transitions(:tracker_id => 2, :role_id => 3) | |
314 | assert_equal source_t3, status_transitions(:tracker_id => 3, :role_id => 3) |
|
314 | assert_equal source_t3, status_transitions(:tracker_id => 3, :role_id => 3) | |
315 | end |
|
315 | end | |
316 |
|
316 | |||
317 | def test_post_copy_with_incomplete_source_specification_should_fail |
|
317 | def test_post_copy_with_incomplete_source_specification_should_fail | |
318 | assert_no_difference 'WorkflowRule.count' do |
|
318 | assert_no_difference 'WorkflowRule.count' do | |
319 | post :copy, |
|
319 | post :copy, | |
320 | :source_tracker_id => '', :source_role_id => '2', |
|
320 | :source_tracker_id => '', :source_role_id => '2', | |
321 | :target_tracker_ids => ['2', '3'], :target_role_ids => ['1', '3'] |
|
321 | :target_tracker_ids => ['2', '3'], :target_role_ids => ['1', '3'] | |
322 | assert_response 200 |
|
322 | assert_response 200 | |
323 | assert_select 'div.flash.error', :text => 'Please select a source tracker or role' |
|
323 | assert_select 'div.flash.error', :text => 'Please select a source tracker or role' | |
324 | end |
|
324 | end | |
325 | end |
|
325 | end | |
326 |
|
326 | |||
327 | def test_post_copy_with_incomplete_target_specification_should_fail |
|
327 | def test_post_copy_with_incomplete_target_specification_should_fail | |
328 | assert_no_difference 'WorkflowRule.count' do |
|
328 | assert_no_difference 'WorkflowRule.count' do | |
329 | post :copy, |
|
329 | post :copy, | |
330 | :source_tracker_id => '1', :source_role_id => '2', |
|
330 | :source_tracker_id => '1', :source_role_id => '2', | |
331 | :target_tracker_ids => ['2', '3'] |
|
331 | :target_tracker_ids => ['2', '3'] | |
332 | assert_response 200 |
|
332 | assert_response 200 | |
333 | assert_select 'div.flash.error', :text => 'Please select target tracker(s) and role(s)' |
|
333 | assert_select 'div.flash.error', :text => 'Please select target tracker(s) and role(s)' | |
334 | end |
|
334 | end | |
335 | end |
|
335 | end | |
336 |
|
336 | |||
337 | # Returns an array of status transitions that can be compared |
|
337 | # Returns an array of status transitions that can be compared | |
338 | def status_transitions(conditions) |
|
338 | def status_transitions(conditions) | |
339 | WorkflowTransition. |
|
339 | WorkflowTransition. | |
340 | where(conditions). |
|
340 | where(conditions). | |
341 | order('tracker_id, role_id, old_status_id, new_status_id'). |
|
341 | order('tracker_id, role_id, old_status_id, new_status_id'). | |
342 | all. |
|
|||
343 | collect {|w| [w.old_status, w.new_status_id]} |
|
342 | collect {|w| [w.old_status, w.new_status_id]} | |
344 | end |
|
343 | end | |
345 | end |
|
344 | end |
General Comments 0
You need to be logged in to leave comments.
Login now