Mercurial > hg > soundsoftware-site
comparison test/functional/.svn/text-base/workflows_controller_test.rb.svn-base @ 0:513646585e45
* Import Redmine trunk SVN rev 3859
author | Chris Cannam |
---|---|
date | Fri, 23 Jul 2010 15:52:44 +0100 |
parents | |
children | af80e5618e9b |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:513646585e45 |
---|---|
1 # Redmine - project management software | |
2 # Copyright (C) 2006-2008 Jean-Philippe Lang | |
3 # | |
4 # This program is free software; you can redistribute it and/or | |
5 # modify it under the terms of the GNU General Public License | |
6 # as published by the Free Software Foundation; either version 2 | |
7 # of the License, or (at your option) any later version. | |
8 # | |
9 # This program is distributed in the hope that it will be useful, | |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 # GNU General Public License for more details. | |
13 # | |
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 | |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 | |
18 require File.dirname(__FILE__) + '/../test_helper' | |
19 require 'workflows_controller' | |
20 | |
21 # Re-raise errors caught by the controller. | |
22 class WorkflowsController; def rescue_action(e) raise e end; end | |
23 | |
24 class WorkflowsControllerTest < ActionController::TestCase | |
25 fixtures :roles, :trackers, :workflows, :users, :issue_statuses | |
26 | |
27 def setup | |
28 @controller = WorkflowsController.new | |
29 @request = ActionController::TestRequest.new | |
30 @response = ActionController::TestResponse.new | |
31 User.current = nil | |
32 @request.session[:user_id] = 1 # admin | |
33 end | |
34 | |
35 def test_index | |
36 get :index | |
37 assert_response :success | |
38 assert_template 'index' | |
39 | |
40 count = Workflow.count(:all, :conditions => 'role_id = 1 AND tracker_id = 2') | |
41 assert_tag :tag => 'a', :content => count.to_s, | |
42 :attributes => { :href => '/workflows/edit?role_id=1&tracker_id=2' } | |
43 end | |
44 | |
45 def test_get_edit | |
46 get :edit | |
47 assert_response :success | |
48 assert_template 'edit' | |
49 assert_not_nil assigns(:roles) | |
50 assert_not_nil assigns(:trackers) | |
51 end | |
52 | |
53 def test_get_edit_with_role_and_tracker | |
54 Workflow.delete_all | |
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) | |
57 | |
58 get :edit, :role_id => 2, :tracker_id => 1 | |
59 assert_response :success | |
60 assert_template 'edit' | |
61 | |
62 # used status only | |
63 assert_not_nil assigns(:statuses) | |
64 assert_equal [2, 3, 5], assigns(:statuses).collect(&:id) | |
65 | |
66 # allowed transitions | |
67 assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
68 :name => 'issue_status[3][]', | |
69 :value => '5', | |
70 :checked => 'checked' } | |
71 # not allowed | |
72 assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
73 :name => 'issue_status[3][]', | |
74 :value => '2', | |
75 :checked => nil } | |
76 # unused | |
77 assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
78 :name => 'issue_status[4][]' } | |
79 end | |
80 | |
81 def test_get_edit_with_role_and_tracker_and_all_statuses | |
82 Workflow.delete_all | |
83 | |
84 get :edit, :role_id => 2, :tracker_id => 1, :used_statuses_only => '0' | |
85 assert_response :success | |
86 assert_template 'edit' | |
87 | |
88 assert_not_nil assigns(:statuses) | |
89 assert_equal IssueStatus.count, assigns(:statuses).size | |
90 | |
91 assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
92 :name => 'issue_status[1][]', | |
93 :value => '1', | |
94 :checked => nil } | |
95 end | |
96 | |
97 def test_post_edit | |
98 post :edit, :role_id => 2, :tracker_id => 1, :issue_status => {'4' => ['5'], '3' => ['1', '2']} | |
99 assert_redirected_to '/workflows/edit?role_id=2&tracker_id=1' | |
100 | |
101 assert_equal 3, Workflow.count(:conditions => {:tracker_id => 1, :role_id => 2}) | |
102 assert_not_nil Workflow.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 2}) | |
103 assert_nil Workflow.find(:first, :conditions => {:role_id => 2, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4}) | |
104 end | |
105 | |
106 def test_clear_workflow | |
107 assert Workflow.count(:conditions => {:tracker_id => 1, :role_id => 2}) > 0 | |
108 | |
109 post :edit, :role_id => 2, :tracker_id => 1 | |
110 assert_equal 0, Workflow.count(:conditions => {:tracker_id => 1, :role_id => 2}) | |
111 end | |
112 | |
113 def test_get_copy | |
114 get :copy | |
115 assert_response :success | |
116 assert_template 'copy' | |
117 end | |
118 | |
119 def test_post_copy_one_to_one | |
120 source_transitions = status_transitions(:tracker_id => 1, :role_id => 2) | |
121 | |
122 post :copy, :source_tracker_id => '1', :source_role_id => '2', | |
123 :target_tracker_ids => ['3'], :target_role_ids => ['1'] | |
124 assert_response 302 | |
125 assert_equal source_transitions, status_transitions(:tracker_id => 3, :role_id => 1) | |
126 end | |
127 | |
128 def test_post_copy_one_to_many | |
129 source_transitions = status_transitions(:tracker_id => 1, :role_id => 2) | |
130 | |
131 post :copy, :source_tracker_id => '1', :source_role_id => '2', | |
132 :target_tracker_ids => ['2', '3'], :target_role_ids => ['1', '3'] | |
133 assert_response 302 | |
134 assert_equal source_transitions, status_transitions(:tracker_id => 2, :role_id => 1) | |
135 assert_equal source_transitions, status_transitions(:tracker_id => 3, :role_id => 1) | |
136 assert_equal source_transitions, status_transitions(:tracker_id => 2, :role_id => 3) | |
137 assert_equal source_transitions, status_transitions(:tracker_id => 3, :role_id => 3) | |
138 end | |
139 | |
140 def test_post_copy_many_to_many | |
141 source_t2 = status_transitions(:tracker_id => 2, :role_id => 2) | |
142 source_t3 = status_transitions(:tracker_id => 3, :role_id => 2) | |
143 | |
144 post :copy, :source_tracker_id => 'any', :source_role_id => '2', | |
145 :target_tracker_ids => ['2', '3'], :target_role_ids => ['1', '3'] | |
146 assert_response 302 | |
147 assert_equal source_t2, status_transitions(:tracker_id => 2, :role_id => 1) | |
148 assert_equal source_t3, status_transitions(:tracker_id => 3, :role_id => 1) | |
149 assert_equal source_t2, status_transitions(:tracker_id => 2, :role_id => 3) | |
150 assert_equal source_t3, status_transitions(:tracker_id => 3, :role_id => 3) | |
151 end | |
152 | |
153 # Returns an array of status transitions that can be compared | |
154 def status_transitions(conditions) | |
155 Workflow.find(:all, :conditions => conditions, | |
156 :order => 'tracker_id, role_id, old_status_id, new_status_id').collect {|w| [w.old_status, w.new_status_id]} | |
157 end | |
158 end |