@@ -1,40 +1,40 | |||||
1 | <%= render :partial => 'action_menu' %> |
|
1 | <%= render :partial => 'action_menu' %> | |
2 |
|
2 | |||
3 | <h2><%=l(:label_workflow)%></h2> |
|
3 | <h2><%=l(:label_workflow)%></h2> | |
4 |
|
4 | |||
5 | <%= form_tag({}, :id => 'workflow_copy_form') do %> |
|
5 | <%= form_tag({}, :id => 'workflow_copy_form') do %> | |
6 | <fieldset class="tabular box"> |
|
6 | <fieldset class="tabular box"> | |
7 | <legend><%= l(:label_copy_source) %></legend> |
|
7 | <legend><%= l(:label_copy_source) %></legend> | |
8 | <p> |
|
8 | <p> | |
9 | <label><%= l(:label_tracker) %></label> |
|
9 | <label><%= l(:label_tracker) %></label> | |
10 | <%= select_tag('source_tracker_id', |
|
10 | <%= select_tag('source_tracker_id', | |
11 |
|
|
11 | content_tag('option', "--- #{l(:actionview_instancetag_blank_option)} ---", :value => '') + | |
12 |
|
|
12 | content_tag('option', "--- #{ l(:label_copy_same_as_target) } ---", :value => 'any') + | |
13 | options_from_collection_for_select(@trackers, 'id', 'name', @source_tracker && @source_tracker.id)) %> |
|
13 | options_from_collection_for_select(@trackers, 'id', 'name', @source_tracker && @source_tracker.id)) %> | |
14 | </p> |
|
14 | </p> | |
15 | <p> |
|
15 | <p> | |
16 | <label><%= l(:label_role) %></label> |
|
16 | <label><%= l(:label_role) %></label> | |
17 | <%= select_tag('source_role_id', |
|
17 | <%= select_tag('source_role_id', | |
18 |
|
|
18 | content_tag('option', "--- #{l(:actionview_instancetag_blank_option)} ---", :value => '') + | |
19 |
|
|
19 | content_tag('option', "--- #{ l(:label_copy_same_as_target) } ---", :value => 'any') + | |
20 | options_from_collection_for_select(@roles, 'id', 'name', @source_role && @source_role.id)) %> |
|
20 | options_from_collection_for_select(@roles, 'id', 'name', @source_role && @source_role.id)) %> | |
21 | </p> |
|
21 | </p> | |
22 | </fieldset> |
|
22 | </fieldset> | |
23 |
|
23 | |||
24 | <fieldset class="tabular box"> |
|
24 | <fieldset class="tabular box"> | |
25 | <legend><%= l(:label_copy_target) %></legend> |
|
25 | <legend><%= l(:label_copy_target) %></legend> | |
26 | <p> |
|
26 | <p> | |
27 | <label><%= l(:label_tracker) %></label> |
|
27 | <label><%= l(:label_tracker) %></label> | |
28 | <%= select_tag 'target_tracker_ids', |
|
28 | <%= select_tag 'target_tracker_ids', | |
29 |
|
|
29 | content_tag('option', "--- #{l(:actionview_instancetag_blank_option)} ---", :value => '', :disabled => true) + | |
30 | options_from_collection_for_select(@trackers, 'id', 'name', @target_trackers && @target_trackers.map(&:id)), :multiple => true %> |
|
30 | options_from_collection_for_select(@trackers, 'id', 'name', @target_trackers && @target_trackers.map(&:id)), :multiple => true %> | |
31 | </p> |
|
31 | </p> | |
32 | <p> |
|
32 | <p> | |
33 | <label><%= l(:label_role) %></label> |
|
33 | <label><%= l(:label_role) %></label> | |
34 | <%= select_tag 'target_role_ids', |
|
34 | <%= select_tag 'target_role_ids', | |
35 |
|
|
35 | content_tag('option', "--- #{l(:actionview_instancetag_blank_option)} ---", :value => '', :disabled => true) + | |
36 | options_from_collection_for_select(@roles, 'id', 'name', @target_roles && @target_roles.map(&:id)), :multiple => true %> |
|
36 | options_from_collection_for_select(@roles, 'id', 'name', @target_roles && @target_roles.map(&:id)), :multiple => true %> | |
37 | </p> |
|
37 | </p> | |
38 | </fieldset> |
|
38 | </fieldset> | |
39 | <%= submit_tag l(:button_copy) %> |
|
39 | <%= submit_tag l(:button_copy) %> | |
40 | <% end %> |
|
40 | <% end %> |
@@ -1,186 +1,198 | |||||
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 = Workflow.count(:all, :conditions => 'role_id = 1 AND tracker_id = 2') |
|
40 | count = Workflow.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 | Workflow.delete_all |
|
54 | Workflow.delete_all | |
55 | Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 2, :new_status_id => 3) |
|
55 | Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 2, :new_status_id => 3) | |
56 | Workflow.create!(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 5) |
|
56 | Workflow.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 | Workflow.delete_all |
|
82 | Workflow.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, Workflow.count(:conditions => {:tracker_id => 1, :role_id => 2}) |
|
105 | assert_equal 3, Workflow.count(:conditions => {:tracker_id => 1, :role_id => 2}) | |
106 | assert_not_nil Workflow.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2}) |
|
106 | assert_not_nil Workflow.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2}) | |
107 | assert_nil Workflow.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4}) |
|
107 | assert_nil Workflow.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, Workflow.count(:conditions => {:tracker_id => 1, :role_id => 2}) |
|
118 | assert_equal 4, Workflow.count(:conditions => {:tracker_id => 1, :role_id => 2}) | |
119 |
|
119 | |||
120 | w = Workflow.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 4, :new_status_id => 5}) |
|
120 | w = Workflow.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 = Workflow.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 1}) |
|
123 | w = Workflow.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 = Workflow.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2}) |
|
126 | w = Workflow.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 = Workflow.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 4}) |
|
129 | w = Workflow.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 Workflow.count(:conditions => {:tracker_id => 1, :role_id => 2}) > 0 |
|
135 | assert Workflow.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, Workflow.count(:conditions => {:tracker_id => 1, :role_id => 2}) |
|
138 | assert_equal 0, Workflow.count(:conditions => {:tracker_id => 1, :role_id => 2}) | |
139 | end |
|
139 | end | |
140 |
|
140 | |||
141 | def test_get_copy |
|
141 | def test_get_copy | |
142 | get :copy |
|
142 | get :copy | |
143 | assert_response :success |
|
143 | assert_response :success | |
144 | assert_template 'copy' |
|
144 | assert_template 'copy' | |
|
145 | assert_select 'select[name=source_tracker_id]' do | |||
|
146 | assert_select 'option[value=1]', :text => 'Bug' | |||
|
147 | end | |||
|
148 | assert_select 'select[name=source_role_id]' do | |||
|
149 | assert_select 'option[value=2]', :text => 'Developer' | |||
|
150 | end | |||
|
151 | assert_select 'select[name=?]', 'target_tracker_ids[]' do | |||
|
152 | assert_select 'option[value=3]', :text => 'Support request' | |||
|
153 | end | |||
|
154 | assert_select 'select[name=?]', 'target_role_ids[]' do | |||
|
155 | assert_select 'option[value=1]', :text => 'Manager' | |||
|
156 | end | |||
145 | end |
|
157 | end | |
146 |
|
158 | |||
147 | def test_post_copy_one_to_one |
|
159 | def test_post_copy_one_to_one | |
148 | source_transitions = status_transitions(:tracker_id => 1, :role_id => 2) |
|
160 | source_transitions = status_transitions(:tracker_id => 1, :role_id => 2) | |
149 |
|
161 | |||
150 | post :copy, :source_tracker_id => '1', :source_role_id => '2', |
|
162 | post :copy, :source_tracker_id => '1', :source_role_id => '2', | |
151 | :target_tracker_ids => ['3'], :target_role_ids => ['1'] |
|
163 | :target_tracker_ids => ['3'], :target_role_ids => ['1'] | |
152 | assert_response 302 |
|
164 | assert_response 302 | |
153 | assert_equal source_transitions, status_transitions(:tracker_id => 3, :role_id => 1) |
|
165 | assert_equal source_transitions, status_transitions(:tracker_id => 3, :role_id => 1) | |
154 | end |
|
166 | end | |
155 |
|
167 | |||
156 | def test_post_copy_one_to_many |
|
168 | def test_post_copy_one_to_many | |
157 | source_transitions = status_transitions(:tracker_id => 1, :role_id => 2) |
|
169 | source_transitions = status_transitions(:tracker_id => 1, :role_id => 2) | |
158 |
|
170 | |||
159 | post :copy, :source_tracker_id => '1', :source_role_id => '2', |
|
171 | post :copy, :source_tracker_id => '1', :source_role_id => '2', | |
160 | :target_tracker_ids => ['2', '3'], :target_role_ids => ['1', '3'] |
|
172 | :target_tracker_ids => ['2', '3'], :target_role_ids => ['1', '3'] | |
161 | assert_response 302 |
|
173 | assert_response 302 | |
162 | assert_equal source_transitions, status_transitions(:tracker_id => 2, :role_id => 1) |
|
174 | assert_equal source_transitions, status_transitions(:tracker_id => 2, :role_id => 1) | |
163 | assert_equal source_transitions, status_transitions(:tracker_id => 3, :role_id => 1) |
|
175 | assert_equal source_transitions, status_transitions(:tracker_id => 3, :role_id => 1) | |
164 | assert_equal source_transitions, status_transitions(:tracker_id => 2, :role_id => 3) |
|
176 | assert_equal source_transitions, status_transitions(:tracker_id => 2, :role_id => 3) | |
165 | assert_equal source_transitions, status_transitions(:tracker_id => 3, :role_id => 3) |
|
177 | assert_equal source_transitions, status_transitions(:tracker_id => 3, :role_id => 3) | |
166 | end |
|
178 | end | |
167 |
|
179 | |||
168 | def test_post_copy_many_to_many |
|
180 | def test_post_copy_many_to_many | |
169 | source_t2 = status_transitions(:tracker_id => 2, :role_id => 2) |
|
181 | source_t2 = status_transitions(:tracker_id => 2, :role_id => 2) | |
170 | source_t3 = status_transitions(:tracker_id => 3, :role_id => 2) |
|
182 | source_t3 = status_transitions(:tracker_id => 3, :role_id => 2) | |
171 |
|
183 | |||
172 | post :copy, :source_tracker_id => 'any', :source_role_id => '2', |
|
184 | post :copy, :source_tracker_id => 'any', :source_role_id => '2', | |
173 | :target_tracker_ids => ['2', '3'], :target_role_ids => ['1', '3'] |
|
185 | :target_tracker_ids => ['2', '3'], :target_role_ids => ['1', '3'] | |
174 | assert_response 302 |
|
186 | assert_response 302 | |
175 | assert_equal source_t2, status_transitions(:tracker_id => 2, :role_id => 1) |
|
187 | assert_equal source_t2, status_transitions(:tracker_id => 2, :role_id => 1) | |
176 | assert_equal source_t3, status_transitions(:tracker_id => 3, :role_id => 1) |
|
188 | assert_equal source_t3, status_transitions(:tracker_id => 3, :role_id => 1) | |
177 | assert_equal source_t2, status_transitions(:tracker_id => 2, :role_id => 3) |
|
189 | assert_equal source_t2, status_transitions(:tracker_id => 2, :role_id => 3) | |
178 | assert_equal source_t3, status_transitions(:tracker_id => 3, :role_id => 3) |
|
190 | assert_equal source_t3, status_transitions(:tracker_id => 3, :role_id => 3) | |
179 | end |
|
191 | end | |
180 |
|
192 | |||
181 | # Returns an array of status transitions that can be compared |
|
193 | # Returns an array of status transitions that can be compared | |
182 | def status_transitions(conditions) |
|
194 | def status_transitions(conditions) | |
183 | Workflow.find(:all, :conditions => conditions, |
|
195 | Workflow.find(:all, :conditions => conditions, | |
184 | :order => 'tracker_id, role_id, old_status_id, new_status_id').collect {|w| [w.old_status, w.new_status_id]} |
|
196 | :order => 'tracker_id, role_id, old_status_id, new_status_id').collect {|w| [w.old_status, w.new_status_id]} | |
185 | end |
|
197 | end | |
186 | end |
|
198 | end |
General Comments 0
You need to be logged in to leave comments.
Login now