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