@@ -1,27 +1,31 | |||||
1 | # encoding: utf-8 |
|
1 | # encoding: utf-8 | |
2 | # |
|
2 | # | |
3 | # Redmine - project management software |
|
3 | # Redmine - project management software | |
4 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
4 | # Copyright (C) 2006-2012 Jean-Philippe Lang | |
5 | # |
|
5 | # | |
6 | # This program is free software; you can redistribute it and/or |
|
6 | # This program is free software; you can redistribute it and/or | |
7 | # modify it under the terms of the GNU General Public License |
|
7 | # modify it under the terms of the GNU General Public License | |
8 | # as published by the Free Software Foundation; either version 2 |
|
8 | # as published by the Free Software Foundation; either version 2 | |
9 | # of the License, or (at your option) any later version. |
|
9 | # of the License, or (at your option) any later version. | |
10 | # |
|
10 | # | |
11 | # This program is distributed in the hope that it will be useful, |
|
11 | # This program is distributed in the hope that it will be useful, | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | # GNU General Public License for more details. |
|
14 | # GNU General Public License for more details. | |
15 | # |
|
15 | # | |
16 | # You should have received a copy of the GNU General Public License |
|
16 | # You should have received a copy of the GNU General Public License | |
17 | # along with this program; if not, write to the Free Software |
|
17 | # along with this program; if not, write to the Free Software | |
18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
19 |
|
19 | |||
20 | module WorkflowsHelper |
|
20 | module WorkflowsHelper | |
21 | def field_permission_tag(permissions, status, field) |
|
21 | def field_permission_tag(permissions, status, field) | |
22 | name = field.is_a?(CustomField) ? field.id.to_s : field |
|
22 | name = field.is_a?(CustomField) ? field.id.to_s : field | |
23 | select_tag("permissions[#{name}][#{status.id}]", |
|
23 | options = [["", ""], [l(:label_readonly), "readonly"], [l(:label_required), "required"]] | |
24 | options_for_select([["", ""], [l(:label_readonly), "readonly"], [l(:label_required), "required"]], permissions[status.id][name]) |
|
24 | ||
25 | ) |
|
25 | if field.is_a?(CustomField) && field.is_required? | |
|
26 | options = [["(#{l(:label_required)})", ""], [l(:label_readonly), "readonly"]] | |||
|
27 | end | |||
|
28 | ||||
|
29 | select_tag("permissions[#{name}][#{status.id}]", options_for_select(options, permissions[status.id][name])) | |||
26 | end |
|
30 | end | |
27 | end |
|
31 | end |
@@ -1,296 +1,312 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2012 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 | require 'workflows_controller' |
|
19 | require 'workflows_controller' | |
20 |
|
20 | |||
21 | # Re-raise errors caught by the controller. |
|
21 | # Re-raise errors caught by the controller. | |
22 | class WorkflowsController; def rescue_action(e) raise e end; end |
|
22 | class WorkflowsController; def rescue_action(e) raise e end; end | |
23 |
|
23 | |||
24 | class WorkflowsControllerTest < ActionController::TestCase |
|
24 | class WorkflowsControllerTest < ActionController::TestCase | |
25 | fixtures :roles, :trackers, :workflows, :users, :issue_statuses |
|
25 | fixtures :roles, :trackers, :workflows, :users, :issue_statuses | |
26 |
|
26 | |||
27 | def setup |
|
27 | def setup | |
28 | @controller = WorkflowsController.new |
|
28 | @controller = WorkflowsController.new | |
29 | @request = ActionController::TestRequest.new |
|
29 | @request = ActionController::TestRequest.new | |
30 | @response = ActionController::TestResponse.new |
|
30 | @response = ActionController::TestResponse.new | |
31 | User.current = nil |
|
31 | User.current = nil | |
32 | @request.session[:user_id] = 1 # admin |
|
32 | @request.session[:user_id] = 1 # admin | |
33 | end |
|
33 | end | |
34 |
|
34 | |||
35 | def test_index |
|
35 | def test_index | |
36 | get :index |
|
36 | get :index | |
37 | assert_response :success |
|
37 | assert_response :success | |
38 | assert_template 'index' |
|
38 | assert_template 'index' | |
39 |
|
39 | |||
40 | count = WorkflowTransition.count(:all, :conditions => 'role_id = 1 AND tracker_id = 2') |
|
40 | count = WorkflowTransition.count(:all, :conditions => 'role_id = 1 AND tracker_id = 2') | |
41 | assert_tag :tag => 'a', :content => count.to_s, |
|
41 | assert_tag :tag => 'a', :content => count.to_s, | |
42 | :attributes => { :href => '/workflows/edit?role_id=1&tracker_id=2' } |
|
42 | :attributes => { :href => '/workflows/edit?role_id=1&tracker_id=2' } | |
43 | end |
|
43 | end | |
44 |
|
44 | |||
45 | def test_get_edit |
|
45 | def test_get_edit | |
46 | get :edit |
|
46 | get :edit | |
47 | assert_response :success |
|
47 | assert_response :success | |
48 | assert_template 'edit' |
|
48 | assert_template 'edit' | |
49 | assert_not_nil assigns(:roles) |
|
49 | assert_not_nil assigns(:roles) | |
50 | assert_not_nil assigns(:trackers) |
|
50 | assert_not_nil assigns(:trackers) | |
51 | end |
|
51 | end | |
52 |
|
52 | |||
53 | def test_get_edit_with_role_and_tracker |
|
53 | def test_get_edit_with_role_and_tracker | |
54 | WorkflowTransition.delete_all |
|
54 | WorkflowTransition.delete_all | |
55 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 2, :new_status_id => 3) |
|
55 | WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 2, :new_status_id => 3) | |
56 | WorkflowTransition.create!(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 5) |
|
56 | WorkflowTransition.create!(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 5) | |
57 |
|
57 | |||
58 | get :edit, :role_id => 2, :tracker_id => 1 |
|
58 | get :edit, :role_id => 2, :tracker_id => 1 | |
59 | assert_response :success |
|
59 | assert_response :success | |
60 | assert_template 'edit' |
|
60 | assert_template 'edit' | |
61 |
|
61 | |||
62 | # used status only |
|
62 | # used status only | |
63 | assert_not_nil assigns(:statuses) |
|
63 | assert_not_nil assigns(:statuses) | |
64 | assert_equal [2, 3, 5], assigns(:statuses).collect(&:id) |
|
64 | assert_equal [2, 3, 5], assigns(:statuses).collect(&:id) | |
65 |
|
65 | |||
66 | # allowed transitions |
|
66 | # allowed transitions | |
67 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
67 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
68 | :name => 'issue_status[3][5][]', |
|
68 | :name => 'issue_status[3][5][]', | |
69 | :value => 'always', |
|
69 | :value => 'always', | |
70 | :checked => 'checked' } |
|
70 | :checked => 'checked' } | |
71 | # not allowed |
|
71 | # not allowed | |
72 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
72 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
73 | :name => 'issue_status[3][2][]', |
|
73 | :name => 'issue_status[3][2][]', | |
74 | :value => 'always', |
|
74 | :value => 'always', | |
75 | :checked => nil } |
|
75 | :checked => nil } | |
76 | # unused |
|
76 | # unused | |
77 | assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
77 | assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
78 | :name => 'issue_status[1][1][]' } |
|
78 | :name => 'issue_status[1][1][]' } | |
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_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
91 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
92 | :name => 'issue_status[1][1][]', |
|
92 | :name => 'issue_status[1][1][]', | |
93 | :value => 'always', |
|
93 | :value => 'always', | |
94 | :checked => nil } |
|
94 | :checked => nil } | |
95 | end |
|
95 | end | |
96 |
|
96 | |||
97 | def test_post_edit |
|
97 | def test_post_edit | |
98 | post :edit, :role_id => 2, :tracker_id => 1, |
|
98 | post :edit, :role_id => 2, :tracker_id => 1, | |
99 | :issue_status => { |
|
99 | :issue_status => { | |
100 | '4' => {'5' => ['always']}, |
|
100 | '4' => {'5' => ['always']}, | |
101 | '3' => {'1' => ['always'], '2' => ['always']} |
|
101 | '3' => {'1' => ['always'], '2' => ['always']} | |
102 | } |
|
102 | } | |
103 | assert_redirected_to '/workflows/edit?role_id=2&tracker_id=1' |
|
103 | assert_redirected_to '/workflows/edit?role_id=2&tracker_id=1' | |
104 |
|
104 | |||
105 | assert_equal 3, WorkflowTransition.count(:conditions => {:tracker_id => 1, :role_id => 2}) |
|
105 | assert_equal 3, WorkflowTransition.count(:conditions => {:tracker_id => 1, :role_id => 2}) | |
106 | assert_not_nil WorkflowTransition.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2}) |
|
106 | assert_not_nil WorkflowTransition.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2}) | |
107 | assert_nil WorkflowTransition.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4}) |
|
107 | assert_nil WorkflowTransition.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4}) | |
108 | end |
|
108 | end | |
109 |
|
109 | |||
110 | def test_post_edit_with_additional_transitions |
|
110 | def test_post_edit_with_additional_transitions | |
111 | post :edit, :role_id => 2, :tracker_id => 1, |
|
111 | post :edit, :role_id => 2, :tracker_id => 1, | |
112 | :issue_status => { |
|
112 | :issue_status => { | |
113 | '4' => {'5' => ['always']}, |
|
113 | '4' => {'5' => ['always']}, | |
114 | '3' => {'1' => ['author'], '2' => ['assignee'], '4' => ['author', 'assignee']} |
|
114 | '3' => {'1' => ['author'], '2' => ['assignee'], '4' => ['author', 'assignee']} | |
115 | } |
|
115 | } | |
116 | assert_redirected_to '/workflows/edit?role_id=2&tracker_id=1' |
|
116 | assert_redirected_to '/workflows/edit?role_id=2&tracker_id=1' | |
117 |
|
117 | |||
118 | assert_equal 4, WorkflowTransition.count(:conditions => {:tracker_id => 1, :role_id => 2}) |
|
118 | assert_equal 4, WorkflowTransition.count(:conditions => {:tracker_id => 1, :role_id => 2}) | |
119 |
|
119 | |||
120 | w = WorkflowTransition.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 4, :new_status_id => 5}) |
|
120 | w = WorkflowTransition.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 4, :new_status_id => 5}) | |
121 | assert ! w.author |
|
121 | assert ! w.author | |
122 | assert ! w.assignee |
|
122 | assert ! w.assignee | |
123 | w = WorkflowTransition.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 1}) |
|
123 | w = WorkflowTransition.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 1}) | |
124 | assert w.author |
|
124 | assert w.author | |
125 | assert ! w.assignee |
|
125 | assert ! w.assignee | |
126 | w = WorkflowTransition.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2}) |
|
126 | w = WorkflowTransition.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2}) | |
127 | assert ! w.author |
|
127 | assert ! w.author | |
128 | assert w.assignee |
|
128 | assert w.assignee | |
129 | w = WorkflowTransition.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 4}) |
|
129 | w = WorkflowTransition.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 4}) | |
130 | assert w.author |
|
130 | assert w.author | |
131 | assert w.assignee |
|
131 | assert w.assignee | |
132 | end |
|
132 | end | |
133 |
|
133 | |||
134 | def test_clear_workflow |
|
134 | def test_clear_workflow | |
135 | assert WorkflowTransition.count(:conditions => {:tracker_id => 1, :role_id => 2}) > 0 |
|
135 | assert WorkflowTransition.count(:conditions => {:tracker_id => 1, :role_id => 2}) > 0 | |
136 |
|
136 | |||
137 | post :edit, :role_id => 2, :tracker_id => 1 |
|
137 | post :edit, :role_id => 2, :tracker_id => 1 | |
138 | assert_equal 0, WorkflowTransition.count(:conditions => {:tracker_id => 1, :role_id => 2}) |
|
138 | assert_equal 0, WorkflowTransition.count(:conditions => {:tracker_id => 1, :role_id => 2}) | |
139 | end |
|
139 | end | |
140 |
|
140 | |||
141 | def test_get_permissions |
|
141 | def test_get_permissions | |
142 | get :permissions |
|
142 | get :permissions | |
143 |
|
143 | |||
144 | assert_response :success |
|
144 | assert_response :success | |
145 | assert_template 'permissions' |
|
145 | assert_template 'permissions' | |
146 | assert_not_nil assigns(:roles) |
|
146 | assert_not_nil assigns(:roles) | |
147 | assert_not_nil assigns(:trackers) |
|
147 | assert_not_nil assigns(:trackers) | |
148 | end |
|
148 | end | |
149 |
|
149 | |||
150 | def test_get_permissions_with_role_and_tracker |
|
150 | def test_get_permissions_with_role_and_tracker | |
151 | WorkflowPermission.delete_all |
|
151 | WorkflowPermission.delete_all | |
152 | WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :field_name => 'assigned_to_id', :rule => 'required') |
|
152 | WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :field_name => 'assigned_to_id', :rule => 'required') | |
153 | WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :field_name => 'fixed_version_id', :rule => 'required') |
|
153 | WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :field_name => 'fixed_version_id', :rule => 'required') | |
154 | WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 3, :field_name => 'fixed_version_id', :rule => 'readonly') |
|
154 | WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 3, :field_name => 'fixed_version_id', :rule => 'readonly') | |
155 |
|
155 | |||
156 | get :permissions, :role_id => 1, :tracker_id => 2 |
|
156 | get :permissions, :role_id => 1, :tracker_id => 2 | |
157 | assert_response :success |
|
157 | assert_response :success | |
158 | assert_template 'permissions' |
|
158 | assert_template 'permissions' | |
159 |
|
159 | |||
160 | assert_select 'input[name=role_id][value=1]' |
|
160 | assert_select 'input[name=role_id][value=1]' | |
161 | assert_select 'input[name=tracker_id][value=2]' |
|
161 | assert_select 'input[name=tracker_id][value=2]' | |
162 |
|
162 | |||
163 | # Required field |
|
163 | # Required field | |
164 | assert_select 'select[name=?]', 'permissions[assigned_to_id][2]' do |
|
164 | assert_select 'select[name=?]', 'permissions[assigned_to_id][2]' do | |
165 | assert_select 'option[value=]' |
|
165 | assert_select 'option[value=]' | |
166 | assert_select 'option[value=][selected=selected]', 0 |
|
166 | assert_select 'option[value=][selected=selected]', 0 | |
167 | assert_select 'option[value=readonly]', :text => 'Read-only' |
|
167 | assert_select 'option[value=readonly]', :text => 'Read-only' | |
168 | assert_select 'option[value=readonly][selected=selected]', 0 |
|
168 | assert_select 'option[value=readonly][selected=selected]', 0 | |
169 | assert_select 'option[value=required]', :text => 'Required' |
|
169 | assert_select 'option[value=required]', :text => 'Required' | |
170 | assert_select 'option[value=required][selected=selected]' |
|
170 | assert_select 'option[value=required][selected=selected]' | |
171 | end |
|
171 | end | |
172 |
|
172 | |||
173 | # Read-only field |
|
173 | # Read-only field | |
174 | assert_select 'select[name=?]', 'permissions[fixed_version_id][3]' do |
|
174 | assert_select 'select[name=?]', 'permissions[fixed_version_id][3]' do | |
175 | assert_select 'option[value=]' |
|
175 | assert_select 'option[value=]' | |
176 | assert_select 'option[value=][selected=selected]', 0 |
|
176 | assert_select 'option[value=][selected=selected]', 0 | |
177 | assert_select 'option[value=readonly]', :text => 'Read-only' |
|
177 | assert_select 'option[value=readonly]', :text => 'Read-only' | |
178 | assert_select 'option[value=readonly][selected=selected]' |
|
178 | assert_select 'option[value=readonly][selected=selected]' | |
179 | assert_select 'option[value=required]', :text => 'Required' |
|
179 | assert_select 'option[value=required]', :text => 'Required' | |
180 | assert_select 'option[value=required][selected=selected]', 0 |
|
180 | assert_select 'option[value=required][selected=selected]', 0 | |
181 | end |
|
181 | end | |
182 |
|
182 | |||
183 | # Other field |
|
183 | # Other field | |
184 | assert_select 'select[name=?]', 'permissions[due_date][3]' do |
|
184 | assert_select 'select[name=?]', 'permissions[due_date][3]' do | |
185 | assert_select 'option[value=]' |
|
185 | assert_select 'option[value=]' | |
186 | assert_select 'option[value=][selected=selected]', 0 |
|
186 | assert_select 'option[value=][selected=selected]', 0 | |
187 | assert_select 'option[value=readonly]', :text => 'Read-only' |
|
187 | assert_select 'option[value=readonly]', :text => 'Read-only' | |
188 | assert_select 'option[value=readonly][selected=selected]', 0 |
|
188 | assert_select 'option[value=readonly][selected=selected]', 0 | |
189 | assert_select 'option[value=required]', :text => 'Required' |
|
189 | assert_select 'option[value=required]', :text => 'Required' | |
190 | assert_select 'option[value=required][selected=selected]', 0 |
|
190 | assert_select 'option[value=required][selected=selected]', 0 | |
191 | end |
|
191 | end | |
192 | end |
|
192 | end | |
193 |
|
193 | |||
|
194 | def test_get_permissions_with_always_required_custom_field | |||
|
195 | cf = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :tracker_ids => [1], :is_required => true) | |||
|
196 | ||||
|
197 | get :permissions, :role_id => 1, :tracker_id => 1 | |||
|
198 | assert_response :success | |||
|
199 | assert_template 'permissions' | |||
|
200 | ||||
|
201 | # Custom field that is always required | |||
|
202 | # The default option is "(Required)" | |||
|
203 | assert_select 'select[name=?]', "permissions[#{cf.id}][3]" do | |||
|
204 | assert_select 'option[value=]', :text => '(Required)' | |||
|
205 | assert_select 'option[value=readonly]', :text => 'Read-only' | |||
|
206 | assert_select 'option[value=required]', 0 | |||
|
207 | end | |||
|
208 | end | |||
|
209 | ||||
194 | def test_get_permissions_with_role_and_tracker_and_all_statuses |
|
210 | def test_get_permissions_with_role_and_tracker_and_all_statuses | |
195 | WorkflowTransition.delete_all |
|
211 | WorkflowTransition.delete_all | |
196 |
|
212 | |||
197 | get :permissions, :role_id => 1, :tracker_id => 2, :used_statuses_only => '0' |
|
213 | get :permissions, :role_id => 1, :tracker_id => 2, :used_statuses_only => '0' | |
198 | assert_response :success |
|
214 | assert_response :success | |
199 | assert_equal IssueStatus.sorted.all, assigns(:statuses) |
|
215 | assert_equal IssueStatus.sorted.all, assigns(:statuses) | |
200 | end |
|
216 | end | |
201 |
|
217 | |||
202 | def test_post_permissions |
|
218 | def test_post_permissions | |
203 | WorkflowPermission.delete_all |
|
219 | WorkflowPermission.delete_all | |
204 |
|
220 | |||
205 | post :permissions, :role_id => 1, :tracker_id => 2, :permissions => { |
|
221 | post :permissions, :role_id => 1, :tracker_id => 2, :permissions => { | |
206 | 'assigned_to_id' => {'1' => '', '2' => 'readonly', '3' => ''}, |
|
222 | 'assigned_to_id' => {'1' => '', '2' => 'readonly', '3' => ''}, | |
207 | 'fixed_version_id' => {'1' => 'required', '2' => 'readonly', '3' => ''}, |
|
223 | 'fixed_version_id' => {'1' => 'required', '2' => 'readonly', '3' => ''}, | |
208 | 'due_date' => {'1' => '', '2' => '', '3' => ''}, |
|
224 | 'due_date' => {'1' => '', '2' => '', '3' => ''}, | |
209 | } |
|
225 | } | |
210 | assert_redirected_to '/workflows/permissions?role_id=1&tracker_id=2' |
|
226 | assert_redirected_to '/workflows/permissions?role_id=1&tracker_id=2' | |
211 |
|
227 | |||
212 | workflows = WorkflowPermission.all |
|
228 | workflows = WorkflowPermission.all | |
213 | assert_equal 3, workflows.size |
|
229 | assert_equal 3, workflows.size | |
214 | workflows.each do |workflow| |
|
230 | workflows.each do |workflow| | |
215 | assert_equal 1, workflow.role_id |
|
231 | assert_equal 1, workflow.role_id | |
216 | assert_equal 2, workflow.tracker_id |
|
232 | assert_equal 2, workflow.tracker_id | |
217 | end |
|
233 | end | |
218 | assert workflows.detect {|wf| wf.old_status_id == 2 && wf.field_name == 'assigned_to_id' && wf.rule == 'readonly'} |
|
234 | assert workflows.detect {|wf| wf.old_status_id == 2 && wf.field_name == 'assigned_to_id' && wf.rule == 'readonly'} | |
219 | assert workflows.detect {|wf| wf.old_status_id == 1 && wf.field_name == 'fixed_version_id' && wf.rule == 'required'} |
|
235 | assert workflows.detect {|wf| wf.old_status_id == 1 && wf.field_name == 'fixed_version_id' && wf.rule == 'required'} | |
220 | assert workflows.detect {|wf| wf.old_status_id == 2 && wf.field_name == 'fixed_version_id' && wf.rule == 'readonly'} |
|
236 | assert workflows.detect {|wf| wf.old_status_id == 2 && wf.field_name == 'fixed_version_id' && wf.rule == 'readonly'} | |
221 | end |
|
237 | end | |
222 |
|
238 | |||
223 | def test_post_permissions_should_clear_permissions |
|
239 | def test_post_permissions_should_clear_permissions | |
224 | WorkflowPermission.delete_all |
|
240 | WorkflowPermission.delete_all | |
225 | WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :field_name => 'assigned_to_id', :rule => 'required') |
|
241 | WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :field_name => 'assigned_to_id', :rule => 'required') | |
226 | WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :field_name => 'fixed_version_id', :rule => 'required') |
|
242 | WorkflowPermission.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :field_name => 'fixed_version_id', :rule => 'required') | |
227 | wf1 = WorkflowPermission.create!(:role_id => 1, :tracker_id => 3, :old_status_id => 2, :field_name => 'fixed_version_id', :rule => 'required') |
|
243 | wf1 = WorkflowPermission.create!(:role_id => 1, :tracker_id => 3, :old_status_id => 2, :field_name => 'fixed_version_id', :rule => 'required') | |
228 | wf2 = WorkflowPermission.create!(:role_id => 2, :tracker_id => 2, :old_status_id => 3, :field_name => 'fixed_version_id', :rule => 'readonly') |
|
244 | wf2 = WorkflowPermission.create!(:role_id => 2, :tracker_id => 2, :old_status_id => 3, :field_name => 'fixed_version_id', :rule => 'readonly') | |
229 |
|
245 | |||
230 | post :permissions, :role_id => 1, :tracker_id => 2 |
|
246 | post :permissions, :role_id => 1, :tracker_id => 2 | |
231 | assert_redirected_to '/workflows/permissions?role_id=1&tracker_id=2' |
|
247 | assert_redirected_to '/workflows/permissions?role_id=1&tracker_id=2' | |
232 |
|
248 | |||
233 | workflows = WorkflowPermission.all |
|
249 | workflows = WorkflowPermission.all | |
234 | assert_equal 2, workflows.size |
|
250 | assert_equal 2, workflows.size | |
235 | assert wf1.reload |
|
251 | assert wf1.reload | |
236 | assert wf2.reload |
|
252 | assert wf2.reload | |
237 | end |
|
253 | end | |
238 |
|
254 | |||
239 | def test_get_copy |
|
255 | def test_get_copy | |
240 | get :copy |
|
256 | get :copy | |
241 | assert_response :success |
|
257 | assert_response :success | |
242 | assert_template 'copy' |
|
258 | assert_template 'copy' | |
243 | assert_select 'select[name=source_tracker_id]' do |
|
259 | assert_select 'select[name=source_tracker_id]' do | |
244 | assert_select 'option[value=1]', :text => 'Bug' |
|
260 | assert_select 'option[value=1]', :text => 'Bug' | |
245 | end |
|
261 | end | |
246 | assert_select 'select[name=source_role_id]' do |
|
262 | assert_select 'select[name=source_role_id]' do | |
247 | assert_select 'option[value=2]', :text => 'Developer' |
|
263 | assert_select 'option[value=2]', :text => 'Developer' | |
248 | end |
|
264 | end | |
249 | assert_select 'select[name=?]', 'target_tracker_ids[]' do |
|
265 | assert_select 'select[name=?]', 'target_tracker_ids[]' do | |
250 | assert_select 'option[value=3]', :text => 'Support request' |
|
266 | assert_select 'option[value=3]', :text => 'Support request' | |
251 | end |
|
267 | end | |
252 | assert_select 'select[name=?]', 'target_role_ids[]' do |
|
268 | assert_select 'select[name=?]', 'target_role_ids[]' do | |
253 | assert_select 'option[value=1]', :text => 'Manager' |
|
269 | assert_select 'option[value=1]', :text => 'Manager' | |
254 | end |
|
270 | end | |
255 | end |
|
271 | end | |
256 |
|
272 | |||
257 | def test_post_copy_one_to_one |
|
273 | def test_post_copy_one_to_one | |
258 | source_transitions = status_transitions(:tracker_id => 1, :role_id => 2) |
|
274 | source_transitions = status_transitions(:tracker_id => 1, :role_id => 2) | |
259 |
|
275 | |||
260 | post :copy, :source_tracker_id => '1', :source_role_id => '2', |
|
276 | post :copy, :source_tracker_id => '1', :source_role_id => '2', | |
261 | :target_tracker_ids => ['3'], :target_role_ids => ['1'] |
|
277 | :target_tracker_ids => ['3'], :target_role_ids => ['1'] | |
262 | assert_response 302 |
|
278 | assert_response 302 | |
263 | assert_equal source_transitions, status_transitions(:tracker_id => 3, :role_id => 1) |
|
279 | assert_equal source_transitions, status_transitions(:tracker_id => 3, :role_id => 1) | |
264 | end |
|
280 | end | |
265 |
|
281 | |||
266 | def test_post_copy_one_to_many |
|
282 | def test_post_copy_one_to_many | |
267 | source_transitions = status_transitions(:tracker_id => 1, :role_id => 2) |
|
283 | source_transitions = status_transitions(:tracker_id => 1, :role_id => 2) | |
268 |
|
284 | |||
269 | post :copy, :source_tracker_id => '1', :source_role_id => '2', |
|
285 | post :copy, :source_tracker_id => '1', :source_role_id => '2', | |
270 | :target_tracker_ids => ['2', '3'], :target_role_ids => ['1', '3'] |
|
286 | :target_tracker_ids => ['2', '3'], :target_role_ids => ['1', '3'] | |
271 | assert_response 302 |
|
287 | assert_response 302 | |
272 | assert_equal source_transitions, status_transitions(:tracker_id => 2, :role_id => 1) |
|
288 | assert_equal source_transitions, status_transitions(:tracker_id => 2, :role_id => 1) | |
273 | 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) | |
274 | assert_equal source_transitions, status_transitions(:tracker_id => 2, :role_id => 3) |
|
290 | assert_equal source_transitions, status_transitions(:tracker_id => 2, :role_id => 3) | |
275 | assert_equal source_transitions, status_transitions(:tracker_id => 3, :role_id => 3) |
|
291 | assert_equal source_transitions, status_transitions(:tracker_id => 3, :role_id => 3) | |
276 | end |
|
292 | end | |
277 |
|
293 | |||
278 | def test_post_copy_many_to_many |
|
294 | def test_post_copy_many_to_many | |
279 | source_t2 = status_transitions(:tracker_id => 2, :role_id => 2) |
|
295 | source_t2 = status_transitions(:tracker_id => 2, :role_id => 2) | |
280 | source_t3 = status_transitions(:tracker_id => 3, :role_id => 2) |
|
296 | source_t3 = status_transitions(:tracker_id => 3, :role_id => 2) | |
281 |
|
297 | |||
282 | post :copy, :source_tracker_id => 'any', :source_role_id => '2', |
|
298 | post :copy, :source_tracker_id => 'any', :source_role_id => '2', | |
283 | :target_tracker_ids => ['2', '3'], :target_role_ids => ['1', '3'] |
|
299 | :target_tracker_ids => ['2', '3'], :target_role_ids => ['1', '3'] | |
284 | assert_response 302 |
|
300 | assert_response 302 | |
285 | assert_equal source_t2, status_transitions(:tracker_id => 2, :role_id => 1) |
|
301 | assert_equal source_t2, status_transitions(:tracker_id => 2, :role_id => 1) | |
286 | assert_equal source_t3, status_transitions(:tracker_id => 3, :role_id => 1) |
|
302 | assert_equal source_t3, status_transitions(:tracker_id => 3, :role_id => 1) | |
287 | assert_equal source_t2, status_transitions(:tracker_id => 2, :role_id => 3) |
|
303 | assert_equal source_t2, status_transitions(:tracker_id => 2, :role_id => 3) | |
288 | assert_equal source_t3, status_transitions(:tracker_id => 3, :role_id => 3) |
|
304 | assert_equal source_t3, status_transitions(:tracker_id => 3, :role_id => 3) | |
289 | end |
|
305 | end | |
290 |
|
306 | |||
291 | # Returns an array of status transitions that can be compared |
|
307 | # Returns an array of status transitions that can be compared | |
292 | def status_transitions(conditions) |
|
308 | def status_transitions(conditions) | |
293 | WorkflowTransition.find(:all, :conditions => conditions, |
|
309 | WorkflowTransition.find(:all, :conditions => conditions, | |
294 | :order => 'tracker_id, role_id, old_status_id, new_status_id').collect {|w| [w.old_status, w.new_status_id]} |
|
310 | :order => 'tracker_id, role_id, old_status_id, new_status_id').collect {|w| [w.old_status, w.new_status_id]} | |
295 | end |
|
311 | end | |
296 | end |
|
312 | end |
General Comments 0
You need to be logged in to leave comments.
Login now