@@ -1,123 +1,123 | |||
|
1 | 1 | <%= render :partial => 'action_menu' %> |
|
2 | 2 | |
|
3 | 3 | <%= title l(:label_workflow) %> |
|
4 | 4 | |
|
5 | 5 | <div class="tabs"> |
|
6 | 6 | <ul> |
|
7 | 7 | <li><%= link_to l(:label_status_transitions), workflows_edit_path(:role_id => @roles, :tracker_id => @trackers) %></li> |
|
8 | 8 | <li><%= link_to l(:label_fields_permissions), workflows_permissions_path(:role_id => @roles, :tracker_id => @trackers), :class => 'selected' %></li> |
|
9 | 9 | </ul> |
|
10 | 10 | </div> |
|
11 | 11 | |
|
12 | 12 | <p><%=l(:text_workflow_edit)%>:</p> |
|
13 | 13 | |
|
14 | 14 | <%= form_tag({}, :method => 'get') do %> |
|
15 | 15 | <p> |
|
16 | 16 | <label><%=l(:label_role)%>: |
|
17 | 17 | <%= options_for_workflow_select 'role_id[]', Role.sorted.select(&:consider_workflow?), @roles, :id => 'role_id', :class => 'expandable' %> |
|
18 | 18 | </label> |
|
19 | 19 | <a href="#" data-expands="#role_id"><%= image_tag 'bullet_toggle_plus.png' %></a> |
|
20 | 20 | |
|
21 | 21 | <label><%=l(:label_tracker)%>: |
|
22 | 22 | <%= options_for_workflow_select 'tracker_id[]', Tracker.sorted, @trackers, :id => 'tracker_id', :class => 'expandable' %> |
|
23 | 23 | </label> |
|
24 | 24 | <a href="#" data-expands="#tracker_id"><%= image_tag 'bullet_toggle_plus.png' %></a> |
|
25 | 25 | |
|
26 | 26 | <%= submit_tag l(:button_edit), :name => nil %> |
|
27 | 27 | |
|
28 | 28 | <%= hidden_field_tag 'used_statuses_only', '0', :id => nil %> |
|
29 | 29 | <label><%= check_box_tag 'used_statuses_only', '1', @used_statuses_only %> <%= l(:label_display_used_statuses_only) %></label> |
|
30 | 30 | </p> |
|
31 | 31 | <% end %> |
|
32 | 32 | |
|
33 | 33 | <% if @trackers && @roles && @statuses.any? %> |
|
34 | 34 | <%= form_tag({}, :id => 'workflow_form' ) do %> |
|
35 | 35 | <%= @trackers.map {|tracker| hidden_field_tag 'tracker_id[]', tracker.id, :id => nil}.join.html_safe %> |
|
36 | 36 | <%= @roles.map {|role| hidden_field_tag 'role_id[]', role.id, :id => nil}.join.html_safe %> |
|
37 | 37 | <%= hidden_field_tag 'used_statuses_only', params[:used_statuses_only], :id => nil %> |
|
38 | 38 | <div class="autoscroll"> |
|
39 | 39 | <table class="list workflows fields_permissions"> |
|
40 | 40 | <thead> |
|
41 | 41 | <tr> |
|
42 | 42 | <th> |
|
43 | 43 | </th> |
|
44 | 44 | <th colspan="<%= @statuses.length %>"><%=l(:label_issue_status)%></th> |
|
45 | 45 | </tr> |
|
46 | 46 | <tr> |
|
47 | 47 | <td></td> |
|
48 | 48 | <% for status in @statuses %> |
|
49 | 49 | <td style="width:<%= 75 / @statuses.size %>%;"> |
|
50 | 50 | <%= status.name %> |
|
51 | 51 | </td> |
|
52 | 52 | <% end %> |
|
53 | 53 | </tr> |
|
54 | 54 | </thead> |
|
55 | 55 | <tbody> |
|
56 | 56 | <tr class="group open"> |
|
57 | 57 | <td colspan="<%= @statuses.size + 1 %>"> |
|
58 | 58 | <span class="expander" onclick="toggleRowGroup(this);"> </span> |
|
59 | 59 | <%= l(:field_core_fields) %> |
|
60 | 60 | </td> |
|
61 | 61 | </tr> |
|
62 | 62 | <% @fields.each do |field, name| %> |
|
63 | 63 | <tr class="<%= cycle("odd", "even") %>"> |
|
64 | 64 | <td class="name"> |
|
65 | 65 | <%= name %> <%= content_tag('span', '*', :class => 'required') if field_required?(field) %> |
|
66 | 66 | </td> |
|
67 | 67 | <% for status in @statuses -%> |
|
68 | 68 | <td class="<%= @permissions[status.id][field].try(:join, ' ') %>"> |
|
69 | 69 | <%= field_permission_tag(@permissions, status, field, @roles) %> |
|
70 | 70 | <% unless status == @statuses.last %><a href="#" class="repeat-value">»</a><% end %> |
|
71 | 71 | </td> |
|
72 | 72 | <% end -%> |
|
73 | 73 | </tr> |
|
74 | 74 | <% end %> |
|
75 | 75 | <% if @custom_fields.any? %> |
|
76 | 76 | <tr class="group open"> |
|
77 | 77 | <td colspan="<%= @statuses.size + 1 %>"> |
|
78 | 78 | <span class="expander" onclick="toggleRowGroup(this);"> </span> |
|
79 | 79 | <%= l(:label_custom_field_plural) %> |
|
80 | 80 | </td> |
|
81 | 81 | </tr> |
|
82 | 82 | <% @custom_fields.each do |field| %> |
|
83 | 83 | <tr class="<%= cycle("odd", "even") %>"> |
|
84 | 84 | <td class="name"> |
|
85 | 85 | <%= field.name %> <%= content_tag('span', '*', :class => 'required') if field_required?(field) %> |
|
86 | 86 | </td> |
|
87 | 87 | <% for status in @statuses -%> |
|
88 | <td class="<%= @permissions[status.id][field.id.to_s] %>"> | |
|
88 | <td class="<%= @permissions[status.id][field.id.to_s].try(:join, ' ') %>"> | |
|
89 | 89 | <%= field_permission_tag(@permissions, status, field, @roles) %> |
|
90 | 90 | <% unless status == @statuses.last %><a href="#" class="repeat-value">»</a><% end %> |
|
91 | 91 | </td> |
|
92 | 92 | <% end -%> |
|
93 | 93 | </tr> |
|
94 | 94 | <% end %> |
|
95 | 95 | <% end %> |
|
96 | 96 | </tbody> |
|
97 | 97 | </table> |
|
98 | 98 | </div> |
|
99 | 99 | <%= submit_tag l(:button_save) %> |
|
100 | 100 | <% end %> |
|
101 | 101 | <% end %> |
|
102 | 102 | |
|
103 | 103 | <%= javascript_tag do %> |
|
104 | 104 | $("a.repeat-value").click(function(e){ |
|
105 | 105 | e.preventDefault(); |
|
106 | 106 | var td = $(this).closest('td'); |
|
107 | 107 | var selected = td.find("select").find(":selected").val(); |
|
108 | 108 | td.nextAll('td').find("select").val(selected); |
|
109 | 109 | }); |
|
110 | 110 | |
|
111 | 111 | $("a[data-expands]").click(function(e){ |
|
112 | 112 | e.preventDefault(); |
|
113 | 113 | var target = $($(this).attr("data-expands")); |
|
114 | 114 | if (target.attr("multiple")) { |
|
115 | 115 | target.attr("multiple", false); |
|
116 | 116 | target.find("option[value=all]").show(); |
|
117 | 117 | } else { |
|
118 | 118 | target.attr("multiple", true); |
|
119 | 119 | target.find("option[value=all]").attr("selected", false).hide(); |
|
120 | 120 | } |
|
121 | 121 | }); |
|
122 | 122 | |
|
123 | 123 | <% end %> |
@@ -1,393 +1,396 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2016 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 WorkflowsControllerTest < ActionController::TestCase |
|
21 | 21 | fixtures :roles, :trackers, :workflows, :users, :issue_statuses |
|
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 | count = WorkflowTransition.where(:role_id => 1, :tracker_id => 2).count |
|
34 | 34 | assert_select 'a[href=?]', '/workflows/edit?role_id=1&tracker_id=2', :content => count.to_s |
|
35 | 35 | end |
|
36 | 36 | |
|
37 | 37 | def test_get_edit |
|
38 | 38 | get :edit |
|
39 | 39 | assert_response :success |
|
40 | 40 | assert_template 'edit' |
|
41 | 41 | end |
|
42 | 42 | |
|
43 | 43 | def test_get_edit_with_role_and_tracker |
|
44 | 44 | WorkflowTransition.delete_all |
|
45 | 45 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 2, :new_status_id => 3) |
|
46 | 46 | WorkflowTransition.create!(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 5) |
|
47 | 47 | |
|
48 | 48 | get :edit, :role_id => 2, :tracker_id => 1 |
|
49 | 49 | assert_response :success |
|
50 | 50 | assert_template 'edit' |
|
51 | 51 | |
|
52 | 52 | # used status only |
|
53 | 53 | assert_not_nil assigns(:statuses) |
|
54 | 54 | assert_equal [2, 3, 5], assigns(:statuses).collect(&:id) |
|
55 | 55 | |
|
56 | 56 | # allowed transitions |
|
57 | 57 | assert_select 'input[type=checkbox][name=?][value="1"][checked=checked]', 'transitions[3][5][always]' |
|
58 | 58 | # not allowed |
|
59 | 59 | assert_select 'input[type=checkbox][name=?][value="1"]:not([checked=checked])', 'transitions[3][2][always]' |
|
60 | 60 | # unused |
|
61 | 61 | assert_select 'input[type=checkbox][name=?]', 'transitions[1][1][always]', 0 |
|
62 | 62 | end |
|
63 | 63 | |
|
64 | 64 | def test_get_edit_should_include_allowed_statuses_for_new_issues |
|
65 | 65 | WorkflowTransition.delete_all |
|
66 | 66 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 0, :new_status_id => 1) |
|
67 | 67 | |
|
68 | 68 | get :edit, :role_id => 1, :tracker_id => 1 |
|
69 | 69 | assert_response :success |
|
70 | 70 | assert_select 'td', 'New issue' |
|
71 | 71 | assert_select 'input[type=checkbox][name=?][value="1"][checked=checked]', 'transitions[0][1][always]' |
|
72 | 72 | end |
|
73 | 73 | |
|
74 | 74 | def test_get_edit_with_all_roles_and_all_trackers |
|
75 | 75 | get :edit, :role_id => 'all', :tracker_id => 'all' |
|
76 | 76 | assert_response :success |
|
77 | 77 | assert_equal Role.sorted.to_a, assigns(:roles) |
|
78 | 78 | assert_equal Tracker.sorted.to_a, assigns(:trackers) |
|
79 | 79 | end |
|
80 | 80 | |
|
81 | 81 | def test_get_edit_with_role_and_tracker_and_all_statuses |
|
82 | 82 | WorkflowTransition.delete_all |
|
83 | 83 | |
|
84 | 84 | get :edit, :role_id => 2, :tracker_id => 1, :used_statuses_only => '0' |
|
85 | 85 | assert_response :success |
|
86 | 86 | assert_template 'edit' |
|
87 | 87 | |
|
88 | 88 | assert_not_nil assigns(:statuses) |
|
89 | 89 | assert_equal IssueStatus.count, assigns(:statuses).size |
|
90 | 90 | |
|
91 | 91 | assert_select 'input[type=checkbox][name=?]', 'transitions[1][1][always]' |
|
92 | 92 | end |
|
93 | 93 | |
|
94 | 94 | def test_post_edit |
|
95 | 95 | WorkflowTransition.delete_all |
|
96 | 96 | |
|
97 | 97 | post :edit, :role_id => 2, :tracker_id => 1, |
|
98 | 98 | :transitions => { |
|
99 | 99 | '4' => {'5' => {'always' => '1'}}, |
|
100 | 100 | '3' => {'1' => {'always' => '1'}, '2' => {'always' => '1'}} |
|
101 | 101 | } |
|
102 | 102 | assert_response 302 |
|
103 | 103 | |
|
104 | 104 | assert_equal 3, WorkflowTransition.where(:tracker_id => 1, :role_id => 2).count |
|
105 | 105 | assert_not_nil WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2).first |
|
106 | 106 | assert_nil WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4).first |
|
107 | 107 | end |
|
108 | 108 | |
|
109 | 109 | def test_post_edit_with_allowed_statuses_for_new_issues |
|
110 | 110 | WorkflowTransition.delete_all |
|
111 | 111 | |
|
112 | 112 | post :edit, :role_id => 2, :tracker_id => 1, |
|
113 | 113 | :transitions => { |
|
114 | 114 | '0' => {'1' => {'always' => '1'}, '2' => {'always' => '1'}} |
|
115 | 115 | } |
|
116 | 116 | assert_response 302 |
|
117 | 117 | |
|
118 | 118 | assert WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 0, :new_status_id => 1).any? |
|
119 | 119 | assert WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 0, :new_status_id => 2).any? |
|
120 | 120 | assert_equal 2, WorkflowTransition.where(:tracker_id => 1, :role_id => 2).count |
|
121 | 121 | end |
|
122 | 122 | |
|
123 | 123 | def test_post_edit_with_additional_transitions |
|
124 | 124 | WorkflowTransition.delete_all |
|
125 | 125 | |
|
126 | 126 | post :edit, :role_id => 2, :tracker_id => 1, |
|
127 | 127 | :transitions => { |
|
128 | 128 | '4' => {'5' => {'always' => '1', 'author' => '0', 'assignee' => '0'}}, |
|
129 | 129 | '3' => {'1' => {'always' => '0', 'author' => '1', 'assignee' => '0'}, |
|
130 | 130 | '2' => {'always' => '0', 'author' => '0', 'assignee' => '1'}, |
|
131 | 131 | '4' => {'always' => '0', 'author' => '1', 'assignee' => '1'}} |
|
132 | 132 | } |
|
133 | 133 | assert_response 302 |
|
134 | 134 | |
|
135 | 135 | assert_equal 4, WorkflowTransition.where(:tracker_id => 1, :role_id => 2).count |
|
136 | 136 | |
|
137 | 137 | w = WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 4, :new_status_id => 5).first |
|
138 | 138 | assert ! w.author |
|
139 | 139 | assert ! w.assignee |
|
140 | 140 | w = WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 1).first |
|
141 | 141 | assert w.author |
|
142 | 142 | assert ! w.assignee |
|
143 | 143 | w = WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2).first |
|
144 | 144 | assert ! w.author |
|
145 | 145 | assert w.assignee |
|
146 | 146 | w = WorkflowTransition.where(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 4).first |
|
147 | 147 | assert w.author |
|
148 | 148 | assert w.assignee |
|
149 | 149 | end |
|
150 | 150 | |
|
151 | 151 | def test_get_permissions |
|
152 | 152 | get :permissions |
|
153 | 153 | |
|
154 | 154 | assert_response :success |
|
155 | 155 | assert_template 'permissions' |
|
156 | 156 | end |
|
157 | 157 | |
|
158 | 158 | def test_get_permissions_with_role_and_tracker |
|
159 | 159 | WorkflowPermission.delete_all |
|
160 | 160 | WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :field_name => 'assigned_to_id', :rule => 'required') |
|
161 | 161 | WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :field_name => 'fixed_version_id', :rule => 'required') |
|
162 | 162 | WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 3, :field_name => 'fixed_version_id', :rule => 'readonly') |
|
163 | 163 | |
|
164 | 164 | get :permissions, :role_id => 1, :tracker_id => 2 |
|
165 | 165 | assert_response :success |
|
166 | 166 | assert_template 'permissions' |
|
167 | 167 | |
|
168 | 168 | assert_select 'input[name=?][value="1"]', 'role_id[]' |
|
169 | 169 | assert_select 'input[name=?][value="2"]', 'tracker_id[]' |
|
170 | 170 | |
|
171 | 171 | # Required field |
|
172 | 172 | assert_select 'select[name=?]', 'permissions[2][assigned_to_id]' do |
|
173 | 173 | assert_select 'option[value=""]' |
|
174 | 174 | assert_select 'option[value=""][selected=selected]', 0 |
|
175 | 175 | assert_select 'option[value=readonly]', :text => 'Read-only' |
|
176 | 176 | assert_select 'option[value=readonly][selected=selected]', 0 |
|
177 | 177 | assert_select 'option[value=required]', :text => 'Required' |
|
178 | 178 | assert_select 'option[value=required][selected=selected]' |
|
179 | 179 | end |
|
180 | 180 | |
|
181 | 181 | # Read-only field |
|
182 | 182 | assert_select 'select[name=?]', 'permissions[3][fixed_version_id]' do |
|
183 | 183 | assert_select 'option[value=""]' |
|
184 | 184 | assert_select 'option[value=""][selected=selected]', 0 |
|
185 | 185 | assert_select 'option[value=readonly]', :text => 'Read-only' |
|
186 | 186 | assert_select 'option[value=readonly][selected=selected]' |
|
187 | 187 | assert_select 'option[value=required]', :text => 'Required' |
|
188 | 188 | assert_select 'option[value=required][selected=selected]', 0 |
|
189 | 189 | end |
|
190 | 190 | |
|
191 | 191 | # Other field |
|
192 | 192 | assert_select 'select[name=?]', 'permissions[3][due_date]' do |
|
193 | 193 | assert_select 'option[value=""]' |
|
194 | 194 | assert_select 'option[value=""][selected=selected]', 0 |
|
195 | 195 | assert_select 'option[value=readonly]', :text => 'Read-only' |
|
196 | 196 | assert_select 'option[value=readonly][selected=selected]', 0 |
|
197 | 197 | assert_select 'option[value=required]', :text => 'Required' |
|
198 | 198 | assert_select 'option[value=required][selected=selected]', 0 |
|
199 | 199 | end |
|
200 | 200 | end |
|
201 | 201 | |
|
202 | 202 | def test_get_permissions_with_required_custom_field_should_not_show_required_option |
|
203 | 203 | cf = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :tracker_ids => [1], :is_required => true) |
|
204 | 204 | |
|
205 | 205 | get :permissions, :role_id => 1, :tracker_id => 1 |
|
206 | 206 | assert_response :success |
|
207 | 207 | assert_template 'permissions' |
|
208 | 208 | |
|
209 | 209 | # Custom field that is always required |
|
210 | 210 | # The default option is "(Required)" |
|
211 | 211 | assert_select 'select[name=?]', "permissions[3][#{cf.id}]" do |
|
212 | 212 | assert_select 'option[value=""]' |
|
213 | 213 | assert_select 'option[value=readonly]', :text => 'Read-only' |
|
214 | 214 | assert_select 'option[value=required]', 0 |
|
215 | 215 | end |
|
216 | 216 | end |
|
217 | 217 | |
|
218 | 218 | def test_get_permissions_should_disable_hidden_custom_fields |
|
219 | 219 | cf1 = IssueCustomField.generate!(:tracker_ids => [1], :visible => true) |
|
220 | 220 | cf2 = IssueCustomField.generate!(:tracker_ids => [1], :visible => false, :role_ids => [1]) |
|
221 | 221 | cf3 = IssueCustomField.generate!(:tracker_ids => [1], :visible => false, :role_ids => [1, 2]) |
|
222 | 222 | |
|
223 | 223 | get :permissions, :role_id => 2, :tracker_id => 1 |
|
224 | 224 | assert_response :success |
|
225 | 225 | assert_template 'permissions' |
|
226 | 226 | |
|
227 | 227 | assert_select 'select[name=?]:not(.disabled)', "permissions[1][#{cf1.id}]" |
|
228 | 228 | assert_select 'select[name=?]:not(.disabled)', "permissions[1][#{cf3.id}]" |
|
229 | 229 | |
|
230 | 230 | assert_select 'select[name=?][disabled=disabled]', "permissions[1][#{cf2.id}]" do |
|
231 | 231 | assert_select 'option[value=""][selected=selected]', :text => 'Hidden' |
|
232 | 232 | end |
|
233 | 233 | end |
|
234 | 234 | |
|
235 | 235 | def test_get_permissions_with_missing_permissions_for_roles_should_default_to_no_change |
|
236 | 236 | WorkflowPermission.delete_all |
|
237 | 237 | WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 1, :field_name => 'assigned_to_id', :rule => 'required') |
|
238 | 238 | |
|
239 | 239 | get :permissions, :role_id => [1, 2], :tracker_id => 2 |
|
240 | 240 | assert_response :success |
|
241 | 241 | |
|
242 | 242 | assert_select 'select[name=?]', 'permissions[1][assigned_to_id]' do |
|
243 | 243 | assert_select 'option[selected]', 1 |
|
244 | 244 | assert_select 'option[selected][value=no_change]' |
|
245 | 245 | end |
|
246 | 246 | end |
|
247 | 247 | |
|
248 | 248 | def test_get_permissions_with_different_permissions_for_roles_should_default_to_no_change |
|
249 | 249 | WorkflowPermission.delete_all |
|
250 | 250 | WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 1, :field_name => 'assigned_to_id', :rule => 'required') |
|
251 | 251 | WorkflowPermission.create!(:role_id => 2, :tracker_id => 2, :old_status_id => 1, :field_name => 'assigned_to_id', :rule => 'readonly') |
|
252 | 252 | |
|
253 | 253 | get :permissions, :role_id => [1, 2], :tracker_id => 2 |
|
254 | 254 | assert_response :success |
|
255 | 255 | |
|
256 | 256 | assert_select 'select[name=?]', 'permissions[1][assigned_to_id]' do |
|
257 | 257 | assert_select 'option[selected]', 1 |
|
258 | 258 | assert_select 'option[selected][value=no_change]' |
|
259 | 259 | end |
|
260 | 260 | end |
|
261 | 261 | |
|
262 | 262 | def test_get_permissions_with_same_permissions_for_roles_should_default_to_permission |
|
263 | 263 | WorkflowPermission.delete_all |
|
264 | 264 | WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 1, :field_name => 'assigned_to_id', :rule => 'required') |
|
265 | 265 | WorkflowPermission.create!(:role_id => 2, :tracker_id => 2, :old_status_id => 1, :field_name => 'assigned_to_id', :rule => 'required') |
|
266 | 266 | |
|
267 | 267 | get :permissions, :role_id => [1, 2], :tracker_id => 2 |
|
268 | 268 | assert_response :success |
|
269 | 269 | |
|
270 | 270 | assert_select 'select[name=?]', 'permissions[1][assigned_to_id]' do |
|
271 | 271 | assert_select 'option[selected]', 1 |
|
272 | 272 | assert_select 'option[selected][value=required]' |
|
273 | 273 | end |
|
274 | 274 | end |
|
275 | 275 | |
|
276 | 276 | def test_get_permissions_with_role_and_tracker_and_all_statuses_should_show_all_statuses |
|
277 | 277 | WorkflowTransition.delete_all |
|
278 | 278 | |
|
279 | 279 | get :permissions, :role_id => 1, :tracker_id => 2, :used_statuses_only => '0' |
|
280 | 280 | assert_response :success |
|
281 | 281 | assert_equal IssueStatus.sorted.to_a, assigns(:statuses) |
|
282 | 282 | end |
|
283 | 283 | |
|
284 | 284 | def test_get_permissions_should_set_css_class |
|
285 | 285 | WorkflowPermission.delete_all |
|
286 | 286 | WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 1, :field_name => 'assigned_to_id', :rule => 'required') |
|
287 | cf = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :tracker_ids => [2]) | |
|
288 | WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 1, :field_name => cf.id, :rule => 'required') | |
|
287 | 289 | |
|
288 | 290 | get :permissions, :role_id => 1, :tracker_id => 2 |
|
289 | 291 | assert_response :success |
|
290 | 292 | assert_select 'td.required > select[name=?]', 'permissions[1][assigned_to_id]' |
|
293 | assert_select 'td.required > select[name=?]', "permissions[1][#{cf.id}]" | |
|
291 | 294 | end |
|
292 | 295 | |
|
293 | 296 | def test_post_permissions |
|
294 | 297 | WorkflowPermission.delete_all |
|
295 | 298 | |
|
296 | 299 | post :permissions, :role_id => 1, :tracker_id => 2, :permissions => { |
|
297 | 300 | '1' => {'assigned_to_id' => '', 'fixed_version_id' => 'required', 'due_date' => ''}, |
|
298 | 301 | '2' => {'assigned_to_id' => 'readonly', 'fixed_version_id' => 'readonly', 'due_date' => ''}, |
|
299 | 302 | '3' => {'assigned_to_id' => '', 'fixed_version_id' => '', 'due_date' => ''} |
|
300 | 303 | } |
|
301 | 304 | assert_response 302 |
|
302 | 305 | |
|
303 | 306 | workflows = WorkflowPermission.all |
|
304 | 307 | assert_equal 3, workflows.size |
|
305 | 308 | workflows.each do |workflow| |
|
306 | 309 | assert_equal 1, workflow.role_id |
|
307 | 310 | assert_equal 2, workflow.tracker_id |
|
308 | 311 | end |
|
309 | 312 | assert workflows.detect {|wf| wf.old_status_id == 2 && wf.field_name == 'assigned_to_id' && wf.rule == 'readonly'} |
|
310 | 313 | assert workflows.detect {|wf| wf.old_status_id == 1 && wf.field_name == 'fixed_version_id' && wf.rule == 'required'} |
|
311 | 314 | assert workflows.detect {|wf| wf.old_status_id == 2 && wf.field_name == 'fixed_version_id' && wf.rule == 'readonly'} |
|
312 | 315 | end |
|
313 | 316 | |
|
314 | 317 | def test_get_copy |
|
315 | 318 | get :copy |
|
316 | 319 | assert_response :success |
|
317 | 320 | assert_template 'copy' |
|
318 | 321 | assert_select 'select[name=source_tracker_id]' do |
|
319 | 322 | assert_select 'option[value="1"]', :text => 'Bug' |
|
320 | 323 | end |
|
321 | 324 | assert_select 'select[name=source_role_id]' do |
|
322 | 325 | assert_select 'option[value="2"]', :text => 'Developer' |
|
323 | 326 | end |
|
324 | 327 | assert_select 'select[name=?]', 'target_tracker_ids[]' do |
|
325 | 328 | assert_select 'option[value="3"]', :text => 'Support request' |
|
326 | 329 | end |
|
327 | 330 | assert_select 'select[name=?]', 'target_role_ids[]' do |
|
328 | 331 | assert_select 'option[value="1"]', :text => 'Manager' |
|
329 | 332 | end |
|
330 | 333 | end |
|
331 | 334 | |
|
332 | 335 | def test_post_copy_one_to_one |
|
333 | 336 | source_transitions = status_transitions(:tracker_id => 1, :role_id => 2) |
|
334 | 337 | |
|
335 | 338 | post :copy, :source_tracker_id => '1', :source_role_id => '2', |
|
336 | 339 | :target_tracker_ids => ['3'], :target_role_ids => ['1'] |
|
337 | 340 | assert_response 302 |
|
338 | 341 | assert_equal source_transitions, status_transitions(:tracker_id => 3, :role_id => 1) |
|
339 | 342 | end |
|
340 | 343 | |
|
341 | 344 | def test_post_copy_one_to_many |
|
342 | 345 | source_transitions = status_transitions(:tracker_id => 1, :role_id => 2) |
|
343 | 346 | |
|
344 | 347 | post :copy, :source_tracker_id => '1', :source_role_id => '2', |
|
345 | 348 | :target_tracker_ids => ['2', '3'], :target_role_ids => ['1', '3'] |
|
346 | 349 | assert_response 302 |
|
347 | 350 | assert_equal source_transitions, status_transitions(:tracker_id => 2, :role_id => 1) |
|
348 | 351 | assert_equal source_transitions, status_transitions(:tracker_id => 3, :role_id => 1) |
|
349 | 352 | assert_equal source_transitions, status_transitions(:tracker_id => 2, :role_id => 3) |
|
350 | 353 | assert_equal source_transitions, status_transitions(:tracker_id => 3, :role_id => 3) |
|
351 | 354 | end |
|
352 | 355 | |
|
353 | 356 | def test_post_copy_many_to_many |
|
354 | 357 | source_t2 = status_transitions(:tracker_id => 2, :role_id => 2) |
|
355 | 358 | source_t3 = status_transitions(:tracker_id => 3, :role_id => 2) |
|
356 | 359 | |
|
357 | 360 | post :copy, :source_tracker_id => 'any', :source_role_id => '2', |
|
358 | 361 | :target_tracker_ids => ['2', '3'], :target_role_ids => ['1', '3'] |
|
359 | 362 | assert_response 302 |
|
360 | 363 | assert_equal source_t2, status_transitions(:tracker_id => 2, :role_id => 1) |
|
361 | 364 | assert_equal source_t3, status_transitions(:tracker_id => 3, :role_id => 1) |
|
362 | 365 | assert_equal source_t2, status_transitions(:tracker_id => 2, :role_id => 3) |
|
363 | 366 | assert_equal source_t3, status_transitions(:tracker_id => 3, :role_id => 3) |
|
364 | 367 | end |
|
365 | 368 | |
|
366 | 369 | def test_post_copy_with_incomplete_source_specification_should_fail |
|
367 | 370 | assert_no_difference 'WorkflowRule.count' do |
|
368 | 371 | post :copy, |
|
369 | 372 | :source_tracker_id => '', :source_role_id => '2', |
|
370 | 373 | :target_tracker_ids => ['2', '3'], :target_role_ids => ['1', '3'] |
|
371 | 374 | assert_response 200 |
|
372 | 375 | assert_select 'div.flash.error', :text => 'Please select a source tracker or role' |
|
373 | 376 | end |
|
374 | 377 | end |
|
375 | 378 | |
|
376 | 379 | def test_post_copy_with_incomplete_target_specification_should_fail |
|
377 | 380 | assert_no_difference 'WorkflowRule.count' do |
|
378 | 381 | post :copy, |
|
379 | 382 | :source_tracker_id => '1', :source_role_id => '2', |
|
380 | 383 | :target_tracker_ids => ['2', '3'] |
|
381 | 384 | assert_response 200 |
|
382 | 385 | assert_select 'div.flash.error', :text => 'Please select target tracker(s) and role(s)' |
|
383 | 386 | end |
|
384 | 387 | end |
|
385 | 388 | |
|
386 | 389 | # Returns an array of status transitions that can be compared |
|
387 | 390 | def status_transitions(conditions) |
|
388 | 391 | WorkflowTransition. |
|
389 | 392 | where(conditions). |
|
390 | 393 | order('tracker_id, role_id, old_status_id, new_status_id'). |
|
391 | 394 | collect {|w| [w.old_status, w.new_status_id]} |
|
392 | 395 | end |
|
393 | 396 | end |
General Comments 0
You need to be logged in to leave comments.
Login now