@@ -1,1153 +1,1158 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2008 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2008 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.dirname(__FILE__) + '/../test_helper' |
|
18 | require File.dirname(__FILE__) + '/../test_helper' | |
19 | require 'issues_controller' |
|
19 | require 'issues_controller' | |
20 |
|
20 | |||
21 | # Re-raise errors caught by the controller. |
|
21 | # Re-raise errors caught by the controller. | |
22 | class IssuesController; def rescue_action(e) raise e end; end |
|
22 | class IssuesController; def rescue_action(e) raise e end; end | |
23 |
|
23 | |||
24 | class IssuesControllerTest < ActionController::TestCase |
|
24 | class IssuesControllerTest < ActionController::TestCase | |
25 | fixtures :projects, |
|
25 | fixtures :projects, | |
26 | :users, |
|
26 | :users, | |
27 | :roles, |
|
27 | :roles, | |
28 | :members, |
|
28 | :members, | |
29 | :member_roles, |
|
29 | :member_roles, | |
30 | :issues, |
|
30 | :issues, | |
31 | :issue_statuses, |
|
31 | :issue_statuses, | |
32 | :versions, |
|
32 | :versions, | |
33 | :trackers, |
|
33 | :trackers, | |
34 | :projects_trackers, |
|
34 | :projects_trackers, | |
35 | :issue_categories, |
|
35 | :issue_categories, | |
36 | :enabled_modules, |
|
36 | :enabled_modules, | |
37 | :enumerations, |
|
37 | :enumerations, | |
38 | :attachments, |
|
38 | :attachments, | |
39 | :workflows, |
|
39 | :workflows, | |
40 | :custom_fields, |
|
40 | :custom_fields, | |
41 | :custom_values, |
|
41 | :custom_values, | |
42 | :custom_fields_trackers, |
|
42 | :custom_fields_trackers, | |
43 | :time_entries, |
|
43 | :time_entries, | |
44 | :journals, |
|
44 | :journals, | |
45 | :journal_details, |
|
45 | :journal_details, | |
46 | :queries |
|
46 | :queries | |
47 |
|
47 | |||
48 | def setup |
|
48 | def setup | |
49 | @controller = IssuesController.new |
|
49 | @controller = IssuesController.new | |
50 | @request = ActionController::TestRequest.new |
|
50 | @request = ActionController::TestRequest.new | |
51 | @response = ActionController::TestResponse.new |
|
51 | @response = ActionController::TestResponse.new | |
52 | User.current = nil |
|
52 | User.current = nil | |
53 | end |
|
53 | end | |
54 |
|
54 | |||
55 | def test_index_routing |
|
55 | def test_index_routing | |
56 | assert_routing( |
|
56 | assert_routing( | |
57 | {:method => :get, :path => '/issues'}, |
|
57 | {:method => :get, :path => '/issues'}, | |
58 | :controller => 'issues', :action => 'index' |
|
58 | :controller => 'issues', :action => 'index' | |
59 | ) |
|
59 | ) | |
60 | end |
|
60 | end | |
61 |
|
61 | |||
62 | def test_index |
|
62 | def test_index | |
63 | Setting.default_language = 'en' |
|
63 | Setting.default_language = 'en' | |
64 |
|
64 | |||
65 | get :index |
|
65 | get :index | |
66 | assert_response :success |
|
66 | assert_response :success | |
67 | assert_template 'index.rhtml' |
|
67 | assert_template 'index.rhtml' | |
68 | assert_not_nil assigns(:issues) |
|
68 | assert_not_nil assigns(:issues) | |
69 | assert_nil assigns(:project) |
|
69 | assert_nil assigns(:project) | |
70 | assert_tag :tag => 'a', :content => /Can't print recipes/ |
|
70 | assert_tag :tag => 'a', :content => /Can't print recipes/ | |
71 | assert_tag :tag => 'a', :content => /Subproject issue/ |
|
71 | assert_tag :tag => 'a', :content => /Subproject issue/ | |
72 | # private projects hidden |
|
72 | # private projects hidden | |
73 | assert_no_tag :tag => 'a', :content => /Issue of a private subproject/ |
|
73 | assert_no_tag :tag => 'a', :content => /Issue of a private subproject/ | |
74 | assert_no_tag :tag => 'a', :content => /Issue on project 2/ |
|
74 | assert_no_tag :tag => 'a', :content => /Issue on project 2/ | |
75 | # project column |
|
75 | # project column | |
76 | assert_tag :tag => 'th', :content => /Project/ |
|
76 | assert_tag :tag => 'th', :content => /Project/ | |
77 | end |
|
77 | end | |
78 |
|
78 | |||
79 | def test_index_should_not_list_issues_when_module_disabled |
|
79 | def test_index_should_not_list_issues_when_module_disabled | |
80 | EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1") |
|
80 | EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1") | |
81 | get :index |
|
81 | get :index | |
82 | assert_response :success |
|
82 | assert_response :success | |
83 | assert_template 'index.rhtml' |
|
83 | assert_template 'index.rhtml' | |
84 | assert_not_nil assigns(:issues) |
|
84 | assert_not_nil assigns(:issues) | |
85 | assert_nil assigns(:project) |
|
85 | assert_nil assigns(:project) | |
86 | assert_no_tag :tag => 'a', :content => /Can't print recipes/ |
|
86 | assert_no_tag :tag => 'a', :content => /Can't print recipes/ | |
87 | assert_tag :tag => 'a', :content => /Subproject issue/ |
|
87 | assert_tag :tag => 'a', :content => /Subproject issue/ | |
88 | end |
|
88 | end | |
89 |
|
89 | |||
90 | def test_index_with_project_routing |
|
90 | def test_index_with_project_routing | |
91 | assert_routing( |
|
91 | assert_routing( | |
92 | {:method => :get, :path => '/projects/23/issues'}, |
|
92 | {:method => :get, :path => '/projects/23/issues'}, | |
93 | :controller => 'issues', :action => 'index', :project_id => '23' |
|
93 | :controller => 'issues', :action => 'index', :project_id => '23' | |
94 | ) |
|
94 | ) | |
95 | end |
|
95 | end | |
96 |
|
96 | |||
97 | def test_index_should_not_list_issues_when_module_disabled |
|
97 | def test_index_should_not_list_issues_when_module_disabled | |
98 | EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1") |
|
98 | EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1") | |
99 | get :index |
|
99 | get :index | |
100 | assert_response :success |
|
100 | assert_response :success | |
101 | assert_template 'index.rhtml' |
|
101 | assert_template 'index.rhtml' | |
102 | assert_not_nil assigns(:issues) |
|
102 | assert_not_nil assigns(:issues) | |
103 | assert_nil assigns(:project) |
|
103 | assert_nil assigns(:project) | |
104 | assert_no_tag :tag => 'a', :content => /Can't print recipes/ |
|
104 | assert_no_tag :tag => 'a', :content => /Can't print recipes/ | |
105 | assert_tag :tag => 'a', :content => /Subproject issue/ |
|
105 | assert_tag :tag => 'a', :content => /Subproject issue/ | |
106 | end |
|
106 | end | |
107 |
|
107 | |||
108 | def test_index_with_project_routing |
|
108 | def test_index_with_project_routing | |
109 | assert_routing( |
|
109 | assert_routing( | |
110 | {:method => :get, :path => 'projects/23/issues'}, |
|
110 | {:method => :get, :path => 'projects/23/issues'}, | |
111 | :controller => 'issues', :action => 'index', :project_id => '23' |
|
111 | :controller => 'issues', :action => 'index', :project_id => '23' | |
112 | ) |
|
112 | ) | |
113 | end |
|
113 | end | |
114 |
|
114 | |||
115 | def test_index_with_project |
|
115 | def test_index_with_project | |
116 | Setting.display_subprojects_issues = 0 |
|
116 | Setting.display_subprojects_issues = 0 | |
117 | get :index, :project_id => 1 |
|
117 | get :index, :project_id => 1 | |
118 | assert_response :success |
|
118 | assert_response :success | |
119 | assert_template 'index.rhtml' |
|
119 | assert_template 'index.rhtml' | |
120 | assert_not_nil assigns(:issues) |
|
120 | assert_not_nil assigns(:issues) | |
121 | assert_tag :tag => 'a', :content => /Can't print recipes/ |
|
121 | assert_tag :tag => 'a', :content => /Can't print recipes/ | |
122 | assert_no_tag :tag => 'a', :content => /Subproject issue/ |
|
122 | assert_no_tag :tag => 'a', :content => /Subproject issue/ | |
123 | end |
|
123 | end | |
124 |
|
124 | |||
125 | def test_index_with_project_and_subprojects |
|
125 | def test_index_with_project_and_subprojects | |
126 | Setting.display_subprojects_issues = 1 |
|
126 | Setting.display_subprojects_issues = 1 | |
127 | get :index, :project_id => 1 |
|
127 | get :index, :project_id => 1 | |
128 | assert_response :success |
|
128 | assert_response :success | |
129 | assert_template 'index.rhtml' |
|
129 | assert_template 'index.rhtml' | |
130 | assert_not_nil assigns(:issues) |
|
130 | assert_not_nil assigns(:issues) | |
131 | assert_tag :tag => 'a', :content => /Can't print recipes/ |
|
131 | assert_tag :tag => 'a', :content => /Can't print recipes/ | |
132 | assert_tag :tag => 'a', :content => /Subproject issue/ |
|
132 | assert_tag :tag => 'a', :content => /Subproject issue/ | |
133 | assert_no_tag :tag => 'a', :content => /Issue of a private subproject/ |
|
133 | assert_no_tag :tag => 'a', :content => /Issue of a private subproject/ | |
134 | end |
|
134 | end | |
135 |
|
135 | |||
136 | def test_index_with_project_and_subprojects_should_show_private_subprojects |
|
136 | def test_index_with_project_and_subprojects_should_show_private_subprojects | |
137 | @request.session[:user_id] = 2 |
|
137 | @request.session[:user_id] = 2 | |
138 | Setting.display_subprojects_issues = 1 |
|
138 | Setting.display_subprojects_issues = 1 | |
139 | get :index, :project_id => 1 |
|
139 | get :index, :project_id => 1 | |
140 | assert_response :success |
|
140 | assert_response :success | |
141 | assert_template 'index.rhtml' |
|
141 | assert_template 'index.rhtml' | |
142 | assert_not_nil assigns(:issues) |
|
142 | assert_not_nil assigns(:issues) | |
143 | assert_tag :tag => 'a', :content => /Can't print recipes/ |
|
143 | assert_tag :tag => 'a', :content => /Can't print recipes/ | |
144 | assert_tag :tag => 'a', :content => /Subproject issue/ |
|
144 | assert_tag :tag => 'a', :content => /Subproject issue/ | |
145 | assert_tag :tag => 'a', :content => /Issue of a private subproject/ |
|
145 | assert_tag :tag => 'a', :content => /Issue of a private subproject/ | |
146 | end |
|
146 | end | |
147 |
|
147 | |||
148 | def test_index_with_project_routing_formatted |
|
148 | def test_index_with_project_routing_formatted | |
149 | assert_routing( |
|
149 | assert_routing( | |
150 | {:method => :get, :path => 'projects/23/issues.pdf'}, |
|
150 | {:method => :get, :path => 'projects/23/issues.pdf'}, | |
151 | :controller => 'issues', :action => 'index', :project_id => '23', :format => 'pdf' |
|
151 | :controller => 'issues', :action => 'index', :project_id => '23', :format => 'pdf' | |
152 | ) |
|
152 | ) | |
153 | assert_routing( |
|
153 | assert_routing( | |
154 | {:method => :get, :path => 'projects/23/issues.atom'}, |
|
154 | {:method => :get, :path => 'projects/23/issues.atom'}, | |
155 | :controller => 'issues', :action => 'index', :project_id => '23', :format => 'atom' |
|
155 | :controller => 'issues', :action => 'index', :project_id => '23', :format => 'atom' | |
156 | ) |
|
156 | ) | |
157 | end |
|
157 | end | |
158 |
|
158 | |||
159 | def test_index_with_project_and_filter |
|
159 | def test_index_with_project_and_filter | |
160 | get :index, :project_id => 1, :set_filter => 1 |
|
160 | get :index, :project_id => 1, :set_filter => 1 | |
161 | assert_response :success |
|
161 | assert_response :success | |
162 | assert_template 'index.rhtml' |
|
162 | assert_template 'index.rhtml' | |
163 | assert_not_nil assigns(:issues) |
|
163 | assert_not_nil assigns(:issues) | |
164 | end |
|
164 | end | |
165 |
|
165 | |||
166 | def test_index_with_query |
|
166 | def test_index_with_query | |
167 | get :index, :project_id => 1, :query_id => 5 |
|
167 | get :index, :project_id => 1, :query_id => 5 | |
168 | assert_response :success |
|
168 | assert_response :success | |
169 | assert_template 'index.rhtml' |
|
169 | assert_template 'index.rhtml' | |
170 | assert_not_nil assigns(:issues) |
|
170 | assert_not_nil assigns(:issues) | |
171 | assert_nil assigns(:issue_count_by_group) |
|
171 | assert_nil assigns(:issue_count_by_group) | |
172 | end |
|
172 | end | |
173 |
|
173 | |||
174 | def test_index_with_query_grouped_by_tracker |
|
174 | def test_index_with_query_grouped_by_tracker | |
175 | get :index, :project_id => 1, :query_id => 6 |
|
175 | get :index, :project_id => 1, :query_id => 6 | |
176 | assert_response :success |
|
176 | assert_response :success | |
177 | assert_template 'index.rhtml' |
|
177 | assert_template 'index.rhtml' | |
178 | assert_not_nil assigns(:issues) |
|
178 | assert_not_nil assigns(:issues) | |
179 | count_by_group = assigns(:issue_count_by_group) |
|
179 | count_by_group = assigns(:issue_count_by_group) | |
180 | assert_kind_of Hash, count_by_group |
|
180 | assert_kind_of Hash, count_by_group | |
181 | assert_kind_of Tracker, count_by_group.keys.first |
|
181 | assert_kind_of Tracker, count_by_group.keys.first | |
182 | assert_not_nil count_by_group[Tracker.find(1)] |
|
182 | assert_not_nil count_by_group[Tracker.find(1)] | |
183 | end |
|
183 | end | |
184 |
|
184 | |||
185 | def test_index_with_query_grouped_by_list_custom_field |
|
185 | def test_index_with_query_grouped_by_list_custom_field | |
186 | get :index, :project_id => 1, :query_id => 9 |
|
186 | get :index, :project_id => 1, :query_id => 9 | |
187 | assert_response :success |
|
187 | assert_response :success | |
188 | assert_template 'index.rhtml' |
|
188 | assert_template 'index.rhtml' | |
189 | assert_not_nil assigns(:issues) |
|
189 | assert_not_nil assigns(:issues) | |
190 | count_by_group = assigns(:issue_count_by_group) |
|
190 | count_by_group = assigns(:issue_count_by_group) | |
191 | assert_kind_of Hash, count_by_group |
|
191 | assert_kind_of Hash, count_by_group | |
192 | assert_kind_of String, count_by_group.keys.first |
|
192 | assert_kind_of String, count_by_group.keys.first | |
193 | assert_not_nil count_by_group['MySQL'] |
|
193 | assert_not_nil count_by_group['MySQL'] | |
194 | end |
|
194 | end | |
195 |
|
195 | |||
|
196 | def test_index_sort_by_field_not_included_in_columns | |||
|
197 | Setting.issue_list_default_columns = %w(subject author) | |||
|
198 | get :index, :sort => 'tracker' | |||
|
199 | end | |||
|
200 | ||||
196 | def test_index_csv_with_project |
|
201 | def test_index_csv_with_project | |
197 | Setting.default_language = 'en' |
|
202 | Setting.default_language = 'en' | |
198 |
|
203 | |||
199 | get :index, :format => 'csv' |
|
204 | get :index, :format => 'csv' | |
200 | assert_response :success |
|
205 | assert_response :success | |
201 | assert_not_nil assigns(:issues) |
|
206 | assert_not_nil assigns(:issues) | |
202 | assert_equal 'text/csv', @response.content_type |
|
207 | assert_equal 'text/csv', @response.content_type | |
203 | assert @response.body.starts_with?("#,") |
|
208 | assert @response.body.starts_with?("#,") | |
204 |
|
209 | |||
205 | get :index, :project_id => 1, :format => 'csv' |
|
210 | get :index, :project_id => 1, :format => 'csv' | |
206 | assert_response :success |
|
211 | assert_response :success | |
207 | assert_not_nil assigns(:issues) |
|
212 | assert_not_nil assigns(:issues) | |
208 | assert_equal 'text/csv', @response.content_type |
|
213 | assert_equal 'text/csv', @response.content_type | |
209 | end |
|
214 | end | |
210 |
|
215 | |||
211 | def test_index_formatted |
|
216 | def test_index_formatted | |
212 | assert_routing( |
|
217 | assert_routing( | |
213 | {:method => :get, :path => 'issues.pdf'}, |
|
218 | {:method => :get, :path => 'issues.pdf'}, | |
214 | :controller => 'issues', :action => 'index', :format => 'pdf' |
|
219 | :controller => 'issues', :action => 'index', :format => 'pdf' | |
215 | ) |
|
220 | ) | |
216 | assert_routing( |
|
221 | assert_routing( | |
217 | {:method => :get, :path => 'issues.atom'}, |
|
222 | {:method => :get, :path => 'issues.atom'}, | |
218 | :controller => 'issues', :action => 'index', :format => 'atom' |
|
223 | :controller => 'issues', :action => 'index', :format => 'atom' | |
219 | ) |
|
224 | ) | |
220 | end |
|
225 | end | |
221 |
|
226 | |||
222 | def test_index_pdf |
|
227 | def test_index_pdf | |
223 | get :index, :format => 'pdf' |
|
228 | get :index, :format => 'pdf' | |
224 | assert_response :success |
|
229 | assert_response :success | |
225 | assert_not_nil assigns(:issues) |
|
230 | assert_not_nil assigns(:issues) | |
226 | assert_equal 'application/pdf', @response.content_type |
|
231 | assert_equal 'application/pdf', @response.content_type | |
227 |
|
232 | |||
228 | get :index, :project_id => 1, :format => 'pdf' |
|
233 | get :index, :project_id => 1, :format => 'pdf' | |
229 | assert_response :success |
|
234 | assert_response :success | |
230 | assert_not_nil assigns(:issues) |
|
235 | assert_not_nil assigns(:issues) | |
231 | assert_equal 'application/pdf', @response.content_type |
|
236 | assert_equal 'application/pdf', @response.content_type | |
232 |
|
237 | |||
233 | get :index, :project_id => 1, :query_id => 6, :format => 'pdf' |
|
238 | get :index, :project_id => 1, :query_id => 6, :format => 'pdf' | |
234 | assert_response :success |
|
239 | assert_response :success | |
235 | assert_not_nil assigns(:issues) |
|
240 | assert_not_nil assigns(:issues) | |
236 | assert_equal 'application/pdf', @response.content_type |
|
241 | assert_equal 'application/pdf', @response.content_type | |
237 | end |
|
242 | end | |
238 |
|
243 | |||
239 | def test_index_sort |
|
244 | def test_index_sort | |
240 | get :index, :sort => 'tracker,id:desc' |
|
245 | get :index, :sort => 'tracker,id:desc' | |
241 | assert_response :success |
|
246 | assert_response :success | |
242 |
|
247 | |||
243 | sort_params = @request.session['issues_index_sort'] |
|
248 | sort_params = @request.session['issues_index_sort'] | |
244 | assert sort_params.is_a?(String) |
|
249 | assert sort_params.is_a?(String) | |
245 | assert_equal 'tracker,id:desc', sort_params |
|
250 | assert_equal 'tracker,id:desc', sort_params | |
246 |
|
251 | |||
247 | issues = assigns(:issues) |
|
252 | issues = assigns(:issues) | |
248 | assert_not_nil issues |
|
253 | assert_not_nil issues | |
249 | assert !issues.empty? |
|
254 | assert !issues.empty? | |
250 | assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id) |
|
255 | assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id) | |
251 | end |
|
256 | end | |
252 |
|
257 | |||
253 | def test_gantt |
|
258 | def test_gantt | |
254 | get :gantt, :project_id => 1 |
|
259 | get :gantt, :project_id => 1 | |
255 | assert_response :success |
|
260 | assert_response :success | |
256 | assert_template 'gantt.rhtml' |
|
261 | assert_template 'gantt.rhtml' | |
257 | assert_not_nil assigns(:gantt) |
|
262 | assert_not_nil assigns(:gantt) | |
258 | events = assigns(:gantt).events |
|
263 | events = assigns(:gantt).events | |
259 | assert_not_nil events |
|
264 | assert_not_nil events | |
260 | # Issue with start and due dates |
|
265 | # Issue with start and due dates | |
261 | i = Issue.find(1) |
|
266 | i = Issue.find(1) | |
262 | assert_not_nil i.due_date |
|
267 | assert_not_nil i.due_date | |
263 | assert events.include?(Issue.find(1)) |
|
268 | assert events.include?(Issue.find(1)) | |
264 | # Issue with without due date but targeted to a version with date |
|
269 | # Issue with without due date but targeted to a version with date | |
265 | i = Issue.find(2) |
|
270 | i = Issue.find(2) | |
266 | assert_nil i.due_date |
|
271 | assert_nil i.due_date | |
267 | assert events.include?(i) |
|
272 | assert events.include?(i) | |
268 | end |
|
273 | end | |
269 |
|
274 | |||
270 | def test_cross_project_gantt |
|
275 | def test_cross_project_gantt | |
271 | get :gantt |
|
276 | get :gantt | |
272 | assert_response :success |
|
277 | assert_response :success | |
273 | assert_template 'gantt.rhtml' |
|
278 | assert_template 'gantt.rhtml' | |
274 | assert_not_nil assigns(:gantt) |
|
279 | assert_not_nil assigns(:gantt) | |
275 | events = assigns(:gantt).events |
|
280 | events = assigns(:gantt).events | |
276 | assert_not_nil events |
|
281 | assert_not_nil events | |
277 | end |
|
282 | end | |
278 |
|
283 | |||
279 | def test_gantt_export_to_pdf |
|
284 | def test_gantt_export_to_pdf | |
280 | get :gantt, :project_id => 1, :format => 'pdf' |
|
285 | get :gantt, :project_id => 1, :format => 'pdf' | |
281 | assert_response :success |
|
286 | assert_response :success | |
282 | assert_equal 'application/pdf', @response.content_type |
|
287 | assert_equal 'application/pdf', @response.content_type | |
283 | assert @response.body.starts_with?('%PDF') |
|
288 | assert @response.body.starts_with?('%PDF') | |
284 | assert_not_nil assigns(:gantt) |
|
289 | assert_not_nil assigns(:gantt) | |
285 | end |
|
290 | end | |
286 |
|
291 | |||
287 | def test_cross_project_gantt_export_to_pdf |
|
292 | def test_cross_project_gantt_export_to_pdf | |
288 | get :gantt, :format => 'pdf' |
|
293 | get :gantt, :format => 'pdf' | |
289 | assert_response :success |
|
294 | assert_response :success | |
290 | assert_equal 'application/pdf', @response.content_type |
|
295 | assert_equal 'application/pdf', @response.content_type | |
291 | assert @response.body.starts_with?('%PDF') |
|
296 | assert @response.body.starts_with?('%PDF') | |
292 | assert_not_nil assigns(:gantt) |
|
297 | assert_not_nil assigns(:gantt) | |
293 | end |
|
298 | end | |
294 |
|
299 | |||
295 | if Object.const_defined?(:Magick) |
|
300 | if Object.const_defined?(:Magick) | |
296 | def test_gantt_image |
|
301 | def test_gantt_image | |
297 | get :gantt, :project_id => 1, :format => 'png' |
|
302 | get :gantt, :project_id => 1, :format => 'png' | |
298 | assert_response :success |
|
303 | assert_response :success | |
299 | assert_equal 'image/png', @response.content_type |
|
304 | assert_equal 'image/png', @response.content_type | |
300 | end |
|
305 | end | |
301 | else |
|
306 | else | |
302 | puts "RMagick not installed. Skipping tests !!!" |
|
307 | puts "RMagick not installed. Skipping tests !!!" | |
303 | end |
|
308 | end | |
304 |
|
309 | |||
305 | def test_calendar |
|
310 | def test_calendar | |
306 | get :calendar, :project_id => 1 |
|
311 | get :calendar, :project_id => 1 | |
307 | assert_response :success |
|
312 | assert_response :success | |
308 | assert_template 'calendar' |
|
313 | assert_template 'calendar' | |
309 | assert_not_nil assigns(:calendar) |
|
314 | assert_not_nil assigns(:calendar) | |
310 | end |
|
315 | end | |
311 |
|
316 | |||
312 | def test_cross_project_calendar |
|
317 | def test_cross_project_calendar | |
313 | get :calendar |
|
318 | get :calendar | |
314 | assert_response :success |
|
319 | assert_response :success | |
315 | assert_template 'calendar' |
|
320 | assert_template 'calendar' | |
316 | assert_not_nil assigns(:calendar) |
|
321 | assert_not_nil assigns(:calendar) | |
317 | end |
|
322 | end | |
318 |
|
323 | |||
319 | def test_changes |
|
324 | def test_changes | |
320 | get :changes, :project_id => 1 |
|
325 | get :changes, :project_id => 1 | |
321 | assert_response :success |
|
326 | assert_response :success | |
322 | assert_not_nil assigns(:journals) |
|
327 | assert_not_nil assigns(:journals) | |
323 | assert_equal 'application/atom+xml', @response.content_type |
|
328 | assert_equal 'application/atom+xml', @response.content_type | |
324 | end |
|
329 | end | |
325 |
|
330 | |||
326 | def test_show_routing |
|
331 | def test_show_routing | |
327 | assert_routing( |
|
332 | assert_routing( | |
328 | {:method => :get, :path => '/issues/64'}, |
|
333 | {:method => :get, :path => '/issues/64'}, | |
329 | :controller => 'issues', :action => 'show', :id => '64' |
|
334 | :controller => 'issues', :action => 'show', :id => '64' | |
330 | ) |
|
335 | ) | |
331 | end |
|
336 | end | |
332 |
|
337 | |||
333 | def test_show_routing_formatted |
|
338 | def test_show_routing_formatted | |
334 | assert_routing( |
|
339 | assert_routing( | |
335 | {:method => :get, :path => '/issues/2332.pdf'}, |
|
340 | {:method => :get, :path => '/issues/2332.pdf'}, | |
336 | :controller => 'issues', :action => 'show', :id => '2332', :format => 'pdf' |
|
341 | :controller => 'issues', :action => 'show', :id => '2332', :format => 'pdf' | |
337 | ) |
|
342 | ) | |
338 | assert_routing( |
|
343 | assert_routing( | |
339 | {:method => :get, :path => '/issues/23123.atom'}, |
|
344 | {:method => :get, :path => '/issues/23123.atom'}, | |
340 | :controller => 'issues', :action => 'show', :id => '23123', :format => 'atom' |
|
345 | :controller => 'issues', :action => 'show', :id => '23123', :format => 'atom' | |
341 | ) |
|
346 | ) | |
342 | end |
|
347 | end | |
343 |
|
348 | |||
344 | def test_show_by_anonymous |
|
349 | def test_show_by_anonymous | |
345 | get :show, :id => 1 |
|
350 | get :show, :id => 1 | |
346 | assert_response :success |
|
351 | assert_response :success | |
347 | assert_template 'show.rhtml' |
|
352 | assert_template 'show.rhtml' | |
348 | assert_not_nil assigns(:issue) |
|
353 | assert_not_nil assigns(:issue) | |
349 | assert_equal Issue.find(1), assigns(:issue) |
|
354 | assert_equal Issue.find(1), assigns(:issue) | |
350 |
|
355 | |||
351 | # anonymous role is allowed to add a note |
|
356 | # anonymous role is allowed to add a note | |
352 | assert_tag :tag => 'form', |
|
357 | assert_tag :tag => 'form', | |
353 | :descendant => { :tag => 'fieldset', |
|
358 | :descendant => { :tag => 'fieldset', | |
354 | :child => { :tag => 'legend', |
|
359 | :child => { :tag => 'legend', | |
355 | :content => /Notes/ } } |
|
360 | :content => /Notes/ } } | |
356 | end |
|
361 | end | |
357 |
|
362 | |||
358 | def test_show_by_manager |
|
363 | def test_show_by_manager | |
359 | @request.session[:user_id] = 2 |
|
364 | @request.session[:user_id] = 2 | |
360 | get :show, :id => 1 |
|
365 | get :show, :id => 1 | |
361 | assert_response :success |
|
366 | assert_response :success | |
362 |
|
367 | |||
363 | assert_tag :tag => 'form', |
|
368 | assert_tag :tag => 'form', | |
364 | :descendant => { :tag => 'fieldset', |
|
369 | :descendant => { :tag => 'fieldset', | |
365 | :child => { :tag => 'legend', |
|
370 | :child => { :tag => 'legend', | |
366 | :content => /Change properties/ } }, |
|
371 | :content => /Change properties/ } }, | |
367 | :descendant => { :tag => 'fieldset', |
|
372 | :descendant => { :tag => 'fieldset', | |
368 | :child => { :tag => 'legend', |
|
373 | :child => { :tag => 'legend', | |
369 | :content => /Log time/ } }, |
|
374 | :content => /Log time/ } }, | |
370 | :descendant => { :tag => 'fieldset', |
|
375 | :descendant => { :tag => 'fieldset', | |
371 | :child => { :tag => 'legend', |
|
376 | :child => { :tag => 'legend', | |
372 | :content => /Notes/ } } |
|
377 | :content => /Notes/ } } | |
373 | end |
|
378 | end | |
374 |
|
379 | |||
375 | def test_show_should_deny_anonymous_access_without_permission |
|
380 | def test_show_should_deny_anonymous_access_without_permission | |
376 | Role.anonymous.remove_permission!(:view_issues) |
|
381 | Role.anonymous.remove_permission!(:view_issues) | |
377 | get :show, :id => 1 |
|
382 | get :show, :id => 1 | |
378 | assert_response :redirect |
|
383 | assert_response :redirect | |
379 | end |
|
384 | end | |
380 |
|
385 | |||
381 | def test_show_should_deny_non_member_access_without_permission |
|
386 | def test_show_should_deny_non_member_access_without_permission | |
382 | Role.non_member.remove_permission!(:view_issues) |
|
387 | Role.non_member.remove_permission!(:view_issues) | |
383 | @request.session[:user_id] = 9 |
|
388 | @request.session[:user_id] = 9 | |
384 | get :show, :id => 1 |
|
389 | get :show, :id => 1 | |
385 | assert_response 403 |
|
390 | assert_response 403 | |
386 | end |
|
391 | end | |
387 |
|
392 | |||
388 | def test_show_should_deny_member_access_without_permission |
|
393 | def test_show_should_deny_member_access_without_permission | |
389 | Role.find(1).remove_permission!(:view_issues) |
|
394 | Role.find(1).remove_permission!(:view_issues) | |
390 | @request.session[:user_id] = 2 |
|
395 | @request.session[:user_id] = 2 | |
391 | get :show, :id => 1 |
|
396 | get :show, :id => 1 | |
392 | assert_response 403 |
|
397 | assert_response 403 | |
393 | end |
|
398 | end | |
394 |
|
399 | |||
395 | def test_show_should_not_disclose_relations_to_invisible_issues |
|
400 | def test_show_should_not_disclose_relations_to_invisible_issues | |
396 | Setting.cross_project_issue_relations = '1' |
|
401 | Setting.cross_project_issue_relations = '1' | |
397 | IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates') |
|
402 | IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates') | |
398 | # Relation to a private project issue |
|
403 | # Relation to a private project issue | |
399 | IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates') |
|
404 | IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates') | |
400 |
|
405 | |||
401 | get :show, :id => 1 |
|
406 | get :show, :id => 1 | |
402 | assert_response :success |
|
407 | assert_response :success | |
403 |
|
408 | |||
404 | assert_tag :div, :attributes => { :id => 'relations' }, |
|
409 | assert_tag :div, :attributes => { :id => 'relations' }, | |
405 | :descendant => { :tag => 'a', :content => /#2$/ } |
|
410 | :descendant => { :tag => 'a', :content => /#2$/ } | |
406 | assert_no_tag :div, :attributes => { :id => 'relations' }, |
|
411 | assert_no_tag :div, :attributes => { :id => 'relations' }, | |
407 | :descendant => { :tag => 'a', :content => /#4$/ } |
|
412 | :descendant => { :tag => 'a', :content => /#4$/ } | |
408 | end |
|
413 | end | |
409 |
|
414 | |||
410 | def test_show_atom |
|
415 | def test_show_atom | |
411 | get :show, :id => 2, :format => 'atom' |
|
416 | get :show, :id => 2, :format => 'atom' | |
412 | assert_response :success |
|
417 | assert_response :success | |
413 | assert_template 'changes.rxml' |
|
418 | assert_template 'changes.rxml' | |
414 | # Inline image |
|
419 | # Inline image | |
415 | assert @response.body.include?("<img src=\"http://test.host/attachments/download/10\" alt=\"\" />"), "Body did not match. Body: #{@response.body}" |
|
420 | assert @response.body.include?("<img src=\"http://test.host/attachments/download/10\" alt=\"\" />"), "Body did not match. Body: #{@response.body}" | |
416 | end |
|
421 | end | |
417 |
|
422 | |||
418 | def test_new_routing |
|
423 | def test_new_routing | |
419 | assert_routing( |
|
424 | assert_routing( | |
420 | {:method => :get, :path => '/projects/1/issues/new'}, |
|
425 | {:method => :get, :path => '/projects/1/issues/new'}, | |
421 | :controller => 'issues', :action => 'new', :project_id => '1' |
|
426 | :controller => 'issues', :action => 'new', :project_id => '1' | |
422 | ) |
|
427 | ) | |
423 | assert_recognizes( |
|
428 | assert_recognizes( | |
424 | {:controller => 'issues', :action => 'new', :project_id => '1'}, |
|
429 | {:controller => 'issues', :action => 'new', :project_id => '1'}, | |
425 | {:method => :post, :path => '/projects/1/issues'} |
|
430 | {:method => :post, :path => '/projects/1/issues'} | |
426 | ) |
|
431 | ) | |
427 | end |
|
432 | end | |
428 |
|
433 | |||
429 | def test_show_export_to_pdf |
|
434 | def test_show_export_to_pdf | |
430 | get :show, :id => 3, :format => 'pdf' |
|
435 | get :show, :id => 3, :format => 'pdf' | |
431 | assert_response :success |
|
436 | assert_response :success | |
432 | assert_equal 'application/pdf', @response.content_type |
|
437 | assert_equal 'application/pdf', @response.content_type | |
433 | assert @response.body.starts_with?('%PDF') |
|
438 | assert @response.body.starts_with?('%PDF') | |
434 | assert_not_nil assigns(:issue) |
|
439 | assert_not_nil assigns(:issue) | |
435 | end |
|
440 | end | |
436 |
|
441 | |||
437 | def test_get_new |
|
442 | def test_get_new | |
438 | @request.session[:user_id] = 2 |
|
443 | @request.session[:user_id] = 2 | |
439 | get :new, :project_id => 1, :tracker_id => 1 |
|
444 | get :new, :project_id => 1, :tracker_id => 1 | |
440 | assert_response :success |
|
445 | assert_response :success | |
441 | assert_template 'new' |
|
446 | assert_template 'new' | |
442 |
|
447 | |||
443 | assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]', |
|
448 | assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]', | |
444 | :value => 'Default string' } |
|
449 | :value => 'Default string' } | |
445 | end |
|
450 | end | |
446 |
|
451 | |||
447 | def test_get_new_without_tracker_id |
|
452 | def test_get_new_without_tracker_id | |
448 | @request.session[:user_id] = 2 |
|
453 | @request.session[:user_id] = 2 | |
449 | get :new, :project_id => 1 |
|
454 | get :new, :project_id => 1 | |
450 | assert_response :success |
|
455 | assert_response :success | |
451 | assert_template 'new' |
|
456 | assert_template 'new' | |
452 |
|
457 | |||
453 | issue = assigns(:issue) |
|
458 | issue = assigns(:issue) | |
454 | assert_not_nil issue |
|
459 | assert_not_nil issue | |
455 | assert_equal Project.find(1).trackers.first, issue.tracker |
|
460 | assert_equal Project.find(1).trackers.first, issue.tracker | |
456 | end |
|
461 | end | |
457 |
|
462 | |||
458 | def test_get_new_with_no_default_status_should_display_an_error |
|
463 | def test_get_new_with_no_default_status_should_display_an_error | |
459 | @request.session[:user_id] = 2 |
|
464 | @request.session[:user_id] = 2 | |
460 | IssueStatus.delete_all |
|
465 | IssueStatus.delete_all | |
461 |
|
466 | |||
462 | get :new, :project_id => 1 |
|
467 | get :new, :project_id => 1 | |
463 | assert_response 500 |
|
468 | assert_response 500 | |
464 | assert_not_nil flash[:error] |
|
469 | assert_not_nil flash[:error] | |
465 | assert_tag :tag => 'div', :attributes => { :class => /error/ }, |
|
470 | assert_tag :tag => 'div', :attributes => { :class => /error/ }, | |
466 | :content => /No default issue/ |
|
471 | :content => /No default issue/ | |
467 | end |
|
472 | end | |
468 |
|
473 | |||
469 | def test_get_new_with_no_tracker_should_display_an_error |
|
474 | def test_get_new_with_no_tracker_should_display_an_error | |
470 | @request.session[:user_id] = 2 |
|
475 | @request.session[:user_id] = 2 | |
471 | Tracker.delete_all |
|
476 | Tracker.delete_all | |
472 |
|
477 | |||
473 | get :new, :project_id => 1 |
|
478 | get :new, :project_id => 1 | |
474 | assert_response 500 |
|
479 | assert_response 500 | |
475 | assert_not_nil flash[:error] |
|
480 | assert_not_nil flash[:error] | |
476 | assert_tag :tag => 'div', :attributes => { :class => /error/ }, |
|
481 | assert_tag :tag => 'div', :attributes => { :class => /error/ }, | |
477 | :content => /No tracker/ |
|
482 | :content => /No tracker/ | |
478 | end |
|
483 | end | |
479 |
|
484 | |||
480 | def test_update_new_form |
|
485 | def test_update_new_form | |
481 | @request.session[:user_id] = 2 |
|
486 | @request.session[:user_id] = 2 | |
482 | xhr :post, :new, :project_id => 1, |
|
487 | xhr :post, :new, :project_id => 1, | |
483 | :issue => {:tracker_id => 2, |
|
488 | :issue => {:tracker_id => 2, | |
484 | :subject => 'This is the test_new issue', |
|
489 | :subject => 'This is the test_new issue', | |
485 | :description => 'This is the description', |
|
490 | :description => 'This is the description', | |
486 | :priority_id => 5} |
|
491 | :priority_id => 5} | |
487 | assert_response :success |
|
492 | assert_response :success | |
488 | assert_template 'new' |
|
493 | assert_template 'new' | |
489 | end |
|
494 | end | |
490 |
|
495 | |||
491 | def test_post_new |
|
496 | def test_post_new | |
492 | @request.session[:user_id] = 2 |
|
497 | @request.session[:user_id] = 2 | |
493 | assert_difference 'Issue.count' do |
|
498 | assert_difference 'Issue.count' do | |
494 | post :new, :project_id => 1, |
|
499 | post :new, :project_id => 1, | |
495 | :issue => {:tracker_id => 3, |
|
500 | :issue => {:tracker_id => 3, | |
496 | :subject => 'This is the test_new issue', |
|
501 | :subject => 'This is the test_new issue', | |
497 | :description => 'This is the description', |
|
502 | :description => 'This is the description', | |
498 | :priority_id => 5, |
|
503 | :priority_id => 5, | |
499 | :estimated_hours => '', |
|
504 | :estimated_hours => '', | |
500 | :custom_field_values => {'2' => 'Value for field 2'}} |
|
505 | :custom_field_values => {'2' => 'Value for field 2'}} | |
501 | end |
|
506 | end | |
502 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id |
|
507 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id | |
503 |
|
508 | |||
504 | issue = Issue.find_by_subject('This is the test_new issue') |
|
509 | issue = Issue.find_by_subject('This is the test_new issue') | |
505 | assert_not_nil issue |
|
510 | assert_not_nil issue | |
506 | assert_equal 2, issue.author_id |
|
511 | assert_equal 2, issue.author_id | |
507 | assert_equal 3, issue.tracker_id |
|
512 | assert_equal 3, issue.tracker_id | |
508 | assert_nil issue.estimated_hours |
|
513 | assert_nil issue.estimated_hours | |
509 | v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2}) |
|
514 | v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2}) | |
510 | assert_not_nil v |
|
515 | assert_not_nil v | |
511 | assert_equal 'Value for field 2', v.value |
|
516 | assert_equal 'Value for field 2', v.value | |
512 | end |
|
517 | end | |
513 |
|
518 | |||
514 | def test_post_new_and_continue |
|
519 | def test_post_new_and_continue | |
515 | @request.session[:user_id] = 2 |
|
520 | @request.session[:user_id] = 2 | |
516 | post :new, :project_id => 1, |
|
521 | post :new, :project_id => 1, | |
517 | :issue => {:tracker_id => 3, |
|
522 | :issue => {:tracker_id => 3, | |
518 | :subject => 'This is first issue', |
|
523 | :subject => 'This is first issue', | |
519 | :priority_id => 5}, |
|
524 | :priority_id => 5}, | |
520 | :continue => '' |
|
525 | :continue => '' | |
521 | assert_redirected_to :controller => 'issues', :action => 'new', :tracker_id => 3 |
|
526 | assert_redirected_to :controller => 'issues', :action => 'new', :tracker_id => 3 | |
522 | end |
|
527 | end | |
523 |
|
528 | |||
524 | def test_post_new_without_custom_fields_param |
|
529 | def test_post_new_without_custom_fields_param | |
525 | @request.session[:user_id] = 2 |
|
530 | @request.session[:user_id] = 2 | |
526 | assert_difference 'Issue.count' do |
|
531 | assert_difference 'Issue.count' do | |
527 | post :new, :project_id => 1, |
|
532 | post :new, :project_id => 1, | |
528 | :issue => {:tracker_id => 1, |
|
533 | :issue => {:tracker_id => 1, | |
529 | :subject => 'This is the test_new issue', |
|
534 | :subject => 'This is the test_new issue', | |
530 | :description => 'This is the description', |
|
535 | :description => 'This is the description', | |
531 | :priority_id => 5} |
|
536 | :priority_id => 5} | |
532 | end |
|
537 | end | |
533 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id |
|
538 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id | |
534 | end |
|
539 | end | |
535 |
|
540 | |||
536 | def test_post_new_with_required_custom_field_and_without_custom_fields_param |
|
541 | def test_post_new_with_required_custom_field_and_without_custom_fields_param | |
537 | field = IssueCustomField.find_by_name('Database') |
|
542 | field = IssueCustomField.find_by_name('Database') | |
538 | field.update_attribute(:is_required, true) |
|
543 | field.update_attribute(:is_required, true) | |
539 |
|
544 | |||
540 | @request.session[:user_id] = 2 |
|
545 | @request.session[:user_id] = 2 | |
541 | post :new, :project_id => 1, |
|
546 | post :new, :project_id => 1, | |
542 | :issue => {:tracker_id => 1, |
|
547 | :issue => {:tracker_id => 1, | |
543 | :subject => 'This is the test_new issue', |
|
548 | :subject => 'This is the test_new issue', | |
544 | :description => 'This is the description', |
|
549 | :description => 'This is the description', | |
545 | :priority_id => 5} |
|
550 | :priority_id => 5} | |
546 | assert_response :success |
|
551 | assert_response :success | |
547 | assert_template 'new' |
|
552 | assert_template 'new' | |
548 | issue = assigns(:issue) |
|
553 | issue = assigns(:issue) | |
549 | assert_not_nil issue |
|
554 | assert_not_nil issue | |
550 | assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values) |
|
555 | assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values) | |
551 | end |
|
556 | end | |
552 |
|
557 | |||
553 | def test_post_new_with_watchers |
|
558 | def test_post_new_with_watchers | |
554 | @request.session[:user_id] = 2 |
|
559 | @request.session[:user_id] = 2 | |
555 | ActionMailer::Base.deliveries.clear |
|
560 | ActionMailer::Base.deliveries.clear | |
556 |
|
561 | |||
557 | assert_difference 'Watcher.count', 2 do |
|
562 | assert_difference 'Watcher.count', 2 do | |
558 | post :new, :project_id => 1, |
|
563 | post :new, :project_id => 1, | |
559 | :issue => {:tracker_id => 1, |
|
564 | :issue => {:tracker_id => 1, | |
560 | :subject => 'This is a new issue with watchers', |
|
565 | :subject => 'This is a new issue with watchers', | |
561 | :description => 'This is the description', |
|
566 | :description => 'This is the description', | |
562 | :priority_id => 5, |
|
567 | :priority_id => 5, | |
563 | :watcher_user_ids => ['2', '3']} |
|
568 | :watcher_user_ids => ['2', '3']} | |
564 | end |
|
569 | end | |
565 | issue = Issue.find_by_subject('This is a new issue with watchers') |
|
570 | issue = Issue.find_by_subject('This is a new issue with watchers') | |
566 | assert_not_nil issue |
|
571 | assert_not_nil issue | |
567 | assert_redirected_to :controller => 'issues', :action => 'show', :id => issue |
|
572 | assert_redirected_to :controller => 'issues', :action => 'show', :id => issue | |
568 |
|
573 | |||
569 | # Watchers added |
|
574 | # Watchers added | |
570 | assert_equal [2, 3], issue.watcher_user_ids.sort |
|
575 | assert_equal [2, 3], issue.watcher_user_ids.sort | |
571 | assert issue.watched_by?(User.find(3)) |
|
576 | assert issue.watched_by?(User.find(3)) | |
572 | # Watchers notified |
|
577 | # Watchers notified | |
573 | mail = ActionMailer::Base.deliveries.last |
|
578 | mail = ActionMailer::Base.deliveries.last | |
574 | assert_kind_of TMail::Mail, mail |
|
579 | assert_kind_of TMail::Mail, mail | |
575 | assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail) |
|
580 | assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail) | |
576 | end |
|
581 | end | |
577 |
|
582 | |||
578 | def test_post_new_should_send_a_notification |
|
583 | def test_post_new_should_send_a_notification | |
579 | ActionMailer::Base.deliveries.clear |
|
584 | ActionMailer::Base.deliveries.clear | |
580 | @request.session[:user_id] = 2 |
|
585 | @request.session[:user_id] = 2 | |
581 | assert_difference 'Issue.count' do |
|
586 | assert_difference 'Issue.count' do | |
582 | post :new, :project_id => 1, |
|
587 | post :new, :project_id => 1, | |
583 | :issue => {:tracker_id => 3, |
|
588 | :issue => {:tracker_id => 3, | |
584 | :subject => 'This is the test_new issue', |
|
589 | :subject => 'This is the test_new issue', | |
585 | :description => 'This is the description', |
|
590 | :description => 'This is the description', | |
586 | :priority_id => 5, |
|
591 | :priority_id => 5, | |
587 | :estimated_hours => '', |
|
592 | :estimated_hours => '', | |
588 | :custom_field_values => {'2' => 'Value for field 2'}} |
|
593 | :custom_field_values => {'2' => 'Value for field 2'}} | |
589 | end |
|
594 | end | |
590 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id |
|
595 | assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id | |
591 |
|
596 | |||
592 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
597 | assert_equal 1, ActionMailer::Base.deliveries.size | |
593 | end |
|
598 | end | |
594 |
|
599 | |||
595 | def test_post_should_preserve_fields_values_on_validation_failure |
|
600 | def test_post_should_preserve_fields_values_on_validation_failure | |
596 | @request.session[:user_id] = 2 |
|
601 | @request.session[:user_id] = 2 | |
597 | post :new, :project_id => 1, |
|
602 | post :new, :project_id => 1, | |
598 | :issue => {:tracker_id => 1, |
|
603 | :issue => {:tracker_id => 1, | |
599 | # empty subject |
|
604 | # empty subject | |
600 | :subject => '', |
|
605 | :subject => '', | |
601 | :description => 'This is a description', |
|
606 | :description => 'This is a description', | |
602 | :priority_id => 6, |
|
607 | :priority_id => 6, | |
603 | :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}} |
|
608 | :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}} | |
604 | assert_response :success |
|
609 | assert_response :success | |
605 | assert_template 'new' |
|
610 | assert_template 'new' | |
606 |
|
611 | |||
607 | assert_tag :textarea, :attributes => { :name => 'issue[description]' }, |
|
612 | assert_tag :textarea, :attributes => { :name => 'issue[description]' }, | |
608 | :content => 'This is a description' |
|
613 | :content => 'This is a description' | |
609 | assert_tag :select, :attributes => { :name => 'issue[priority_id]' }, |
|
614 | assert_tag :select, :attributes => { :name => 'issue[priority_id]' }, | |
610 | :child => { :tag => 'option', :attributes => { :selected => 'selected', |
|
615 | :child => { :tag => 'option', :attributes => { :selected => 'selected', | |
611 | :value => '6' }, |
|
616 | :value => '6' }, | |
612 | :content => 'High' } |
|
617 | :content => 'High' } | |
613 | # Custom fields |
|
618 | # Custom fields | |
614 | assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' }, |
|
619 | assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' }, | |
615 | :child => { :tag => 'option', :attributes => { :selected => 'selected', |
|
620 | :child => { :tag => 'option', :attributes => { :selected => 'selected', | |
616 | :value => 'Oracle' }, |
|
621 | :value => 'Oracle' }, | |
617 | :content => 'Oracle' } |
|
622 | :content => 'Oracle' } | |
618 | assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]', |
|
623 | assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]', | |
619 | :value => 'Value for field 2'} |
|
624 | :value => 'Value for field 2'} | |
620 | end |
|
625 | end | |
621 |
|
626 | |||
622 | def test_copy_routing |
|
627 | def test_copy_routing | |
623 | assert_routing( |
|
628 | assert_routing( | |
624 | {:method => :get, :path => '/projects/world_domination/issues/567/copy'}, |
|
629 | {:method => :get, :path => '/projects/world_domination/issues/567/copy'}, | |
625 | :controller => 'issues', :action => 'new', :project_id => 'world_domination', :copy_from => '567' |
|
630 | :controller => 'issues', :action => 'new', :project_id => 'world_domination', :copy_from => '567' | |
626 | ) |
|
631 | ) | |
627 | end |
|
632 | end | |
628 |
|
633 | |||
629 | def test_copy_issue |
|
634 | def test_copy_issue | |
630 | @request.session[:user_id] = 2 |
|
635 | @request.session[:user_id] = 2 | |
631 | get :new, :project_id => 1, :copy_from => 1 |
|
636 | get :new, :project_id => 1, :copy_from => 1 | |
632 | assert_template 'new' |
|
637 | assert_template 'new' | |
633 | assert_not_nil assigns(:issue) |
|
638 | assert_not_nil assigns(:issue) | |
634 | orig = Issue.find(1) |
|
639 | orig = Issue.find(1) | |
635 | assert_equal orig.subject, assigns(:issue).subject |
|
640 | assert_equal orig.subject, assigns(:issue).subject | |
636 | end |
|
641 | end | |
637 |
|
642 | |||
638 | def test_edit_routing |
|
643 | def test_edit_routing | |
639 | assert_routing( |
|
644 | assert_routing( | |
640 | {:method => :get, :path => '/issues/1/edit'}, |
|
645 | {:method => :get, :path => '/issues/1/edit'}, | |
641 | :controller => 'issues', :action => 'edit', :id => '1' |
|
646 | :controller => 'issues', :action => 'edit', :id => '1' | |
642 | ) |
|
647 | ) | |
643 | assert_recognizes( #TODO: use a PUT on the issue URI isntead, need to adjust form |
|
648 | assert_recognizes( #TODO: use a PUT on the issue URI isntead, need to adjust form | |
644 | {:controller => 'issues', :action => 'edit', :id => '1'}, |
|
649 | {:controller => 'issues', :action => 'edit', :id => '1'}, | |
645 | {:method => :post, :path => '/issues/1/edit'} |
|
650 | {:method => :post, :path => '/issues/1/edit'} | |
646 | ) |
|
651 | ) | |
647 | end |
|
652 | end | |
648 |
|
653 | |||
649 | def test_get_edit |
|
654 | def test_get_edit | |
650 | @request.session[:user_id] = 2 |
|
655 | @request.session[:user_id] = 2 | |
651 | get :edit, :id => 1 |
|
656 | get :edit, :id => 1 | |
652 | assert_response :success |
|
657 | assert_response :success | |
653 | assert_template 'edit' |
|
658 | assert_template 'edit' | |
654 | assert_not_nil assigns(:issue) |
|
659 | assert_not_nil assigns(:issue) | |
655 | assert_equal Issue.find(1), assigns(:issue) |
|
660 | assert_equal Issue.find(1), assigns(:issue) | |
656 | end |
|
661 | end | |
657 |
|
662 | |||
658 | def test_get_edit_with_params |
|
663 | def test_get_edit_with_params | |
659 | @request.session[:user_id] = 2 |
|
664 | @request.session[:user_id] = 2 | |
660 | get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 } |
|
665 | get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 } | |
661 | assert_response :success |
|
666 | assert_response :success | |
662 | assert_template 'edit' |
|
667 | assert_template 'edit' | |
663 |
|
668 | |||
664 | issue = assigns(:issue) |
|
669 | issue = assigns(:issue) | |
665 | assert_not_nil issue |
|
670 | assert_not_nil issue | |
666 |
|
671 | |||
667 | assert_equal 5, issue.status_id |
|
672 | assert_equal 5, issue.status_id | |
668 | assert_tag :select, :attributes => { :name => 'issue[status_id]' }, |
|
673 | assert_tag :select, :attributes => { :name => 'issue[status_id]' }, | |
669 | :child => { :tag => 'option', |
|
674 | :child => { :tag => 'option', | |
670 | :content => 'Closed', |
|
675 | :content => 'Closed', | |
671 | :attributes => { :selected => 'selected' } } |
|
676 | :attributes => { :selected => 'selected' } } | |
672 |
|
677 | |||
673 | assert_equal 7, issue.priority_id |
|
678 | assert_equal 7, issue.priority_id | |
674 | assert_tag :select, :attributes => { :name => 'issue[priority_id]' }, |
|
679 | assert_tag :select, :attributes => { :name => 'issue[priority_id]' }, | |
675 | :child => { :tag => 'option', |
|
680 | :child => { :tag => 'option', | |
676 | :content => 'Urgent', |
|
681 | :content => 'Urgent', | |
677 | :attributes => { :selected => 'selected' } } |
|
682 | :attributes => { :selected => 'selected' } } | |
678 | end |
|
683 | end | |
679 |
|
684 | |||
680 | def test_reply_routing |
|
685 | def test_reply_routing | |
681 | assert_routing( |
|
686 | assert_routing( | |
682 | {:method => :post, :path => '/issues/1/quoted'}, |
|
687 | {:method => :post, :path => '/issues/1/quoted'}, | |
683 | :controller => 'issues', :action => 'reply', :id => '1' |
|
688 | :controller => 'issues', :action => 'reply', :id => '1' | |
684 | ) |
|
689 | ) | |
685 | end |
|
690 | end | |
686 |
|
691 | |||
687 | def test_reply_to_issue |
|
692 | def test_reply_to_issue | |
688 | @request.session[:user_id] = 2 |
|
693 | @request.session[:user_id] = 2 | |
689 | get :reply, :id => 1 |
|
694 | get :reply, :id => 1 | |
690 | assert_response :success |
|
695 | assert_response :success | |
691 | assert_select_rjs :show, "update" |
|
696 | assert_select_rjs :show, "update" | |
692 | end |
|
697 | end | |
693 |
|
698 | |||
694 | def test_reply_to_note |
|
699 | def test_reply_to_note | |
695 | @request.session[:user_id] = 2 |
|
700 | @request.session[:user_id] = 2 | |
696 | get :reply, :id => 1, :journal_id => 2 |
|
701 | get :reply, :id => 1, :journal_id => 2 | |
697 | assert_response :success |
|
702 | assert_response :success | |
698 | assert_select_rjs :show, "update" |
|
703 | assert_select_rjs :show, "update" | |
699 | end |
|
704 | end | |
700 |
|
705 | |||
701 | def test_post_edit_without_custom_fields_param |
|
706 | def test_post_edit_without_custom_fields_param | |
702 | @request.session[:user_id] = 2 |
|
707 | @request.session[:user_id] = 2 | |
703 | ActionMailer::Base.deliveries.clear |
|
708 | ActionMailer::Base.deliveries.clear | |
704 |
|
709 | |||
705 | issue = Issue.find(1) |
|
710 | issue = Issue.find(1) | |
706 | assert_equal '125', issue.custom_value_for(2).value |
|
711 | assert_equal '125', issue.custom_value_for(2).value | |
707 | old_subject = issue.subject |
|
712 | old_subject = issue.subject | |
708 | new_subject = 'Subject modified by IssuesControllerTest#test_post_edit' |
|
713 | new_subject = 'Subject modified by IssuesControllerTest#test_post_edit' | |
709 |
|
714 | |||
710 | assert_difference('Journal.count') do |
|
715 | assert_difference('Journal.count') do | |
711 | assert_difference('JournalDetail.count', 2) do |
|
716 | assert_difference('JournalDetail.count', 2) do | |
712 | post :edit, :id => 1, :issue => {:subject => new_subject, |
|
717 | post :edit, :id => 1, :issue => {:subject => new_subject, | |
713 | :priority_id => '6', |
|
718 | :priority_id => '6', | |
714 | :category_id => '1' # no change |
|
719 | :category_id => '1' # no change | |
715 | } |
|
720 | } | |
716 | end |
|
721 | end | |
717 | end |
|
722 | end | |
718 | assert_redirected_to :action => 'show', :id => '1' |
|
723 | assert_redirected_to :action => 'show', :id => '1' | |
719 | issue.reload |
|
724 | issue.reload | |
720 | assert_equal new_subject, issue.subject |
|
725 | assert_equal new_subject, issue.subject | |
721 | # Make sure custom fields were not cleared |
|
726 | # Make sure custom fields were not cleared | |
722 | assert_equal '125', issue.custom_value_for(2).value |
|
727 | assert_equal '125', issue.custom_value_for(2).value | |
723 |
|
728 | |||
724 | mail = ActionMailer::Base.deliveries.last |
|
729 | mail = ActionMailer::Base.deliveries.last | |
725 | assert_kind_of TMail::Mail, mail |
|
730 | assert_kind_of TMail::Mail, mail | |
726 | assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]") |
|
731 | assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]") | |
727 | assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}") |
|
732 | assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}") | |
728 | end |
|
733 | end | |
729 |
|
734 | |||
730 | def test_post_edit_with_custom_field_change |
|
735 | def test_post_edit_with_custom_field_change | |
731 | @request.session[:user_id] = 2 |
|
736 | @request.session[:user_id] = 2 | |
732 | issue = Issue.find(1) |
|
737 | issue = Issue.find(1) | |
733 | assert_equal '125', issue.custom_value_for(2).value |
|
738 | assert_equal '125', issue.custom_value_for(2).value | |
734 |
|
739 | |||
735 | assert_difference('Journal.count') do |
|
740 | assert_difference('Journal.count') do | |
736 | assert_difference('JournalDetail.count', 3) do |
|
741 | assert_difference('JournalDetail.count', 3) do | |
737 | post :edit, :id => 1, :issue => {:subject => 'Custom field change', |
|
742 | post :edit, :id => 1, :issue => {:subject => 'Custom field change', | |
738 | :priority_id => '6', |
|
743 | :priority_id => '6', | |
739 | :category_id => '1', # no change |
|
744 | :category_id => '1', # no change | |
740 | :custom_field_values => { '2' => 'New custom value' } |
|
745 | :custom_field_values => { '2' => 'New custom value' } | |
741 | } |
|
746 | } | |
742 | end |
|
747 | end | |
743 | end |
|
748 | end | |
744 | assert_redirected_to :action => 'show', :id => '1' |
|
749 | assert_redirected_to :action => 'show', :id => '1' | |
745 | issue.reload |
|
750 | issue.reload | |
746 | assert_equal 'New custom value', issue.custom_value_for(2).value |
|
751 | assert_equal 'New custom value', issue.custom_value_for(2).value | |
747 |
|
752 | |||
748 | mail = ActionMailer::Base.deliveries.last |
|
753 | mail = ActionMailer::Base.deliveries.last | |
749 | assert_kind_of TMail::Mail, mail |
|
754 | assert_kind_of TMail::Mail, mail | |
750 | assert mail.body.include?("Searchable field changed from 125 to New custom value") |
|
755 | assert mail.body.include?("Searchable field changed from 125 to New custom value") | |
751 | end |
|
756 | end | |
752 |
|
757 | |||
753 | def test_post_edit_with_status_and_assignee_change |
|
758 | def test_post_edit_with_status_and_assignee_change | |
754 | issue = Issue.find(1) |
|
759 | issue = Issue.find(1) | |
755 | assert_equal 1, issue.status_id |
|
760 | assert_equal 1, issue.status_id | |
756 | @request.session[:user_id] = 2 |
|
761 | @request.session[:user_id] = 2 | |
757 | assert_difference('TimeEntry.count', 0) do |
|
762 | assert_difference('TimeEntry.count', 0) do | |
758 | post :edit, |
|
763 | post :edit, | |
759 | :id => 1, |
|
764 | :id => 1, | |
760 | :issue => { :status_id => 2, :assigned_to_id => 3 }, |
|
765 | :issue => { :status_id => 2, :assigned_to_id => 3 }, | |
761 | :notes => 'Assigned to dlopper', |
|
766 | :notes => 'Assigned to dlopper', | |
762 | :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first } |
|
767 | :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first } | |
763 | end |
|
768 | end | |
764 | assert_redirected_to :action => 'show', :id => '1' |
|
769 | assert_redirected_to :action => 'show', :id => '1' | |
765 | issue.reload |
|
770 | issue.reload | |
766 | assert_equal 2, issue.status_id |
|
771 | assert_equal 2, issue.status_id | |
767 | j = issue.journals.find(:first, :order => 'id DESC') |
|
772 | j = issue.journals.find(:first, :order => 'id DESC') | |
768 | assert_equal 'Assigned to dlopper', j.notes |
|
773 | assert_equal 'Assigned to dlopper', j.notes | |
769 | assert_equal 2, j.details.size |
|
774 | assert_equal 2, j.details.size | |
770 |
|
775 | |||
771 | mail = ActionMailer::Base.deliveries.last |
|
776 | mail = ActionMailer::Base.deliveries.last | |
772 | assert mail.body.include?("Status changed from New to Assigned") |
|
777 | assert mail.body.include?("Status changed from New to Assigned") | |
773 | # subject should contain the new status |
|
778 | # subject should contain the new status | |
774 | assert mail.subject.include?("(#{ IssueStatus.find(2).name })") |
|
779 | assert mail.subject.include?("(#{ IssueStatus.find(2).name })") | |
775 | end |
|
780 | end | |
776 |
|
781 | |||
777 | def test_post_edit_with_note_only |
|
782 | def test_post_edit_with_note_only | |
778 | notes = 'Note added by IssuesControllerTest#test_update_with_note_only' |
|
783 | notes = 'Note added by IssuesControllerTest#test_update_with_note_only' | |
779 | # anonymous user |
|
784 | # anonymous user | |
780 | post :edit, |
|
785 | post :edit, | |
781 | :id => 1, |
|
786 | :id => 1, | |
782 | :notes => notes |
|
787 | :notes => notes | |
783 | assert_redirected_to :action => 'show', :id => '1' |
|
788 | assert_redirected_to :action => 'show', :id => '1' | |
784 | j = Issue.find(1).journals.find(:first, :order => 'id DESC') |
|
789 | j = Issue.find(1).journals.find(:first, :order => 'id DESC') | |
785 | assert_equal notes, j.notes |
|
790 | assert_equal notes, j.notes | |
786 | assert_equal 0, j.details.size |
|
791 | assert_equal 0, j.details.size | |
787 | assert_equal User.anonymous, j.user |
|
792 | assert_equal User.anonymous, j.user | |
788 |
|
793 | |||
789 | mail = ActionMailer::Base.deliveries.last |
|
794 | mail = ActionMailer::Base.deliveries.last | |
790 | assert mail.body.include?(notes) |
|
795 | assert mail.body.include?(notes) | |
791 | end |
|
796 | end | |
792 |
|
797 | |||
793 | def test_post_edit_with_note_and_spent_time |
|
798 | def test_post_edit_with_note_and_spent_time | |
794 | @request.session[:user_id] = 2 |
|
799 | @request.session[:user_id] = 2 | |
795 | spent_hours_before = Issue.find(1).spent_hours |
|
800 | spent_hours_before = Issue.find(1).spent_hours | |
796 | assert_difference('TimeEntry.count') do |
|
801 | assert_difference('TimeEntry.count') do | |
797 | post :edit, |
|
802 | post :edit, | |
798 | :id => 1, |
|
803 | :id => 1, | |
799 | :notes => '2.5 hours added', |
|
804 | :notes => '2.5 hours added', | |
800 | :time_entry => { :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first } |
|
805 | :time_entry => { :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first } | |
801 | end |
|
806 | end | |
802 | assert_redirected_to :action => 'show', :id => '1' |
|
807 | assert_redirected_to :action => 'show', :id => '1' | |
803 |
|
808 | |||
804 | issue = Issue.find(1) |
|
809 | issue = Issue.find(1) | |
805 |
|
810 | |||
806 | j = issue.journals.find(:first, :order => 'id DESC') |
|
811 | j = issue.journals.find(:first, :order => 'id DESC') | |
807 | assert_equal '2.5 hours added', j.notes |
|
812 | assert_equal '2.5 hours added', j.notes | |
808 | assert_equal 0, j.details.size |
|
813 | assert_equal 0, j.details.size | |
809 |
|
814 | |||
810 | t = issue.time_entries.find(:first, :order => 'id DESC') |
|
815 | t = issue.time_entries.find(:first, :order => 'id DESC') | |
811 | assert_not_nil t |
|
816 | assert_not_nil t | |
812 | assert_equal 2.5, t.hours |
|
817 | assert_equal 2.5, t.hours | |
813 | assert_equal spent_hours_before + 2.5, issue.spent_hours |
|
818 | assert_equal spent_hours_before + 2.5, issue.spent_hours | |
814 | end |
|
819 | end | |
815 |
|
820 | |||
816 | def test_post_edit_with_attachment_only |
|
821 | def test_post_edit_with_attachment_only | |
817 | set_tmp_attachments_directory |
|
822 | set_tmp_attachments_directory | |
818 |
|
823 | |||
819 | # Delete all fixtured journals, a race condition can occur causing the wrong |
|
824 | # Delete all fixtured journals, a race condition can occur causing the wrong | |
820 | # journal to get fetched in the next find. |
|
825 | # journal to get fetched in the next find. | |
821 | Journal.delete_all |
|
826 | Journal.delete_all | |
822 |
|
827 | |||
823 | # anonymous user |
|
828 | # anonymous user | |
824 | post :edit, |
|
829 | post :edit, | |
825 | :id => 1, |
|
830 | :id => 1, | |
826 | :notes => '', |
|
831 | :notes => '', | |
827 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} |
|
832 | :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} | |
828 | assert_redirected_to :action => 'show', :id => '1' |
|
833 | assert_redirected_to :action => 'show', :id => '1' | |
829 | j = Issue.find(1).journals.find(:first, :order => 'id DESC') |
|
834 | j = Issue.find(1).journals.find(:first, :order => 'id DESC') | |
830 | assert j.notes.blank? |
|
835 | assert j.notes.blank? | |
831 | assert_equal 1, j.details.size |
|
836 | assert_equal 1, j.details.size | |
832 | assert_equal 'testfile.txt', j.details.first.value |
|
837 | assert_equal 'testfile.txt', j.details.first.value | |
833 | assert_equal User.anonymous, j.user |
|
838 | assert_equal User.anonymous, j.user | |
834 |
|
839 | |||
835 | mail = ActionMailer::Base.deliveries.last |
|
840 | mail = ActionMailer::Base.deliveries.last | |
836 | assert mail.body.include?('testfile.txt') |
|
841 | assert mail.body.include?('testfile.txt') | |
837 | end |
|
842 | end | |
838 |
|
843 | |||
839 | def test_post_edit_with_no_change |
|
844 | def test_post_edit_with_no_change | |
840 | issue = Issue.find(1) |
|
845 | issue = Issue.find(1) | |
841 | issue.journals.clear |
|
846 | issue.journals.clear | |
842 | ActionMailer::Base.deliveries.clear |
|
847 | ActionMailer::Base.deliveries.clear | |
843 |
|
848 | |||
844 | post :edit, |
|
849 | post :edit, | |
845 | :id => 1, |
|
850 | :id => 1, | |
846 | :notes => '' |
|
851 | :notes => '' | |
847 | assert_redirected_to :action => 'show', :id => '1' |
|
852 | assert_redirected_to :action => 'show', :id => '1' | |
848 |
|
853 | |||
849 | issue.reload |
|
854 | issue.reload | |
850 | assert issue.journals.empty? |
|
855 | assert issue.journals.empty? | |
851 | # No email should be sent |
|
856 | # No email should be sent | |
852 | assert ActionMailer::Base.deliveries.empty? |
|
857 | assert ActionMailer::Base.deliveries.empty? | |
853 | end |
|
858 | end | |
854 |
|
859 | |||
855 | def test_post_edit_should_send_a_notification |
|
860 | def test_post_edit_should_send_a_notification | |
856 | @request.session[:user_id] = 2 |
|
861 | @request.session[:user_id] = 2 | |
857 | ActionMailer::Base.deliveries.clear |
|
862 | ActionMailer::Base.deliveries.clear | |
858 | issue = Issue.find(1) |
|
863 | issue = Issue.find(1) | |
859 | old_subject = issue.subject |
|
864 | old_subject = issue.subject | |
860 | new_subject = 'Subject modified by IssuesControllerTest#test_post_edit' |
|
865 | new_subject = 'Subject modified by IssuesControllerTest#test_post_edit' | |
861 |
|
866 | |||
862 | post :edit, :id => 1, :issue => {:subject => new_subject, |
|
867 | post :edit, :id => 1, :issue => {:subject => new_subject, | |
863 | :priority_id => '6', |
|
868 | :priority_id => '6', | |
864 | :category_id => '1' # no change |
|
869 | :category_id => '1' # no change | |
865 | } |
|
870 | } | |
866 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
871 | assert_equal 1, ActionMailer::Base.deliveries.size | |
867 | end |
|
872 | end | |
868 |
|
873 | |||
869 | def test_post_edit_with_invalid_spent_time |
|
874 | def test_post_edit_with_invalid_spent_time | |
870 | @request.session[:user_id] = 2 |
|
875 | @request.session[:user_id] = 2 | |
871 | notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time' |
|
876 | notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time' | |
872 |
|
877 | |||
873 | assert_no_difference('Journal.count') do |
|
878 | assert_no_difference('Journal.count') do | |
874 | post :edit, |
|
879 | post :edit, | |
875 | :id => 1, |
|
880 | :id => 1, | |
876 | :notes => notes, |
|
881 | :notes => notes, | |
877 | :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"} |
|
882 | :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"} | |
878 | end |
|
883 | end | |
879 | assert_response :success |
|
884 | assert_response :success | |
880 | assert_template 'edit' |
|
885 | assert_template 'edit' | |
881 |
|
886 | |||
882 | assert_tag :textarea, :attributes => { :name => 'notes' }, |
|
887 | assert_tag :textarea, :attributes => { :name => 'notes' }, | |
883 | :content => notes |
|
888 | :content => notes | |
884 | assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" } |
|
889 | assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" } | |
885 | end |
|
890 | end | |
886 |
|
891 | |||
887 | def test_get_bulk_edit |
|
892 | def test_get_bulk_edit | |
888 | @request.session[:user_id] = 2 |
|
893 | @request.session[:user_id] = 2 | |
889 | get :bulk_edit, :ids => [1, 2] |
|
894 | get :bulk_edit, :ids => [1, 2] | |
890 | assert_response :success |
|
895 | assert_response :success | |
891 | assert_template 'bulk_edit' |
|
896 | assert_template 'bulk_edit' | |
892 | end |
|
897 | end | |
893 |
|
898 | |||
894 | def test_bulk_edit |
|
899 | def test_bulk_edit | |
895 | @request.session[:user_id] = 2 |
|
900 | @request.session[:user_id] = 2 | |
896 | # update issues priority |
|
901 | # update issues priority | |
897 | post :bulk_edit, :ids => [1, 2], :priority_id => 7, |
|
902 | post :bulk_edit, :ids => [1, 2], :priority_id => 7, | |
898 | :assigned_to_id => '', |
|
903 | :assigned_to_id => '', | |
899 | :custom_field_values => {'2' => ''}, |
|
904 | :custom_field_values => {'2' => ''}, | |
900 | :notes => 'Bulk editing' |
|
905 | :notes => 'Bulk editing' | |
901 | assert_response 302 |
|
906 | assert_response 302 | |
902 | # check that the issues were updated |
|
907 | # check that the issues were updated | |
903 | assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id} |
|
908 | assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id} | |
904 |
|
909 | |||
905 | issue = Issue.find(1) |
|
910 | issue = Issue.find(1) | |
906 | journal = issue.journals.find(:first, :order => 'created_on DESC') |
|
911 | journal = issue.journals.find(:first, :order => 'created_on DESC') | |
907 | assert_equal '125', issue.custom_value_for(2).value |
|
912 | assert_equal '125', issue.custom_value_for(2).value | |
908 | assert_equal 'Bulk editing', journal.notes |
|
913 | assert_equal 'Bulk editing', journal.notes | |
909 | assert_equal 1, journal.details.size |
|
914 | assert_equal 1, journal.details.size | |
910 | end |
|
915 | end | |
911 |
|
916 | |||
912 | def test_bullk_edit_should_send_a_notification |
|
917 | def test_bullk_edit_should_send_a_notification | |
913 | @request.session[:user_id] = 2 |
|
918 | @request.session[:user_id] = 2 | |
914 | ActionMailer::Base.deliveries.clear |
|
919 | ActionMailer::Base.deliveries.clear | |
915 | post(:bulk_edit, |
|
920 | post(:bulk_edit, | |
916 | { |
|
921 | { | |
917 | :ids => [1, 2], |
|
922 | :ids => [1, 2], | |
918 | :priority_id => 7, |
|
923 | :priority_id => 7, | |
919 | :assigned_to_id => '', |
|
924 | :assigned_to_id => '', | |
920 | :custom_field_values => {'2' => ''}, |
|
925 | :custom_field_values => {'2' => ''}, | |
921 | :notes => 'Bulk editing' |
|
926 | :notes => 'Bulk editing' | |
922 | }) |
|
927 | }) | |
923 |
|
928 | |||
924 | assert_response 302 |
|
929 | assert_response 302 | |
925 | assert_equal 2, ActionMailer::Base.deliveries.size |
|
930 | assert_equal 2, ActionMailer::Base.deliveries.size | |
926 | end |
|
931 | end | |
927 |
|
932 | |||
928 | def test_bulk_edit_status |
|
933 | def test_bulk_edit_status | |
929 | @request.session[:user_id] = 2 |
|
934 | @request.session[:user_id] = 2 | |
930 | # update issues priority |
|
935 | # update issues priority | |
931 | post :bulk_edit, :ids => [1, 2], :priority_id => '', |
|
936 | post :bulk_edit, :ids => [1, 2], :priority_id => '', | |
932 | :assigned_to_id => '', |
|
937 | :assigned_to_id => '', | |
933 | :status_id => '5', |
|
938 | :status_id => '5', | |
934 | :notes => 'Bulk editing status' |
|
939 | :notes => 'Bulk editing status' | |
935 | assert_response 302 |
|
940 | assert_response 302 | |
936 | issue = Issue.find(1) |
|
941 | issue = Issue.find(1) | |
937 | assert issue.closed? |
|
942 | assert issue.closed? | |
938 | end |
|
943 | end | |
939 |
|
944 | |||
940 | def test_bulk_edit_custom_field |
|
945 | def test_bulk_edit_custom_field | |
941 | @request.session[:user_id] = 2 |
|
946 | @request.session[:user_id] = 2 | |
942 | # update issues priority |
|
947 | # update issues priority | |
943 | post :bulk_edit, :ids => [1, 2], :priority_id => '', |
|
948 | post :bulk_edit, :ids => [1, 2], :priority_id => '', | |
944 | :assigned_to_id => '', |
|
949 | :assigned_to_id => '', | |
945 | :custom_field_values => {'2' => '777'}, |
|
950 | :custom_field_values => {'2' => '777'}, | |
946 | :notes => 'Bulk editing custom field' |
|
951 | :notes => 'Bulk editing custom field' | |
947 | assert_response 302 |
|
952 | assert_response 302 | |
948 |
|
953 | |||
949 | issue = Issue.find(1) |
|
954 | issue = Issue.find(1) | |
950 | journal = issue.journals.find(:first, :order => 'created_on DESC') |
|
955 | journal = issue.journals.find(:first, :order => 'created_on DESC') | |
951 | assert_equal '777', issue.custom_value_for(2).value |
|
956 | assert_equal '777', issue.custom_value_for(2).value | |
952 | assert_equal 1, journal.details.size |
|
957 | assert_equal 1, journal.details.size | |
953 | assert_equal '125', journal.details.first.old_value |
|
958 | assert_equal '125', journal.details.first.old_value | |
954 | assert_equal '777', journal.details.first.value |
|
959 | assert_equal '777', journal.details.first.value | |
955 | end |
|
960 | end | |
956 |
|
961 | |||
957 | def test_bulk_unassign |
|
962 | def test_bulk_unassign | |
958 | assert_not_nil Issue.find(2).assigned_to |
|
963 | assert_not_nil Issue.find(2).assigned_to | |
959 | @request.session[:user_id] = 2 |
|
964 | @request.session[:user_id] = 2 | |
960 | # unassign issues |
|
965 | # unassign issues | |
961 | post :bulk_edit, :ids => [1, 2], :notes => 'Bulk unassigning', :assigned_to_id => 'none' |
|
966 | post :bulk_edit, :ids => [1, 2], :notes => 'Bulk unassigning', :assigned_to_id => 'none' | |
962 | assert_response 302 |
|
967 | assert_response 302 | |
963 | # check that the issues were updated |
|
968 | # check that the issues were updated | |
964 | assert_nil Issue.find(2).assigned_to |
|
969 | assert_nil Issue.find(2).assigned_to | |
965 | end |
|
970 | end | |
966 |
|
971 | |||
967 | def test_move_routing |
|
972 | def test_move_routing | |
968 | assert_routing( |
|
973 | assert_routing( | |
969 | {:method => :get, :path => '/issues/1/move'}, |
|
974 | {:method => :get, :path => '/issues/1/move'}, | |
970 | :controller => 'issues', :action => 'move', :id => '1' |
|
975 | :controller => 'issues', :action => 'move', :id => '1' | |
971 | ) |
|
976 | ) | |
972 | assert_recognizes( |
|
977 | assert_recognizes( | |
973 | {:controller => 'issues', :action => 'move', :id => '1'}, |
|
978 | {:controller => 'issues', :action => 'move', :id => '1'}, | |
974 | {:method => :post, :path => '/issues/1/move'} |
|
979 | {:method => :post, :path => '/issues/1/move'} | |
975 | ) |
|
980 | ) | |
976 | end |
|
981 | end | |
977 |
|
982 | |||
978 | def test_move_one_issue_to_another_project |
|
983 | def test_move_one_issue_to_another_project | |
979 | @request.session[:user_id] = 2 |
|
984 | @request.session[:user_id] = 2 | |
980 | post :move, :id => 1, :new_project_id => 2 |
|
985 | post :move, :id => 1, :new_project_id => 2 | |
981 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
986 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
982 | assert_equal 2, Issue.find(1).project_id |
|
987 | assert_equal 2, Issue.find(1).project_id | |
983 | end |
|
988 | end | |
984 |
|
989 | |||
985 | def test_move_one_issue_to_another_project_should_follow_when_needed |
|
990 | def test_move_one_issue_to_another_project_should_follow_when_needed | |
986 | @request.session[:user_id] = 2 |
|
991 | @request.session[:user_id] = 2 | |
987 | post :move, :id => 1, :new_project_id => 2, :follow => '1' |
|
992 | post :move, :id => 1, :new_project_id => 2, :follow => '1' | |
988 | assert_redirected_to '/issues/1' |
|
993 | assert_redirected_to '/issues/1' | |
989 | end |
|
994 | end | |
990 |
|
995 | |||
991 | def test_bulk_move_to_another_project |
|
996 | def test_bulk_move_to_another_project | |
992 | @request.session[:user_id] = 2 |
|
997 | @request.session[:user_id] = 2 | |
993 | post :move, :ids => [1, 2], :new_project_id => 2 |
|
998 | post :move, :ids => [1, 2], :new_project_id => 2 | |
994 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
999 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
995 | # Issues moved to project 2 |
|
1000 | # Issues moved to project 2 | |
996 | assert_equal 2, Issue.find(1).project_id |
|
1001 | assert_equal 2, Issue.find(1).project_id | |
997 | assert_equal 2, Issue.find(2).project_id |
|
1002 | assert_equal 2, Issue.find(2).project_id | |
998 | # No tracker change |
|
1003 | # No tracker change | |
999 | assert_equal 1, Issue.find(1).tracker_id |
|
1004 | assert_equal 1, Issue.find(1).tracker_id | |
1000 | assert_equal 2, Issue.find(2).tracker_id |
|
1005 | assert_equal 2, Issue.find(2).tracker_id | |
1001 | end |
|
1006 | end | |
1002 |
|
1007 | |||
1003 | def test_bulk_move_to_another_tracker |
|
1008 | def test_bulk_move_to_another_tracker | |
1004 | @request.session[:user_id] = 2 |
|
1009 | @request.session[:user_id] = 2 | |
1005 | post :move, :ids => [1, 2], :new_tracker_id => 2 |
|
1010 | post :move, :ids => [1, 2], :new_tracker_id => 2 | |
1006 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
1011 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
1007 | assert_equal 2, Issue.find(1).tracker_id |
|
1012 | assert_equal 2, Issue.find(1).tracker_id | |
1008 | assert_equal 2, Issue.find(2).tracker_id |
|
1013 | assert_equal 2, Issue.find(2).tracker_id | |
1009 | end |
|
1014 | end | |
1010 |
|
1015 | |||
1011 | def test_bulk_copy_to_another_project |
|
1016 | def test_bulk_copy_to_another_project | |
1012 | @request.session[:user_id] = 2 |
|
1017 | @request.session[:user_id] = 2 | |
1013 | assert_difference 'Issue.count', 2 do |
|
1018 | assert_difference 'Issue.count', 2 do | |
1014 | assert_no_difference 'Project.find(1).issues.count' do |
|
1019 | assert_no_difference 'Project.find(1).issues.count' do | |
1015 | post :move, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'} |
|
1020 | post :move, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'} | |
1016 | end |
|
1021 | end | |
1017 | end |
|
1022 | end | |
1018 | assert_redirected_to 'projects/ecookbook/issues' |
|
1023 | assert_redirected_to 'projects/ecookbook/issues' | |
1019 | end |
|
1024 | end | |
1020 |
|
1025 | |||
1021 | def test_copy_to_another_project_should_follow_when_needed |
|
1026 | def test_copy_to_another_project_should_follow_when_needed | |
1022 | @request.session[:user_id] = 2 |
|
1027 | @request.session[:user_id] = 2 | |
1023 | post :move, :ids => [1], :new_project_id => 2, :copy_options => {:copy => '1'}, :follow => '1' |
|
1028 | post :move, :ids => [1], :new_project_id => 2, :copy_options => {:copy => '1'}, :follow => '1' | |
1024 | issue = Issue.first(:order => 'id DESC') |
|
1029 | issue = Issue.first(:order => 'id DESC') | |
1025 | assert_redirected_to :controller => 'issues', :action => 'show', :id => issue |
|
1030 | assert_redirected_to :controller => 'issues', :action => 'show', :id => issue | |
1026 | end |
|
1031 | end | |
1027 |
|
1032 | |||
1028 | def test_context_menu_one_issue |
|
1033 | def test_context_menu_one_issue | |
1029 | @request.session[:user_id] = 2 |
|
1034 | @request.session[:user_id] = 2 | |
1030 | get :context_menu, :ids => [1] |
|
1035 | get :context_menu, :ids => [1] | |
1031 | assert_response :success |
|
1036 | assert_response :success | |
1032 | assert_template 'context_menu' |
|
1037 | assert_template 'context_menu' | |
1033 | assert_tag :tag => 'a', :content => 'Edit', |
|
1038 | assert_tag :tag => 'a', :content => 'Edit', | |
1034 | :attributes => { :href => '/issues/1/edit', |
|
1039 | :attributes => { :href => '/issues/1/edit', | |
1035 | :class => 'icon-edit' } |
|
1040 | :class => 'icon-edit' } | |
1036 | assert_tag :tag => 'a', :content => 'Closed', |
|
1041 | assert_tag :tag => 'a', :content => 'Closed', | |
1037 | :attributes => { :href => '/issues/1/edit?issue%5Bstatus_id%5D=5', |
|
1042 | :attributes => { :href => '/issues/1/edit?issue%5Bstatus_id%5D=5', | |
1038 | :class => '' } |
|
1043 | :class => '' } | |
1039 | assert_tag :tag => 'a', :content => 'Immediate', |
|
1044 | assert_tag :tag => 'a', :content => 'Immediate', | |
1040 | :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&priority_id=8', |
|
1045 | :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&priority_id=8', | |
1041 | :class => '' } |
|
1046 | :class => '' } | |
1042 | assert_tag :tag => 'a', :content => 'Dave Lopper', |
|
1047 | assert_tag :tag => 'a', :content => 'Dave Lopper', | |
1043 | :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&ids%5B%5D=1', |
|
1048 | :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&ids%5B%5D=1', | |
1044 | :class => '' } |
|
1049 | :class => '' } | |
1045 | assert_tag :tag => 'a', :content => 'Copy', |
|
1050 | assert_tag :tag => 'a', :content => 'Copy', | |
1046 | :attributes => { :href => '/projects/ecookbook/issues/1/copy', |
|
1051 | :attributes => { :href => '/projects/ecookbook/issues/1/copy', | |
1047 | :class => 'icon-copy' } |
|
1052 | :class => 'icon-copy' } | |
1048 | assert_tag :tag => 'a', :content => 'Move', |
|
1053 | assert_tag :tag => 'a', :content => 'Move', | |
1049 | :attributes => { :href => '/issues/move?ids%5B%5D=1', |
|
1054 | :attributes => { :href => '/issues/move?ids%5B%5D=1', | |
1050 | :class => 'icon-move' } |
|
1055 | :class => 'icon-move' } | |
1051 | assert_tag :tag => 'a', :content => 'Delete', |
|
1056 | assert_tag :tag => 'a', :content => 'Delete', | |
1052 | :attributes => { :href => '/issues/destroy?ids%5B%5D=1', |
|
1057 | :attributes => { :href => '/issues/destroy?ids%5B%5D=1', | |
1053 | :class => 'icon-del' } |
|
1058 | :class => 'icon-del' } | |
1054 | end |
|
1059 | end | |
1055 |
|
1060 | |||
1056 | def test_context_menu_one_issue_by_anonymous |
|
1061 | def test_context_menu_one_issue_by_anonymous | |
1057 | get :context_menu, :ids => [1] |
|
1062 | get :context_menu, :ids => [1] | |
1058 | assert_response :success |
|
1063 | assert_response :success | |
1059 | assert_template 'context_menu' |
|
1064 | assert_template 'context_menu' | |
1060 | assert_tag :tag => 'a', :content => 'Delete', |
|
1065 | assert_tag :tag => 'a', :content => 'Delete', | |
1061 | :attributes => { :href => '#', |
|
1066 | :attributes => { :href => '#', | |
1062 | :class => 'icon-del disabled' } |
|
1067 | :class => 'icon-del disabled' } | |
1063 | end |
|
1068 | end | |
1064 |
|
1069 | |||
1065 | def test_context_menu_multiple_issues_of_same_project |
|
1070 | def test_context_menu_multiple_issues_of_same_project | |
1066 | @request.session[:user_id] = 2 |
|
1071 | @request.session[:user_id] = 2 | |
1067 | get :context_menu, :ids => [1, 2] |
|
1072 | get :context_menu, :ids => [1, 2] | |
1068 | assert_response :success |
|
1073 | assert_response :success | |
1069 | assert_template 'context_menu' |
|
1074 | assert_template 'context_menu' | |
1070 | assert_tag :tag => 'a', :content => 'Edit', |
|
1075 | assert_tag :tag => 'a', :content => 'Edit', | |
1071 | :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&ids%5B%5D=2', |
|
1076 | :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&ids%5B%5D=2', | |
1072 | :class => 'icon-edit' } |
|
1077 | :class => 'icon-edit' } | |
1073 | assert_tag :tag => 'a', :content => 'Immediate', |
|
1078 | assert_tag :tag => 'a', :content => 'Immediate', | |
1074 | :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&ids%5B%5D=2&priority_id=8', |
|
1079 | :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&ids%5B%5D=2&priority_id=8', | |
1075 | :class => '' } |
|
1080 | :class => '' } | |
1076 | assert_tag :tag => 'a', :content => 'Dave Lopper', |
|
1081 | assert_tag :tag => 'a', :content => 'Dave Lopper', | |
1077 | :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&ids%5B%5D=1&ids%5B%5D=2', |
|
1082 | :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&ids%5B%5D=1&ids%5B%5D=2', | |
1078 | :class => '' } |
|
1083 | :class => '' } | |
1079 | assert_tag :tag => 'a', :content => 'Move', |
|
1084 | assert_tag :tag => 'a', :content => 'Move', | |
1080 | :attributes => { :href => '/issues/move?ids%5B%5D=1&ids%5B%5D=2', |
|
1085 | :attributes => { :href => '/issues/move?ids%5B%5D=1&ids%5B%5D=2', | |
1081 | :class => 'icon-move' } |
|
1086 | :class => 'icon-move' } | |
1082 | assert_tag :tag => 'a', :content => 'Delete', |
|
1087 | assert_tag :tag => 'a', :content => 'Delete', | |
1083 | :attributes => { :href => '/issues/destroy?ids%5B%5D=1&ids%5B%5D=2', |
|
1088 | :attributes => { :href => '/issues/destroy?ids%5B%5D=1&ids%5B%5D=2', | |
1084 | :class => 'icon-del' } |
|
1089 | :class => 'icon-del' } | |
1085 | end |
|
1090 | end | |
1086 |
|
1091 | |||
1087 | def test_context_menu_multiple_issues_of_different_project |
|
1092 | def test_context_menu_multiple_issues_of_different_project | |
1088 | @request.session[:user_id] = 2 |
|
1093 | @request.session[:user_id] = 2 | |
1089 | get :context_menu, :ids => [1, 2, 4] |
|
1094 | get :context_menu, :ids => [1, 2, 4] | |
1090 | assert_response :success |
|
1095 | assert_response :success | |
1091 | assert_template 'context_menu' |
|
1096 | assert_template 'context_menu' | |
1092 | assert_tag :tag => 'a', :content => 'Delete', |
|
1097 | assert_tag :tag => 'a', :content => 'Delete', | |
1093 | :attributes => { :href => '#', |
|
1098 | :attributes => { :href => '#', | |
1094 | :class => 'icon-del disabled' } |
|
1099 | :class => 'icon-del disabled' } | |
1095 | end |
|
1100 | end | |
1096 |
|
1101 | |||
1097 | def test_destroy_routing |
|
1102 | def test_destroy_routing | |
1098 | assert_recognizes( #TODO: use DELETE on issue URI (need to change forms) |
|
1103 | assert_recognizes( #TODO: use DELETE on issue URI (need to change forms) | |
1099 | {:controller => 'issues', :action => 'destroy', :id => '1'}, |
|
1104 | {:controller => 'issues', :action => 'destroy', :id => '1'}, | |
1100 | {:method => :post, :path => '/issues/1/destroy'} |
|
1105 | {:method => :post, :path => '/issues/1/destroy'} | |
1101 | ) |
|
1106 | ) | |
1102 | end |
|
1107 | end | |
1103 |
|
1108 | |||
1104 | def test_destroy_issue_with_no_time_entries |
|
1109 | def test_destroy_issue_with_no_time_entries | |
1105 | assert_nil TimeEntry.find_by_issue_id(2) |
|
1110 | assert_nil TimeEntry.find_by_issue_id(2) | |
1106 | @request.session[:user_id] = 2 |
|
1111 | @request.session[:user_id] = 2 | |
1107 | post :destroy, :id => 2 |
|
1112 | post :destroy, :id => 2 | |
1108 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
1113 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
1109 | assert_nil Issue.find_by_id(2) |
|
1114 | assert_nil Issue.find_by_id(2) | |
1110 | end |
|
1115 | end | |
1111 |
|
1116 | |||
1112 | def test_destroy_issues_with_time_entries |
|
1117 | def test_destroy_issues_with_time_entries | |
1113 | @request.session[:user_id] = 2 |
|
1118 | @request.session[:user_id] = 2 | |
1114 | post :destroy, :ids => [1, 3] |
|
1119 | post :destroy, :ids => [1, 3] | |
1115 | assert_response :success |
|
1120 | assert_response :success | |
1116 | assert_template 'destroy' |
|
1121 | assert_template 'destroy' | |
1117 | assert_not_nil assigns(:hours) |
|
1122 | assert_not_nil assigns(:hours) | |
1118 | assert Issue.find_by_id(1) && Issue.find_by_id(3) |
|
1123 | assert Issue.find_by_id(1) && Issue.find_by_id(3) | |
1119 | end |
|
1124 | end | |
1120 |
|
1125 | |||
1121 | def test_destroy_issues_and_destroy_time_entries |
|
1126 | def test_destroy_issues_and_destroy_time_entries | |
1122 | @request.session[:user_id] = 2 |
|
1127 | @request.session[:user_id] = 2 | |
1123 | post :destroy, :ids => [1, 3], :todo => 'destroy' |
|
1128 | post :destroy, :ids => [1, 3], :todo => 'destroy' | |
1124 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
1129 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
1125 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) |
|
1130 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) | |
1126 | assert_nil TimeEntry.find_by_id([1, 2]) |
|
1131 | assert_nil TimeEntry.find_by_id([1, 2]) | |
1127 | end |
|
1132 | end | |
1128 |
|
1133 | |||
1129 | def test_destroy_issues_and_assign_time_entries_to_project |
|
1134 | def test_destroy_issues_and_assign_time_entries_to_project | |
1130 | @request.session[:user_id] = 2 |
|
1135 | @request.session[:user_id] = 2 | |
1131 | post :destroy, :ids => [1, 3], :todo => 'nullify' |
|
1136 | post :destroy, :ids => [1, 3], :todo => 'nullify' | |
1132 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
1137 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
1133 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) |
|
1138 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) | |
1134 | assert_nil TimeEntry.find(1).issue_id |
|
1139 | assert_nil TimeEntry.find(1).issue_id | |
1135 | assert_nil TimeEntry.find(2).issue_id |
|
1140 | assert_nil TimeEntry.find(2).issue_id | |
1136 | end |
|
1141 | end | |
1137 |
|
1142 | |||
1138 | def test_destroy_issues_and_reassign_time_entries_to_another_issue |
|
1143 | def test_destroy_issues_and_reassign_time_entries_to_another_issue | |
1139 | @request.session[:user_id] = 2 |
|
1144 | @request.session[:user_id] = 2 | |
1140 | post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2 |
|
1145 | post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2 | |
1141 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
1146 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
1142 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) |
|
1147 | assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) | |
1143 | assert_equal 2, TimeEntry.find(1).issue_id |
|
1148 | assert_equal 2, TimeEntry.find(1).issue_id | |
1144 | assert_equal 2, TimeEntry.find(2).issue_id |
|
1149 | assert_equal 2, TimeEntry.find(2).issue_id | |
1145 | end |
|
1150 | end | |
1146 |
|
1151 | |||
1147 | def test_default_search_scope |
|
1152 | def test_default_search_scope | |
1148 | get :index |
|
1153 | get :index | |
1149 | assert_tag :div, :attributes => {:id => 'quick-search'}, |
|
1154 | assert_tag :div, :attributes => {:id => 'quick-search'}, | |
1150 | :child => {:tag => 'form', |
|
1155 | :child => {:tag => 'form', | |
1151 | :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}} |
|
1156 | :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}} | |
1152 | end |
|
1157 | end | |
1153 | end |
|
1158 | end |
General Comments 0
You need to be logged in to leave comments.
Login now