##// END OF EJS Templates
Restored valid test part removed with r7625 (#8371)....
Etienne Massip -
r7507:78a875784620
parent child
Show More
@@ -1,1704 +1,1707
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19 require 'issues_controller'
19 require 'issues_controller'
20
20
21 class IssuesControllerTest < ActionController::TestCase
21 class IssuesControllerTest < ActionController::TestCase
22 fixtures :projects,
22 fixtures :projects,
23 :users,
23 :users,
24 :roles,
24 :roles,
25 :members,
25 :members,
26 :member_roles,
26 :member_roles,
27 :issues,
27 :issues,
28 :issue_statuses,
28 :issue_statuses,
29 :versions,
29 :versions,
30 :trackers,
30 :trackers,
31 :projects_trackers,
31 :projects_trackers,
32 :issue_categories,
32 :issue_categories,
33 :enabled_modules,
33 :enabled_modules,
34 :enumerations,
34 :enumerations,
35 :attachments,
35 :attachments,
36 :workflows,
36 :workflows,
37 :custom_fields,
37 :custom_fields,
38 :custom_values,
38 :custom_values,
39 :custom_fields_projects,
39 :custom_fields_projects,
40 :custom_fields_trackers,
40 :custom_fields_trackers,
41 :time_entries,
41 :time_entries,
42 :journals,
42 :journals,
43 :journal_details,
43 :journal_details,
44 :queries
44 :queries
45
45
46 def setup
46 def setup
47 @controller = IssuesController.new
47 @controller = IssuesController.new
48 @request = ActionController::TestRequest.new
48 @request = ActionController::TestRequest.new
49 @response = ActionController::TestResponse.new
49 @response = ActionController::TestResponse.new
50 User.current = nil
50 User.current = nil
51 end
51 end
52
52
53 def test_index
53 def test_index
54 Setting.default_language = 'en'
54 Setting.default_language = 'en'
55
55
56 get :index
56 get :index
57 assert_response :success
57 assert_response :success
58 assert_template 'index'
58 assert_template 'index'
59 assert_not_nil assigns(:issues)
59 assert_not_nil assigns(:issues)
60 assert_nil assigns(:project)
60 assert_nil assigns(:project)
61 assert_tag :tag => 'a', :content => /Can't print recipes/
61 assert_tag :tag => 'a', :content => /Can't print recipes/
62 assert_tag :tag => 'a', :content => /Subproject issue/
62 assert_tag :tag => 'a', :content => /Subproject issue/
63 # private projects hidden
63 # private projects hidden
64 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
64 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
65 assert_no_tag :tag => 'a', :content => /Issue on project 2/
65 assert_no_tag :tag => 'a', :content => /Issue on project 2/
66 # project column
66 # project column
67 assert_tag :tag => 'th', :content => /Project/
67 assert_tag :tag => 'th', :content => /Project/
68 end
68 end
69
69
70 def test_index_should_not_list_issues_when_module_disabled
70 def test_index_should_not_list_issues_when_module_disabled
71 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
71 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
72 get :index
72 get :index
73 assert_response :success
73 assert_response :success
74 assert_template 'index'
74 assert_template 'index'
75 assert_not_nil assigns(:issues)
75 assert_not_nil assigns(:issues)
76 assert_nil assigns(:project)
76 assert_nil assigns(:project)
77 assert_no_tag :tag => 'a', :content => /Can't print recipes/
77 assert_no_tag :tag => 'a', :content => /Can't print recipes/
78 assert_tag :tag => 'a', :content => /Subproject issue/
78 assert_tag :tag => 'a', :content => /Subproject issue/
79 end
79 end
80
80
81 def test_index_should_list_visible_issues_only
81 def test_index_should_list_visible_issues_only
82 get :index, :per_page => 100
82 get :index, :per_page => 100
83 assert_response :success
83 assert_response :success
84 assert_not_nil assigns(:issues)
84 assert_not_nil assigns(:issues)
85 assert_nil assigns(:issues).detect {|issue| !issue.visible?}
85 assert_nil assigns(:issues).detect {|issue| !issue.visible?}
86 end
86 end
87
87
88 def test_index_with_project
88 def test_index_with_project
89 Setting.display_subprojects_issues = 0
89 Setting.display_subprojects_issues = 0
90 get :index, :project_id => 1
90 get :index, :project_id => 1
91 assert_response :success
91 assert_response :success
92 assert_template 'index'
92 assert_template 'index'
93 assert_not_nil assigns(:issues)
93 assert_not_nil assigns(:issues)
94 assert_tag :tag => 'a', :content => /Can't print recipes/
94 assert_tag :tag => 'a', :content => /Can't print recipes/
95 assert_no_tag :tag => 'a', :content => /Subproject issue/
95 assert_no_tag :tag => 'a', :content => /Subproject issue/
96 end
96 end
97
97
98 def test_index_with_project_and_subprojects
98 def test_index_with_project_and_subprojects
99 Setting.display_subprojects_issues = 1
99 Setting.display_subprojects_issues = 1
100 get :index, :project_id => 1
100 get :index, :project_id => 1
101 assert_response :success
101 assert_response :success
102 assert_template 'index'
102 assert_template 'index'
103 assert_not_nil assigns(:issues)
103 assert_not_nil assigns(:issues)
104 assert_tag :tag => 'a', :content => /Can't print recipes/
104 assert_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 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
106 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
107 end
107 end
108
108
109 def test_index_with_project_and_subprojects_should_show_private_subprojects
109 def test_index_with_project_and_subprojects_should_show_private_subprojects
110 @request.session[:user_id] = 2
110 @request.session[:user_id] = 2
111 Setting.display_subprojects_issues = 1
111 Setting.display_subprojects_issues = 1
112 get :index, :project_id => 1
112 get :index, :project_id => 1
113 assert_response :success
113 assert_response :success
114 assert_template 'index'
114 assert_template 'index'
115 assert_not_nil assigns(:issues)
115 assert_not_nil assigns(:issues)
116 assert_tag :tag => 'a', :content => /Can't print recipes/
116 assert_tag :tag => 'a', :content => /Can't print recipes/
117 assert_tag :tag => 'a', :content => /Subproject issue/
117 assert_tag :tag => 'a', :content => /Subproject issue/
118 assert_tag :tag => 'a', :content => /Issue of a private subproject/
118 assert_tag :tag => 'a', :content => /Issue of a private subproject/
119 end
119 end
120
120
121 def test_index_with_project_and_default_filter
121 def test_index_with_project_and_default_filter
122 get :index, :project_id => 1, :set_filter => 1
122 get :index, :project_id => 1, :set_filter => 1
123 assert_response :success
123 assert_response :success
124 assert_template 'index'
124 assert_template 'index'
125 assert_not_nil assigns(:issues)
125 assert_not_nil assigns(:issues)
126
126
127 query = assigns(:query)
127 query = assigns(:query)
128 assert_not_nil query
128 assert_not_nil query
129 # default filter
129 # default filter
130 assert_equal({'status_id' => {:operator => 'o', :values => ['']}}, query.filters)
130 assert_equal({'status_id' => {:operator => 'o', :values => ['']}}, query.filters)
131 end
131 end
132
132
133 def test_index_with_project_and_filter
133 def test_index_with_project_and_filter
134 get :index, :project_id => 1, :set_filter => 1,
134 get :index, :project_id => 1, :set_filter => 1,
135 :f => ['tracker_id'],
135 :f => ['tracker_id'],
136 :op => {'tracker_id' => '='},
136 :op => {'tracker_id' => '='},
137 :v => {'tracker_id' => ['1']}
137 :v => {'tracker_id' => ['1']}
138 assert_response :success
138 assert_response :success
139 assert_template 'index'
139 assert_template 'index'
140 assert_not_nil assigns(:issues)
140 assert_not_nil assigns(:issues)
141
141
142 query = assigns(:query)
142 query = assigns(:query)
143 assert_not_nil query
143 assert_not_nil query
144 assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters)
144 assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters)
145 end
145 end
146
146
147 def test_index_with_short_filters
147 def test_index_with_short_filters
148
148
149 to_test = {
149 to_test = {
150 'status_id' => {
150 'status_id' => {
151 'o' => { :op => 'o', :values => [''] },
151 'o' => { :op => 'o', :values => [''] },
152 'c' => { :op => 'c', :values => [''] },
152 'c' => { :op => 'c', :values => [''] },
153 '7' => { :op => '=', :values => ['7'] },
153 '7' => { :op => '=', :values => ['7'] },
154 '7|3|4' => { :op => '=', :values => ['7', '3', '4'] },
154 '7|3|4' => { :op => '=', :values => ['7', '3', '4'] },
155 '=7' => { :op => '=', :values => ['7'] },
155 '=7' => { :op => '=', :values => ['7'] },
156 '!3' => { :op => '!', :values => ['3'] },
156 '!3' => { :op => '!', :values => ['3'] },
157 '!7|3|4' => { :op => '!', :values => ['7', '3', '4'] }},
157 '!7|3|4' => { :op => '!', :values => ['7', '3', '4'] }},
158 'subject' => {
158 'subject' => {
159 'This is a subject' => { :op => '=', :values => ['This is a subject'] },
159 'This is a subject' => { :op => '=', :values => ['This is a subject'] },
160 'o' => { :op => '=', :values => ['o'] },
160 'o' => { :op => '=', :values => ['o'] },
161 '~This is part of a subject' => { :op => '~', :values => ['This is part of a subject'] },
161 '~This is part of a subject' => { :op => '~', :values => ['This is part of a subject'] },
162 '!~This is part of a subject' => { :op => '!~', :values => ['This is part of a subject'] }},
162 '!~This is part of a subject' => { :op => '!~', :values => ['This is part of a subject'] }},
163 'tracker_id' => {
164 '3' => { :op => '=', :values => ['3'] },
165 '=3' => { :op => '=', :values => ['3'] }},
163 'start_date' => {
166 'start_date' => {
164 '2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
167 '2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
165 '=2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
168 '=2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
166 '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
169 '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
167 '<=2011-10-12' => { :op => '<=', :values => ['2011-10-12'] },
170 '<=2011-10-12' => { :op => '<=', :values => ['2011-10-12'] },
168 '><2011-10-01|2011-10-30' => { :op => '><', :values => ['2011-10-01', '2011-10-30'] },
171 '><2011-10-01|2011-10-30' => { :op => '><', :values => ['2011-10-01', '2011-10-30'] },
169 '<t+2' => { :op => '<t+', :values => ['2'] },
172 '<t+2' => { :op => '<t+', :values => ['2'] },
170 '>t+2' => { :op => '>t+', :values => ['2'] },
173 '>t+2' => { :op => '>t+', :values => ['2'] },
171 't+2' => { :op => 't+', :values => ['2'] },
174 't+2' => { :op => 't+', :values => ['2'] },
172 't' => { :op => 't', :values => [''] },
175 't' => { :op => 't', :values => [''] },
173 'w' => { :op => 'w', :values => [''] },
176 'w' => { :op => 'w', :values => [''] },
174 '>t-2' => { :op => '>t-', :values => ['2'] },
177 '>t-2' => { :op => '>t-', :values => ['2'] },
175 '<t-2' => { :op => '<t-', :values => ['2'] },
178 '<t-2' => { :op => '<t-', :values => ['2'] },
176 't-2' => { :op => 't-', :values => ['2'] }},
179 't-2' => { :op => 't-', :values => ['2'] }},
177 'created_on' => {
180 'created_on' => {
178 '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
181 '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
179 '<t+2' => { :op => '=', :values => ['<t+2'] },
182 '<t+2' => { :op => '=', :values => ['<t+2'] },
180 '>t+2' => { :op => '=', :values => ['>t+2'] },
183 '>t+2' => { :op => '=', :values => ['>t+2'] },
181 't+2' => { :op => 't', :values => ['+2'] }},
184 't+2' => { :op => 't', :values => ['+2'] }},
182 'cf_1' => {
185 'cf_1' => {
183 'c' => { :op => '=', :values => ['c'] },
186 'c' => { :op => '=', :values => ['c'] },
184 '!c' => { :op => '!', :values => ['c'] },
187 '!c' => { :op => '!', :values => ['c'] },
185 '!*' => { :op => '!*', :values => [''] },
188 '!*' => { :op => '!*', :values => [''] },
186 '*' => { :op => '*', :values => [''] }},
189 '*' => { :op => '*', :values => [''] }},
187 'estimated_hours' => {
190 'estimated_hours' => {
188 '=13.4' => { :op => '=', :values => ['13.4'] },
191 '=13.4' => { :op => '=', :values => ['13.4'] },
189 '>=45' => { :op => '>=', :values => ['45'] },
192 '>=45' => { :op => '>=', :values => ['45'] },
190 '<=125' => { :op => '<=', :values => ['125'] },
193 '<=125' => { :op => '<=', :values => ['125'] },
191 '><10.5|20.5' => { :op => '><', :values => ['10.5', '20.5'] },
194 '><10.5|20.5' => { :op => '><', :values => ['10.5', '20.5'] },
192 '!*' => { :op => '!*', :values => [''] },
195 '!*' => { :op => '!*', :values => [''] },
193 '*' => { :op => '*', :values => [''] }}
196 '*' => { :op => '*', :values => [''] }}
194 }
197 }
195
198
196 default_filter = { 'status_id' => {:operator => 'o', :values => [''] }}
199 default_filter = { 'status_id' => {:operator => 'o', :values => [''] }}
197
200
198 to_test.each do |field, expression_and_expected|
201 to_test.each do |field, expression_and_expected|
199 expression_and_expected.each do |filter_expression, expected|
202 expression_and_expected.each do |filter_expression, expected|
200
203
201 get :index, :set_filter => 1, field => filter_expression
204 get :index, :set_filter => 1, field => filter_expression
202
205
203 assert_response :success
206 assert_response :success
204 assert_template 'index'
207 assert_template 'index'
205 assert_not_nil assigns(:issues)
208 assert_not_nil assigns(:issues)
206
209
207 query = assigns(:query)
210 query = assigns(:query)
208 assert_not_nil query
211 assert_not_nil query
209 assert query.has_filter?(field)
212 assert query.has_filter?(field)
210 assert_equal(default_filter.merge({field => {:operator => expected[:op], :values => expected[:values]}}), query.filters)
213 assert_equal(default_filter.merge({field => {:operator => expected[:op], :values => expected[:values]}}), query.filters)
211 end
214 end
212 end
215 end
213
216
214 end
217 end
215
218
216 def test_index_with_project_and_empty_filters
219 def test_index_with_project_and_empty_filters
217 get :index, :project_id => 1, :set_filter => 1, :fields => ['']
220 get :index, :project_id => 1, :set_filter => 1, :fields => ['']
218 assert_response :success
221 assert_response :success
219 assert_template 'index'
222 assert_template 'index'
220 assert_not_nil assigns(:issues)
223 assert_not_nil assigns(:issues)
221
224
222 query = assigns(:query)
225 query = assigns(:query)
223 assert_not_nil query
226 assert_not_nil query
224 # no filter
227 # no filter
225 assert_equal({}, query.filters)
228 assert_equal({}, query.filters)
226 end
229 end
227
230
228 def test_index_with_query
231 def test_index_with_query
229 get :index, :project_id => 1, :query_id => 5
232 get :index, :project_id => 1, :query_id => 5
230 assert_response :success
233 assert_response :success
231 assert_template 'index'
234 assert_template 'index'
232 assert_not_nil assigns(:issues)
235 assert_not_nil assigns(:issues)
233 assert_nil assigns(:issue_count_by_group)
236 assert_nil assigns(:issue_count_by_group)
234 end
237 end
235
238
236 def test_index_with_query_grouped_by_tracker
239 def test_index_with_query_grouped_by_tracker
237 get :index, :project_id => 1, :query_id => 6
240 get :index, :project_id => 1, :query_id => 6
238 assert_response :success
241 assert_response :success
239 assert_template 'index'
242 assert_template 'index'
240 assert_not_nil assigns(:issues)
243 assert_not_nil assigns(:issues)
241 assert_not_nil assigns(:issue_count_by_group)
244 assert_not_nil assigns(:issue_count_by_group)
242 end
245 end
243
246
244 def test_index_with_query_grouped_by_list_custom_field
247 def test_index_with_query_grouped_by_list_custom_field
245 get :index, :project_id => 1, :query_id => 9
248 get :index, :project_id => 1, :query_id => 9
246 assert_response :success
249 assert_response :success
247 assert_template 'index'
250 assert_template 'index'
248 assert_not_nil assigns(:issues)
251 assert_not_nil assigns(:issues)
249 assert_not_nil assigns(:issue_count_by_group)
252 assert_not_nil assigns(:issue_count_by_group)
250 end
253 end
251
254
252 def test_private_query_should_not_be_available_to_other_users
255 def test_private_query_should_not_be_available_to_other_users
253 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil)
256 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil)
254 @request.session[:user_id] = 3
257 @request.session[:user_id] = 3
255
258
256 get :index, :query_id => q.id
259 get :index, :query_id => q.id
257 assert_response 403
260 assert_response 403
258 end
261 end
259
262
260 def test_private_query_should_be_available_to_its_user
263 def test_private_query_should_be_available_to_its_user
261 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil)
264 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil)
262 @request.session[:user_id] = 2
265 @request.session[:user_id] = 2
263
266
264 get :index, :query_id => q.id
267 get :index, :query_id => q.id
265 assert_response :success
268 assert_response :success
266 end
269 end
267
270
268 def test_public_query_should_be_available_to_other_users
271 def test_public_query_should_be_available_to_other_users
269 q = Query.create!(:name => "private", :user => User.find(2), :is_public => true, :project => nil)
272 q = Query.create!(:name => "private", :user => User.find(2), :is_public => true, :project => nil)
270 @request.session[:user_id] = 3
273 @request.session[:user_id] = 3
271
274
272 get :index, :query_id => q.id
275 get :index, :query_id => q.id
273 assert_response :success
276 assert_response :success
274 end
277 end
275
278
276 def test_index_sort_by_field_not_included_in_columns
279 def test_index_sort_by_field_not_included_in_columns
277 Setting.issue_list_default_columns = %w(subject author)
280 Setting.issue_list_default_columns = %w(subject author)
278 get :index, :sort => 'tracker'
281 get :index, :sort => 'tracker'
279 end
282 end
280
283
281 def test_index_csv_with_project
284 def test_index_csv_with_project
282 Setting.default_language = 'en'
285 Setting.default_language = 'en'
283
286
284 get :index, :format => 'csv'
287 get :index, :format => 'csv'
285 assert_response :success
288 assert_response :success
286 assert_not_nil assigns(:issues)
289 assert_not_nil assigns(:issues)
287 assert_equal 'text/csv', @response.content_type
290 assert_equal 'text/csv', @response.content_type
288 assert @response.body.starts_with?("#,")
291 assert @response.body.starts_with?("#,")
289
292
290 get :index, :project_id => 1, :format => 'csv'
293 get :index, :project_id => 1, :format => 'csv'
291 assert_response :success
294 assert_response :success
292 assert_not_nil assigns(:issues)
295 assert_not_nil assigns(:issues)
293 assert_equal 'text/csv', @response.content_type
296 assert_equal 'text/csv', @response.content_type
294 end
297 end
295
298
296 def test_index_pdf
299 def test_index_pdf
297 get :index, :format => 'pdf'
300 get :index, :format => 'pdf'
298 assert_response :success
301 assert_response :success
299 assert_not_nil assigns(:issues)
302 assert_not_nil assigns(:issues)
300 assert_equal 'application/pdf', @response.content_type
303 assert_equal 'application/pdf', @response.content_type
301
304
302 get :index, :project_id => 1, :format => 'pdf'
305 get :index, :project_id => 1, :format => 'pdf'
303 assert_response :success
306 assert_response :success
304 assert_not_nil assigns(:issues)
307 assert_not_nil assigns(:issues)
305 assert_equal 'application/pdf', @response.content_type
308 assert_equal 'application/pdf', @response.content_type
306
309
307 get :index, :project_id => 1, :query_id => 6, :format => 'pdf'
310 get :index, :project_id => 1, :query_id => 6, :format => 'pdf'
308 assert_response :success
311 assert_response :success
309 assert_not_nil assigns(:issues)
312 assert_not_nil assigns(:issues)
310 assert_equal 'application/pdf', @response.content_type
313 assert_equal 'application/pdf', @response.content_type
311 end
314 end
312
315
313 def test_index_pdf_with_query_grouped_by_list_custom_field
316 def test_index_pdf_with_query_grouped_by_list_custom_field
314 get :index, :project_id => 1, :query_id => 9, :format => 'pdf'
317 get :index, :project_id => 1, :query_id => 9, :format => 'pdf'
315 assert_response :success
318 assert_response :success
316 assert_not_nil assigns(:issues)
319 assert_not_nil assigns(:issues)
317 assert_not_nil assigns(:issue_count_by_group)
320 assert_not_nil assigns(:issue_count_by_group)
318 assert_equal 'application/pdf', @response.content_type
321 assert_equal 'application/pdf', @response.content_type
319 end
322 end
320
323
321 def test_index_sort
324 def test_index_sort
322 get :index, :sort => 'tracker,id:desc'
325 get :index, :sort => 'tracker,id:desc'
323 assert_response :success
326 assert_response :success
324
327
325 sort_params = @request.session['issues_index_sort']
328 sort_params = @request.session['issues_index_sort']
326 assert sort_params.is_a?(String)
329 assert sort_params.is_a?(String)
327 assert_equal 'tracker,id:desc', sort_params
330 assert_equal 'tracker,id:desc', sort_params
328
331
329 issues = assigns(:issues)
332 issues = assigns(:issues)
330 assert_not_nil issues
333 assert_not_nil issues
331 assert !issues.empty?
334 assert !issues.empty?
332 assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
335 assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
333 end
336 end
334
337
335 def test_index_with_columns
338 def test_index_with_columns
336 columns = ['tracker', 'subject', 'assigned_to']
339 columns = ['tracker', 'subject', 'assigned_to']
337 get :index, :set_filter => 1, :c => columns
340 get :index, :set_filter => 1, :c => columns
338 assert_response :success
341 assert_response :success
339
342
340 # query should use specified columns
343 # query should use specified columns
341 query = assigns(:query)
344 query = assigns(:query)
342 assert_kind_of Query, query
345 assert_kind_of Query, query
343 assert_equal columns, query.column_names.map(&:to_s)
346 assert_equal columns, query.column_names.map(&:to_s)
344
347
345 # columns should be stored in session
348 # columns should be stored in session
346 assert_kind_of Hash, session[:query]
349 assert_kind_of Hash, session[:query]
347 assert_kind_of Array, session[:query][:column_names]
350 assert_kind_of Array, session[:query][:column_names]
348 assert_equal columns, session[:query][:column_names].map(&:to_s)
351 assert_equal columns, session[:query][:column_names].map(&:to_s)
349
352
350 # ensure only these columns are kept in the selected columns list
353 # ensure only these columns are kept in the selected columns list
351 assert_tag :tag => 'select', :attributes => { :id => 'selected_columns' },
354 assert_tag :tag => 'select', :attributes => { :id => 'selected_columns' },
352 :children => { :count => 3 }
355 :children => { :count => 3 }
353 assert_no_tag :tag => 'option', :attributes => { :value => 'project' },
356 assert_no_tag :tag => 'option', :attributes => { :value => 'project' },
354 :parent => { :tag => 'select', :attributes => { :id => "selected_columns" } }
357 :parent => { :tag => 'select', :attributes => { :id => "selected_columns" } }
355 end
358 end
356
359
357 def test_index_without_project_should_implicitly_add_project_column_to_default_columns
360 def test_index_without_project_should_implicitly_add_project_column_to_default_columns
358 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
361 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
359 get :index, :set_filter => 1
362 get :index, :set_filter => 1
360
363
361 # query should use specified columns
364 # query should use specified columns
362 query = assigns(:query)
365 query = assigns(:query)
363 assert_kind_of Query, query
366 assert_kind_of Query, query
364 assert_equal [:project, :tracker, :subject, :assigned_to], query.columns.map(&:name)
367 assert_equal [:project, :tracker, :subject, :assigned_to], query.columns.map(&:name)
365 end
368 end
366
369
367 def test_index_without_project_and_explicit_default_columns_should_not_add_project_column
370 def test_index_without_project_and_explicit_default_columns_should_not_add_project_column
368 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
371 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
369 columns = ['tracker', 'subject', 'assigned_to']
372 columns = ['tracker', 'subject', 'assigned_to']
370 get :index, :set_filter => 1, :c => columns
373 get :index, :set_filter => 1, :c => columns
371
374
372 # query should use specified columns
375 # query should use specified columns
373 query = assigns(:query)
376 query = assigns(:query)
374 assert_kind_of Query, query
377 assert_kind_of Query, query
375 assert_equal columns.map(&:to_sym), query.columns.map(&:name)
378 assert_equal columns.map(&:to_sym), query.columns.map(&:name)
376 end
379 end
377
380
378 def test_index_with_custom_field_column
381 def test_index_with_custom_field_column
379 columns = %w(tracker subject cf_2)
382 columns = %w(tracker subject cf_2)
380 get :index, :set_filter => 1, :c => columns
383 get :index, :set_filter => 1, :c => columns
381 assert_response :success
384 assert_response :success
382
385
383 # query should use specified columns
386 # query should use specified columns
384 query = assigns(:query)
387 query = assigns(:query)
385 assert_kind_of Query, query
388 assert_kind_of Query, query
386 assert_equal columns, query.column_names.map(&:to_s)
389 assert_equal columns, query.column_names.map(&:to_s)
387
390
388 assert_tag :td,
391 assert_tag :td,
389 :attributes => {:class => 'cf_2 string'},
392 :attributes => {:class => 'cf_2 string'},
390 :ancestor => {:tag => 'table', :attributes => {:class => /issues/}}
393 :ancestor => {:tag => 'table', :attributes => {:class => /issues/}}
391 end
394 end
392
395
393 def test_index_send_html_if_query_is_invalid
396 def test_index_send_html_if_query_is_invalid
394 get :index, :f => ['start_date'], :op => {:start_date => '='}
397 get :index, :f => ['start_date'], :op => {:start_date => '='}
395 assert_equal 'text/html', @response.content_type
398 assert_equal 'text/html', @response.content_type
396 assert_template 'index'
399 assert_template 'index'
397 end
400 end
398
401
399 def test_index_send_nothing_if_query_is_invalid
402 def test_index_send_nothing_if_query_is_invalid
400 get :index, :f => ['start_date'], :op => {:start_date => '='}, :format => 'csv'
403 get :index, :f => ['start_date'], :op => {:start_date => '='}, :format => 'csv'
401 assert_equal 'text/csv', @response.content_type
404 assert_equal 'text/csv', @response.content_type
402 assert @response.body.blank?
405 assert @response.body.blank?
403 end
406 end
404
407
405 def test_show_by_anonymous
408 def test_show_by_anonymous
406 get :show, :id => 1
409 get :show, :id => 1
407 assert_response :success
410 assert_response :success
408 assert_template 'show'
411 assert_template 'show'
409 assert_not_nil assigns(:issue)
412 assert_not_nil assigns(:issue)
410 assert_equal Issue.find(1), assigns(:issue)
413 assert_equal Issue.find(1), assigns(:issue)
411
414
412 # anonymous role is allowed to add a note
415 # anonymous role is allowed to add a note
413 assert_tag :tag => 'form',
416 assert_tag :tag => 'form',
414 :descendant => { :tag => 'fieldset',
417 :descendant => { :tag => 'fieldset',
415 :child => { :tag => 'legend',
418 :child => { :tag => 'legend',
416 :content => /Notes/ } }
419 :content => /Notes/ } }
417 end
420 end
418
421
419 def test_show_by_manager
422 def test_show_by_manager
420 @request.session[:user_id] = 2
423 @request.session[:user_id] = 2
421 get :show, :id => 1
424 get :show, :id => 1
422 assert_response :success
425 assert_response :success
423
426
424 assert_tag :tag => 'a',
427 assert_tag :tag => 'a',
425 :content => /Quote/
428 :content => /Quote/
426
429
427 assert_tag :tag => 'form',
430 assert_tag :tag => 'form',
428 :descendant => { :tag => 'fieldset',
431 :descendant => { :tag => 'fieldset',
429 :child => { :tag => 'legend',
432 :child => { :tag => 'legend',
430 :content => /Change properties/ } },
433 :content => /Change properties/ } },
431 :descendant => { :tag => 'fieldset',
434 :descendant => { :tag => 'fieldset',
432 :child => { :tag => 'legend',
435 :child => { :tag => 'legend',
433 :content => /Log time/ } },
436 :content => /Log time/ } },
434 :descendant => { :tag => 'fieldset',
437 :descendant => { :tag => 'fieldset',
435 :child => { :tag => 'legend',
438 :child => { :tag => 'legend',
436 :content => /Notes/ } }
439 :content => /Notes/ } }
437 end
440 end
438
441
439 def test_update_form_should_not_display_inactive_enumerations
442 def test_update_form_should_not_display_inactive_enumerations
440 @request.session[:user_id] = 2
443 @request.session[:user_id] = 2
441 get :show, :id => 1
444 get :show, :id => 1
442 assert_response :success
445 assert_response :success
443
446
444 assert ! IssuePriority.find(15).active?
447 assert ! IssuePriority.find(15).active?
445 assert_no_tag :option, :attributes => {:value => '15'},
448 assert_no_tag :option, :attributes => {:value => '15'},
446 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
449 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
447 end
450 end
448
451
449 def test_update_form_should_allow_attachment_upload
452 def test_update_form_should_allow_attachment_upload
450 @request.session[:user_id] = 2
453 @request.session[:user_id] = 2
451 get :show, :id => 1
454 get :show, :id => 1
452
455
453 assert_tag :tag => 'form',
456 assert_tag :tag => 'form',
454 :attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'},
457 :attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'},
455 :descendant => {
458 :descendant => {
456 :tag => 'input',
459 :tag => 'input',
457 :attributes => {:type => 'file', :name => 'attachments[1][file]'}
460 :attributes => {:type => 'file', :name => 'attachments[1][file]'}
458 }
461 }
459 end
462 end
460
463
461 def test_show_should_deny_anonymous_access_without_permission
464 def test_show_should_deny_anonymous_access_without_permission
462 Role.anonymous.remove_permission!(:view_issues)
465 Role.anonymous.remove_permission!(:view_issues)
463 get :show, :id => 1
466 get :show, :id => 1
464 assert_response :redirect
467 assert_response :redirect
465 end
468 end
466
469
467 def test_show_should_deny_anonymous_access_to_private_issue
470 def test_show_should_deny_anonymous_access_to_private_issue
468 Issue.update_all(["is_private = ?", true], "id = 1")
471 Issue.update_all(["is_private = ?", true], "id = 1")
469 get :show, :id => 1
472 get :show, :id => 1
470 assert_response :redirect
473 assert_response :redirect
471 end
474 end
472
475
473 def test_show_should_deny_non_member_access_without_permission
476 def test_show_should_deny_non_member_access_without_permission
474 Role.non_member.remove_permission!(:view_issues)
477 Role.non_member.remove_permission!(:view_issues)
475 @request.session[:user_id] = 9
478 @request.session[:user_id] = 9
476 get :show, :id => 1
479 get :show, :id => 1
477 assert_response 403
480 assert_response 403
478 end
481 end
479
482
480 def test_show_should_deny_non_member_access_to_private_issue
483 def test_show_should_deny_non_member_access_to_private_issue
481 Issue.update_all(["is_private = ?", true], "id = 1")
484 Issue.update_all(["is_private = ?", true], "id = 1")
482 @request.session[:user_id] = 9
485 @request.session[:user_id] = 9
483 get :show, :id => 1
486 get :show, :id => 1
484 assert_response 403
487 assert_response 403
485 end
488 end
486
489
487 def test_show_should_deny_member_access_without_permission
490 def test_show_should_deny_member_access_without_permission
488 Role.find(1).remove_permission!(:view_issues)
491 Role.find(1).remove_permission!(:view_issues)
489 @request.session[:user_id] = 2
492 @request.session[:user_id] = 2
490 get :show, :id => 1
493 get :show, :id => 1
491 assert_response 403
494 assert_response 403
492 end
495 end
493
496
494 def test_show_should_deny_member_access_to_private_issue_without_permission
497 def test_show_should_deny_member_access_to_private_issue_without_permission
495 Issue.update_all(["is_private = ?", true], "id = 1")
498 Issue.update_all(["is_private = ?", true], "id = 1")
496 @request.session[:user_id] = 3
499 @request.session[:user_id] = 3
497 get :show, :id => 1
500 get :show, :id => 1
498 assert_response 403
501 assert_response 403
499 end
502 end
500
503
501 def test_show_should_allow_author_access_to_private_issue
504 def test_show_should_allow_author_access_to_private_issue
502 Issue.update_all(["is_private = ?, author_id = 3", true], "id = 1")
505 Issue.update_all(["is_private = ?, author_id = 3", true], "id = 1")
503 @request.session[:user_id] = 3
506 @request.session[:user_id] = 3
504 get :show, :id => 1
507 get :show, :id => 1
505 assert_response :success
508 assert_response :success
506 end
509 end
507
510
508 def test_show_should_allow_assignee_access_to_private_issue
511 def test_show_should_allow_assignee_access_to_private_issue
509 Issue.update_all(["is_private = ?, assigned_to_id = 3", true], "id = 1")
512 Issue.update_all(["is_private = ?, assigned_to_id = 3", true], "id = 1")
510 @request.session[:user_id] = 3
513 @request.session[:user_id] = 3
511 get :show, :id => 1
514 get :show, :id => 1
512 assert_response :success
515 assert_response :success
513 end
516 end
514
517
515 def test_show_should_allow_member_access_to_private_issue_with_permission
518 def test_show_should_allow_member_access_to_private_issue_with_permission
516 Issue.update_all(["is_private = ?", true], "id = 1")
519 Issue.update_all(["is_private = ?", true], "id = 1")
517 User.find(3).roles_for_project(Project.find(1)).first.update_attribute :issues_visibility, 'all'
520 User.find(3).roles_for_project(Project.find(1)).first.update_attribute :issues_visibility, 'all'
518 @request.session[:user_id] = 3
521 @request.session[:user_id] = 3
519 get :show, :id => 1
522 get :show, :id => 1
520 assert_response :success
523 assert_response :success
521 end
524 end
522
525
523 def test_show_should_not_disclose_relations_to_invisible_issues
526 def test_show_should_not_disclose_relations_to_invisible_issues
524 Setting.cross_project_issue_relations = '1'
527 Setting.cross_project_issue_relations = '1'
525 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates')
528 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates')
526 # Relation to a private project issue
529 # Relation to a private project issue
527 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates')
530 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates')
528
531
529 get :show, :id => 1
532 get :show, :id => 1
530 assert_response :success
533 assert_response :success
531
534
532 assert_tag :div, :attributes => { :id => 'relations' },
535 assert_tag :div, :attributes => { :id => 'relations' },
533 :descendant => { :tag => 'a', :content => /#2$/ }
536 :descendant => { :tag => 'a', :content => /#2$/ }
534 assert_no_tag :div, :attributes => { :id => 'relations' },
537 assert_no_tag :div, :attributes => { :id => 'relations' },
535 :descendant => { :tag => 'a', :content => /#4$/ }
538 :descendant => { :tag => 'a', :content => /#4$/ }
536 end
539 end
537
540
538 def test_show_atom
541 def test_show_atom
539 get :show, :id => 2, :format => 'atom'
542 get :show, :id => 2, :format => 'atom'
540 assert_response :success
543 assert_response :success
541 assert_template 'journals/index'
544 assert_template 'journals/index'
542 # Inline image
545 # Inline image
543 assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10'))
546 assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10'))
544 end
547 end
545
548
546 def test_show_export_to_pdf
549 def test_show_export_to_pdf
547 get :show, :id => 3, :format => 'pdf'
550 get :show, :id => 3, :format => 'pdf'
548 assert_response :success
551 assert_response :success
549 assert_equal 'application/pdf', @response.content_type
552 assert_equal 'application/pdf', @response.content_type
550 assert @response.body.starts_with?('%PDF')
553 assert @response.body.starts_with?('%PDF')
551 assert_not_nil assigns(:issue)
554 assert_not_nil assigns(:issue)
552 end
555 end
553
556
554 def test_get_new
557 def test_get_new
555 @request.session[:user_id] = 2
558 @request.session[:user_id] = 2
556 get :new, :project_id => 1, :tracker_id => 1
559 get :new, :project_id => 1, :tracker_id => 1
557 assert_response :success
560 assert_response :success
558 assert_template 'new'
561 assert_template 'new'
559
562
560 assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]',
563 assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]',
561 :value => 'Default string' }
564 :value => 'Default string' }
562
565
563 # Be sure we don't display inactive IssuePriorities
566 # Be sure we don't display inactive IssuePriorities
564 assert ! IssuePriority.find(15).active?
567 assert ! IssuePriority.find(15).active?
565 assert_no_tag :option, :attributes => {:value => '15'},
568 assert_no_tag :option, :attributes => {:value => '15'},
566 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
569 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
567 end
570 end
568
571
569 def test_get_new_form_should_allow_attachment_upload
572 def test_get_new_form_should_allow_attachment_upload
570 @request.session[:user_id] = 2
573 @request.session[:user_id] = 2
571 get :new, :project_id => 1, :tracker_id => 1
574 get :new, :project_id => 1, :tracker_id => 1
572
575
573 assert_tag :tag => 'form',
576 assert_tag :tag => 'form',
574 :attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'},
577 :attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'},
575 :descendant => {
578 :descendant => {
576 :tag => 'input',
579 :tag => 'input',
577 :attributes => {:type => 'file', :name => 'attachments[1][file]'}
580 :attributes => {:type => 'file', :name => 'attachments[1][file]'}
578 }
581 }
579 end
582 end
580
583
581 def test_get_new_without_tracker_id
584 def test_get_new_without_tracker_id
582 @request.session[:user_id] = 2
585 @request.session[:user_id] = 2
583 get :new, :project_id => 1
586 get :new, :project_id => 1
584 assert_response :success
587 assert_response :success
585 assert_template 'new'
588 assert_template 'new'
586
589
587 issue = assigns(:issue)
590 issue = assigns(:issue)
588 assert_not_nil issue
591 assert_not_nil issue
589 assert_equal Project.find(1).trackers.first, issue.tracker
592 assert_equal Project.find(1).trackers.first, issue.tracker
590 end
593 end
591
594
592 def test_get_new_with_no_default_status_should_display_an_error
595 def test_get_new_with_no_default_status_should_display_an_error
593 @request.session[:user_id] = 2
596 @request.session[:user_id] = 2
594 IssueStatus.delete_all
597 IssueStatus.delete_all
595
598
596 get :new, :project_id => 1
599 get :new, :project_id => 1
597 assert_response 500
600 assert_response 500
598 assert_error_tag :content => /No default issue/
601 assert_error_tag :content => /No default issue/
599 end
602 end
600
603
601 def test_get_new_with_no_tracker_should_display_an_error
604 def test_get_new_with_no_tracker_should_display_an_error
602 @request.session[:user_id] = 2
605 @request.session[:user_id] = 2
603 Tracker.delete_all
606 Tracker.delete_all
604
607
605 get :new, :project_id => 1
608 get :new, :project_id => 1
606 assert_response 500
609 assert_response 500
607 assert_error_tag :content => /No tracker/
610 assert_error_tag :content => /No tracker/
608 end
611 end
609
612
610 def test_update_new_form
613 def test_update_new_form
611 @request.session[:user_id] = 2
614 @request.session[:user_id] = 2
612 xhr :post, :new, :project_id => 1,
615 xhr :post, :new, :project_id => 1,
613 :issue => {:tracker_id => 2,
616 :issue => {:tracker_id => 2,
614 :subject => 'This is the test_new issue',
617 :subject => 'This is the test_new issue',
615 :description => 'This is the description',
618 :description => 'This is the description',
616 :priority_id => 5}
619 :priority_id => 5}
617 assert_response :success
620 assert_response :success
618 assert_template 'attributes'
621 assert_template 'attributes'
619
622
620 issue = assigns(:issue)
623 issue = assigns(:issue)
621 assert_kind_of Issue, issue
624 assert_kind_of Issue, issue
622 assert_equal 1, issue.project_id
625 assert_equal 1, issue.project_id
623 assert_equal 2, issue.tracker_id
626 assert_equal 2, issue.tracker_id
624 assert_equal 'This is the test_new issue', issue.subject
627 assert_equal 'This is the test_new issue', issue.subject
625 end
628 end
626
629
627 def test_post_create
630 def test_post_create
628 @request.session[:user_id] = 2
631 @request.session[:user_id] = 2
629 assert_difference 'Issue.count' do
632 assert_difference 'Issue.count' do
630 post :create, :project_id => 1,
633 post :create, :project_id => 1,
631 :issue => {:tracker_id => 3,
634 :issue => {:tracker_id => 3,
632 :status_id => 2,
635 :status_id => 2,
633 :subject => 'This is the test_new issue',
636 :subject => 'This is the test_new issue',
634 :description => 'This is the description',
637 :description => 'This is the description',
635 :priority_id => 5,
638 :priority_id => 5,
636 :start_date => '2010-11-07',
639 :start_date => '2010-11-07',
637 :estimated_hours => '',
640 :estimated_hours => '',
638 :custom_field_values => {'2' => 'Value for field 2'}}
641 :custom_field_values => {'2' => 'Value for field 2'}}
639 end
642 end
640 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
643 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
641
644
642 issue = Issue.find_by_subject('This is the test_new issue')
645 issue = Issue.find_by_subject('This is the test_new issue')
643 assert_not_nil issue
646 assert_not_nil issue
644 assert_equal 2, issue.author_id
647 assert_equal 2, issue.author_id
645 assert_equal 3, issue.tracker_id
648 assert_equal 3, issue.tracker_id
646 assert_equal 2, issue.status_id
649 assert_equal 2, issue.status_id
647 assert_equal Date.parse('2010-11-07'), issue.start_date
650 assert_equal Date.parse('2010-11-07'), issue.start_date
648 assert_nil issue.estimated_hours
651 assert_nil issue.estimated_hours
649 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2})
652 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2})
650 assert_not_nil v
653 assert_not_nil v
651 assert_equal 'Value for field 2', v.value
654 assert_equal 'Value for field 2', v.value
652 end
655 end
653
656
654 def test_post_new_with_group_assignment
657 def test_post_new_with_group_assignment
655 group = Group.find(11)
658 group = Group.find(11)
656 project = Project.find(1)
659 project = Project.find(1)
657 project.members << Member.new(:principal => group, :roles => [Role.first])
660 project.members << Member.new(:principal => group, :roles => [Role.first])
658
661
659 with_settings :issue_group_assignment => '1' do
662 with_settings :issue_group_assignment => '1' do
660 @request.session[:user_id] = 2
663 @request.session[:user_id] = 2
661 assert_difference 'Issue.count' do
664 assert_difference 'Issue.count' do
662 post :create, :project_id => project.id,
665 post :create, :project_id => project.id,
663 :issue => {:tracker_id => 3,
666 :issue => {:tracker_id => 3,
664 :status_id => 1,
667 :status_id => 1,
665 :subject => 'This is the test_new_with_group_assignment issue',
668 :subject => 'This is the test_new_with_group_assignment issue',
666 :assigned_to_id => group.id}
669 :assigned_to_id => group.id}
667 end
670 end
668 end
671 end
669 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
672 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
670
673
671 issue = Issue.find_by_subject('This is the test_new_with_group_assignment issue')
674 issue = Issue.find_by_subject('This is the test_new_with_group_assignment issue')
672 assert_not_nil issue
675 assert_not_nil issue
673 assert_equal group, issue.assigned_to
676 assert_equal group, issue.assigned_to
674 end
677 end
675
678
676 def test_post_create_without_start_date
679 def test_post_create_without_start_date
677 @request.session[:user_id] = 2
680 @request.session[:user_id] = 2
678 assert_difference 'Issue.count' do
681 assert_difference 'Issue.count' do
679 post :create, :project_id => 1,
682 post :create, :project_id => 1,
680 :issue => {:tracker_id => 3,
683 :issue => {:tracker_id => 3,
681 :status_id => 2,
684 :status_id => 2,
682 :subject => 'This is the test_new issue',
685 :subject => 'This is the test_new issue',
683 :description => 'This is the description',
686 :description => 'This is the description',
684 :priority_id => 5,
687 :priority_id => 5,
685 :start_date => '',
688 :start_date => '',
686 :estimated_hours => '',
689 :estimated_hours => '',
687 :custom_field_values => {'2' => 'Value for field 2'}}
690 :custom_field_values => {'2' => 'Value for field 2'}}
688 end
691 end
689 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
692 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
690
693
691 issue = Issue.find_by_subject('This is the test_new issue')
694 issue = Issue.find_by_subject('This is the test_new issue')
692 assert_not_nil issue
695 assert_not_nil issue
693 assert_nil issue.start_date
696 assert_nil issue.start_date
694 end
697 end
695
698
696 def test_post_create_and_continue
699 def test_post_create_and_continue
697 @request.session[:user_id] = 2
700 @request.session[:user_id] = 2
698 assert_difference 'Issue.count' do
701 assert_difference 'Issue.count' do
699 post :create, :project_id => 1,
702 post :create, :project_id => 1,
700 :issue => {:tracker_id => 3, :subject => 'This is first issue', :priority_id => 5},
703 :issue => {:tracker_id => 3, :subject => 'This is first issue', :priority_id => 5},
701 :continue => ''
704 :continue => ''
702 end
705 end
703
706
704 issue = Issue.first(:order => 'id DESC')
707 issue = Issue.first(:order => 'id DESC')
705 assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook', :issue => {:tracker_id => 3}
708 assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook', :issue => {:tracker_id => 3}
706 assert_not_nil flash[:notice], "flash was not set"
709 assert_not_nil flash[:notice], "flash was not set"
707 assert flash[:notice].include?("<a href='/issues/#{issue.id}'>##{issue.id}</a>"), "issue link not found in flash: #{flash[:notice]}"
710 assert flash[:notice].include?("<a href='/issues/#{issue.id}'>##{issue.id}</a>"), "issue link not found in flash: #{flash[:notice]}"
708 end
711 end
709
712
710 def test_post_create_without_custom_fields_param
713 def test_post_create_without_custom_fields_param
711 @request.session[:user_id] = 2
714 @request.session[:user_id] = 2
712 assert_difference 'Issue.count' do
715 assert_difference 'Issue.count' do
713 post :create, :project_id => 1,
716 post :create, :project_id => 1,
714 :issue => {:tracker_id => 1,
717 :issue => {:tracker_id => 1,
715 :subject => 'This is the test_new issue',
718 :subject => 'This is the test_new issue',
716 :description => 'This is the description',
719 :description => 'This is the description',
717 :priority_id => 5}
720 :priority_id => 5}
718 end
721 end
719 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
722 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
720 end
723 end
721
724
722 def test_post_create_with_required_custom_field_and_without_custom_fields_param
725 def test_post_create_with_required_custom_field_and_without_custom_fields_param
723 field = IssueCustomField.find_by_name('Database')
726 field = IssueCustomField.find_by_name('Database')
724 field.update_attribute(:is_required, true)
727 field.update_attribute(:is_required, true)
725
728
726 @request.session[:user_id] = 2
729 @request.session[:user_id] = 2
727 post :create, :project_id => 1,
730 post :create, :project_id => 1,
728 :issue => {:tracker_id => 1,
731 :issue => {:tracker_id => 1,
729 :subject => 'This is the test_new issue',
732 :subject => 'This is the test_new issue',
730 :description => 'This is the description',
733 :description => 'This is the description',
731 :priority_id => 5}
734 :priority_id => 5}
732 assert_response :success
735 assert_response :success
733 assert_template 'new'
736 assert_template 'new'
734 issue = assigns(:issue)
737 issue = assigns(:issue)
735 assert_not_nil issue
738 assert_not_nil issue
736 assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values)
739 assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values)
737 end
740 end
738
741
739 def test_post_create_with_watchers
742 def test_post_create_with_watchers
740 @request.session[:user_id] = 2
743 @request.session[:user_id] = 2
741 ActionMailer::Base.deliveries.clear
744 ActionMailer::Base.deliveries.clear
742
745
743 assert_difference 'Watcher.count', 2 do
746 assert_difference 'Watcher.count', 2 do
744 post :create, :project_id => 1,
747 post :create, :project_id => 1,
745 :issue => {:tracker_id => 1,
748 :issue => {:tracker_id => 1,
746 :subject => 'This is a new issue with watchers',
749 :subject => 'This is a new issue with watchers',
747 :description => 'This is the description',
750 :description => 'This is the description',
748 :priority_id => 5,
751 :priority_id => 5,
749 :watcher_user_ids => ['2', '3']}
752 :watcher_user_ids => ['2', '3']}
750 end
753 end
751 issue = Issue.find_by_subject('This is a new issue with watchers')
754 issue = Issue.find_by_subject('This is a new issue with watchers')
752 assert_not_nil issue
755 assert_not_nil issue
753 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
756 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
754
757
755 # Watchers added
758 # Watchers added
756 assert_equal [2, 3], issue.watcher_user_ids.sort
759 assert_equal [2, 3], issue.watcher_user_ids.sort
757 assert issue.watched_by?(User.find(3))
760 assert issue.watched_by?(User.find(3))
758 # Watchers notified
761 # Watchers notified
759 mail = ActionMailer::Base.deliveries.last
762 mail = ActionMailer::Base.deliveries.last
760 assert_kind_of TMail::Mail, mail
763 assert_kind_of TMail::Mail, mail
761 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
764 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
762 end
765 end
763
766
764 def test_post_create_subissue
767 def test_post_create_subissue
765 @request.session[:user_id] = 2
768 @request.session[:user_id] = 2
766
769
767 assert_difference 'Issue.count' do
770 assert_difference 'Issue.count' do
768 post :create, :project_id => 1,
771 post :create, :project_id => 1,
769 :issue => {:tracker_id => 1,
772 :issue => {:tracker_id => 1,
770 :subject => 'This is a child issue',
773 :subject => 'This is a child issue',
771 :parent_issue_id => 2}
774 :parent_issue_id => 2}
772 end
775 end
773 issue = Issue.find_by_subject('This is a child issue')
776 issue = Issue.find_by_subject('This is a child issue')
774 assert_not_nil issue
777 assert_not_nil issue
775 assert_equal Issue.find(2), issue.parent
778 assert_equal Issue.find(2), issue.parent
776 end
779 end
777
780
778 def test_post_create_subissue_with_non_numeric_parent_id
781 def test_post_create_subissue_with_non_numeric_parent_id
779 @request.session[:user_id] = 2
782 @request.session[:user_id] = 2
780
783
781 assert_difference 'Issue.count' do
784 assert_difference 'Issue.count' do
782 post :create, :project_id => 1,
785 post :create, :project_id => 1,
783 :issue => {:tracker_id => 1,
786 :issue => {:tracker_id => 1,
784 :subject => 'This is a child issue',
787 :subject => 'This is a child issue',
785 :parent_issue_id => 'ABC'}
788 :parent_issue_id => 'ABC'}
786 end
789 end
787 issue = Issue.find_by_subject('This is a child issue')
790 issue = Issue.find_by_subject('This is a child issue')
788 assert_not_nil issue
791 assert_not_nil issue
789 assert_nil issue.parent
792 assert_nil issue.parent
790 end
793 end
791
794
792 def test_post_create_private
795 def test_post_create_private
793 @request.session[:user_id] = 2
796 @request.session[:user_id] = 2
794
797
795 assert_difference 'Issue.count' do
798 assert_difference 'Issue.count' do
796 post :create, :project_id => 1,
799 post :create, :project_id => 1,
797 :issue => {:tracker_id => 1,
800 :issue => {:tracker_id => 1,
798 :subject => 'This is a private issue',
801 :subject => 'This is a private issue',
799 :is_private => '1'}
802 :is_private => '1'}
800 end
803 end
801 issue = Issue.first(:order => 'id DESC')
804 issue = Issue.first(:order => 'id DESC')
802 assert issue.is_private?
805 assert issue.is_private?
803 end
806 end
804
807
805 def test_post_create_private_with_set_own_issues_private_permission
808 def test_post_create_private_with_set_own_issues_private_permission
806 role = Role.find(1)
809 role = Role.find(1)
807 role.remove_permission! :set_issues_private
810 role.remove_permission! :set_issues_private
808 role.add_permission! :set_own_issues_private
811 role.add_permission! :set_own_issues_private
809
812
810 @request.session[:user_id] = 2
813 @request.session[:user_id] = 2
811
814
812 assert_difference 'Issue.count' do
815 assert_difference 'Issue.count' do
813 post :create, :project_id => 1,
816 post :create, :project_id => 1,
814 :issue => {:tracker_id => 1,
817 :issue => {:tracker_id => 1,
815 :subject => 'This is a private issue',
818 :subject => 'This is a private issue',
816 :is_private => '1'}
819 :is_private => '1'}
817 end
820 end
818 issue = Issue.first(:order => 'id DESC')
821 issue = Issue.first(:order => 'id DESC')
819 assert issue.is_private?
822 assert issue.is_private?
820 end
823 end
821
824
822 def test_post_create_should_send_a_notification
825 def test_post_create_should_send_a_notification
823 ActionMailer::Base.deliveries.clear
826 ActionMailer::Base.deliveries.clear
824 @request.session[:user_id] = 2
827 @request.session[:user_id] = 2
825 assert_difference 'Issue.count' do
828 assert_difference 'Issue.count' do
826 post :create, :project_id => 1,
829 post :create, :project_id => 1,
827 :issue => {:tracker_id => 3,
830 :issue => {:tracker_id => 3,
828 :subject => 'This is the test_new issue',
831 :subject => 'This is the test_new issue',
829 :description => 'This is the description',
832 :description => 'This is the description',
830 :priority_id => 5,
833 :priority_id => 5,
831 :estimated_hours => '',
834 :estimated_hours => '',
832 :custom_field_values => {'2' => 'Value for field 2'}}
835 :custom_field_values => {'2' => 'Value for field 2'}}
833 end
836 end
834 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
837 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
835
838
836 assert_equal 1, ActionMailer::Base.deliveries.size
839 assert_equal 1, ActionMailer::Base.deliveries.size
837 end
840 end
838
841
839 def test_post_create_should_preserve_fields_values_on_validation_failure
842 def test_post_create_should_preserve_fields_values_on_validation_failure
840 @request.session[:user_id] = 2
843 @request.session[:user_id] = 2
841 post :create, :project_id => 1,
844 post :create, :project_id => 1,
842 :issue => {:tracker_id => 1,
845 :issue => {:tracker_id => 1,
843 # empty subject
846 # empty subject
844 :subject => '',
847 :subject => '',
845 :description => 'This is a description',
848 :description => 'This is a description',
846 :priority_id => 6,
849 :priority_id => 6,
847 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
850 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
848 assert_response :success
851 assert_response :success
849 assert_template 'new'
852 assert_template 'new'
850
853
851 assert_tag :textarea, :attributes => { :name => 'issue[description]' },
854 assert_tag :textarea, :attributes => { :name => 'issue[description]' },
852 :content => 'This is a description'
855 :content => 'This is a description'
853 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
856 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
854 :child => { :tag => 'option', :attributes => { :selected => 'selected',
857 :child => { :tag => 'option', :attributes => { :selected => 'selected',
855 :value => '6' },
858 :value => '6' },
856 :content => 'High' }
859 :content => 'High' }
857 # Custom fields
860 # Custom fields
858 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
861 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
859 :child => { :tag => 'option', :attributes => { :selected => 'selected',
862 :child => { :tag => 'option', :attributes => { :selected => 'selected',
860 :value => 'Oracle' },
863 :value => 'Oracle' },
861 :content => 'Oracle' }
864 :content => 'Oracle' }
862 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
865 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
863 :value => 'Value for field 2'}
866 :value => 'Value for field 2'}
864 end
867 end
865
868
866 def test_post_create_should_ignore_non_safe_attributes
869 def test_post_create_should_ignore_non_safe_attributes
867 @request.session[:user_id] = 2
870 @request.session[:user_id] = 2
868 assert_nothing_raised do
871 assert_nothing_raised do
869 post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" }
872 post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" }
870 end
873 end
871 end
874 end
872
875
873 def test_post_create_with_attachment
876 def test_post_create_with_attachment
874 set_tmp_attachments_directory
877 set_tmp_attachments_directory
875 @request.session[:user_id] = 2
878 @request.session[:user_id] = 2
876
879
877 assert_difference 'Issue.count' do
880 assert_difference 'Issue.count' do
878 assert_difference 'Attachment.count' do
881 assert_difference 'Attachment.count' do
879 post :create, :project_id => 1,
882 post :create, :project_id => 1,
880 :issue => { :tracker_id => '1', :subject => 'With attachment' },
883 :issue => { :tracker_id => '1', :subject => 'With attachment' },
881 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
884 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
882 end
885 end
883 end
886 end
884
887
885 issue = Issue.first(:order => 'id DESC')
888 issue = Issue.first(:order => 'id DESC')
886 attachment = Attachment.first(:order => 'id DESC')
889 attachment = Attachment.first(:order => 'id DESC')
887
890
888 assert_equal issue, attachment.container
891 assert_equal issue, attachment.container
889 assert_equal 2, attachment.author_id
892 assert_equal 2, attachment.author_id
890 assert_equal 'testfile.txt', attachment.filename
893 assert_equal 'testfile.txt', attachment.filename
891 assert_equal 'text/plain', attachment.content_type
894 assert_equal 'text/plain', attachment.content_type
892 assert_equal 'test file', attachment.description
895 assert_equal 'test file', attachment.description
893 assert_equal 59, attachment.filesize
896 assert_equal 59, attachment.filesize
894 assert File.exists?(attachment.diskfile)
897 assert File.exists?(attachment.diskfile)
895 assert_equal 59, File.size(attachment.diskfile)
898 assert_equal 59, File.size(attachment.diskfile)
896 end
899 end
897
900
898 context "without workflow privilege" do
901 context "without workflow privilege" do
899 setup do
902 setup do
900 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
903 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
901 Role.anonymous.add_permission! :add_issues, :add_issue_notes
904 Role.anonymous.add_permission! :add_issues, :add_issue_notes
902 end
905 end
903
906
904 context "#new" do
907 context "#new" do
905 should "propose default status only" do
908 should "propose default status only" do
906 get :new, :project_id => 1
909 get :new, :project_id => 1
907 assert_response :success
910 assert_response :success
908 assert_template 'new'
911 assert_template 'new'
909 assert_tag :tag => 'select',
912 assert_tag :tag => 'select',
910 :attributes => {:name => 'issue[status_id]'},
913 :attributes => {:name => 'issue[status_id]'},
911 :children => {:count => 1},
914 :children => {:count => 1},
912 :child => {:tag => 'option', :attributes => {:value => IssueStatus.default.id.to_s}}
915 :child => {:tag => 'option', :attributes => {:value => IssueStatus.default.id.to_s}}
913 end
916 end
914
917
915 should "accept default status" do
918 should "accept default status" do
916 assert_difference 'Issue.count' do
919 assert_difference 'Issue.count' do
917 post :create, :project_id => 1,
920 post :create, :project_id => 1,
918 :issue => {:tracker_id => 1,
921 :issue => {:tracker_id => 1,
919 :subject => 'This is an issue',
922 :subject => 'This is an issue',
920 :status_id => 1}
923 :status_id => 1}
921 end
924 end
922 issue = Issue.last(:order => 'id')
925 issue = Issue.last(:order => 'id')
923 assert_equal IssueStatus.default, issue.status
926 assert_equal IssueStatus.default, issue.status
924 end
927 end
925
928
926 should "ignore unauthorized status" do
929 should "ignore unauthorized status" do
927 assert_difference 'Issue.count' do
930 assert_difference 'Issue.count' do
928 post :create, :project_id => 1,
931 post :create, :project_id => 1,
929 :issue => {:tracker_id => 1,
932 :issue => {:tracker_id => 1,
930 :subject => 'This is an issue',
933 :subject => 'This is an issue',
931 :status_id => 3}
934 :status_id => 3}
932 end
935 end
933 issue = Issue.last(:order => 'id')
936 issue = Issue.last(:order => 'id')
934 assert_equal IssueStatus.default, issue.status
937 assert_equal IssueStatus.default, issue.status
935 end
938 end
936 end
939 end
937
940
938 context "#update" do
941 context "#update" do
939 should "ignore status change" do
942 should "ignore status change" do
940 assert_difference 'Journal.count' do
943 assert_difference 'Journal.count' do
941 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
944 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
942 end
945 end
943 assert_equal 1, Issue.find(1).status_id
946 assert_equal 1, Issue.find(1).status_id
944 end
947 end
945
948
946 should "ignore attributes changes" do
949 should "ignore attributes changes" do
947 assert_difference 'Journal.count' do
950 assert_difference 'Journal.count' do
948 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
951 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
949 end
952 end
950 issue = Issue.find(1)
953 issue = Issue.find(1)
951 assert_equal "Can't print recipes", issue.subject
954 assert_equal "Can't print recipes", issue.subject
952 assert_nil issue.assigned_to
955 assert_nil issue.assigned_to
953 end
956 end
954 end
957 end
955 end
958 end
956
959
957 context "with workflow privilege" do
960 context "with workflow privilege" do
958 setup do
961 setup do
959 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
962 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
960 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
963 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
961 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
964 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
962 Role.anonymous.add_permission! :add_issues, :add_issue_notes
965 Role.anonymous.add_permission! :add_issues, :add_issue_notes
963 end
966 end
964
967
965 context "#update" do
968 context "#update" do
966 should "accept authorized status" do
969 should "accept authorized status" do
967 assert_difference 'Journal.count' do
970 assert_difference 'Journal.count' do
968 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
971 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
969 end
972 end
970 assert_equal 3, Issue.find(1).status_id
973 assert_equal 3, Issue.find(1).status_id
971 end
974 end
972
975
973 should "ignore unauthorized status" do
976 should "ignore unauthorized status" do
974 assert_difference 'Journal.count' do
977 assert_difference 'Journal.count' do
975 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
978 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
976 end
979 end
977 assert_equal 1, Issue.find(1).status_id
980 assert_equal 1, Issue.find(1).status_id
978 end
981 end
979
982
980 should "accept authorized attributes changes" do
983 should "accept authorized attributes changes" do
981 assert_difference 'Journal.count' do
984 assert_difference 'Journal.count' do
982 put :update, :id => 1, :notes => 'just trying', :issue => {:assigned_to_id => 2}
985 put :update, :id => 1, :notes => 'just trying', :issue => {:assigned_to_id => 2}
983 end
986 end
984 issue = Issue.find(1)
987 issue = Issue.find(1)
985 assert_equal 2, issue.assigned_to_id
988 assert_equal 2, issue.assigned_to_id
986 end
989 end
987
990
988 should "ignore unauthorized attributes changes" do
991 should "ignore unauthorized attributes changes" do
989 assert_difference 'Journal.count' do
992 assert_difference 'Journal.count' do
990 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed'}
993 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed'}
991 end
994 end
992 issue = Issue.find(1)
995 issue = Issue.find(1)
993 assert_equal "Can't print recipes", issue.subject
996 assert_equal "Can't print recipes", issue.subject
994 end
997 end
995 end
998 end
996
999
997 context "and :edit_issues permission" do
1000 context "and :edit_issues permission" do
998 setup do
1001 setup do
999 Role.anonymous.add_permission! :add_issues, :edit_issues
1002 Role.anonymous.add_permission! :add_issues, :edit_issues
1000 end
1003 end
1001
1004
1002 should "accept authorized status" do
1005 should "accept authorized status" do
1003 assert_difference 'Journal.count' do
1006 assert_difference 'Journal.count' do
1004 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1007 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1005 end
1008 end
1006 assert_equal 3, Issue.find(1).status_id
1009 assert_equal 3, Issue.find(1).status_id
1007 end
1010 end
1008
1011
1009 should "ignore unauthorized status" do
1012 should "ignore unauthorized status" do
1010 assert_difference 'Journal.count' do
1013 assert_difference 'Journal.count' do
1011 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
1014 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
1012 end
1015 end
1013 assert_equal 1, Issue.find(1).status_id
1016 assert_equal 1, Issue.find(1).status_id
1014 end
1017 end
1015
1018
1016 should "accept authorized attributes changes" do
1019 should "accept authorized attributes changes" do
1017 assert_difference 'Journal.count' do
1020 assert_difference 'Journal.count' do
1018 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
1021 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
1019 end
1022 end
1020 issue = Issue.find(1)
1023 issue = Issue.find(1)
1021 assert_equal "changed", issue.subject
1024 assert_equal "changed", issue.subject
1022 assert_equal 2, issue.assigned_to_id
1025 assert_equal 2, issue.assigned_to_id
1023 end
1026 end
1024 end
1027 end
1025 end
1028 end
1026
1029
1027 def test_copy_issue
1030 def test_copy_issue
1028 @request.session[:user_id] = 2
1031 @request.session[:user_id] = 2
1029 get :new, :project_id => 1, :copy_from => 1
1032 get :new, :project_id => 1, :copy_from => 1
1030 assert_template 'new'
1033 assert_template 'new'
1031 assert_not_nil assigns(:issue)
1034 assert_not_nil assigns(:issue)
1032 orig = Issue.find(1)
1035 orig = Issue.find(1)
1033 assert_equal orig.subject, assigns(:issue).subject
1036 assert_equal orig.subject, assigns(:issue).subject
1034 end
1037 end
1035
1038
1036 def test_get_edit
1039 def test_get_edit
1037 @request.session[:user_id] = 2
1040 @request.session[:user_id] = 2
1038 get :edit, :id => 1
1041 get :edit, :id => 1
1039 assert_response :success
1042 assert_response :success
1040 assert_template 'edit'
1043 assert_template 'edit'
1041 assert_not_nil assigns(:issue)
1044 assert_not_nil assigns(:issue)
1042 assert_equal Issue.find(1), assigns(:issue)
1045 assert_equal Issue.find(1), assigns(:issue)
1043
1046
1044 # Be sure we don't display inactive IssuePriorities
1047 # Be sure we don't display inactive IssuePriorities
1045 assert ! IssuePriority.find(15).active?
1048 assert ! IssuePriority.find(15).active?
1046 assert_no_tag :option, :attributes => {:value => '15'},
1049 assert_no_tag :option, :attributes => {:value => '15'},
1047 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
1050 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
1048 end
1051 end
1049
1052
1050 def test_get_edit_with_params
1053 def test_get_edit_with_params
1051 @request.session[:user_id] = 2
1054 @request.session[:user_id] = 2
1052 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 },
1055 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 },
1053 :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => TimeEntryActivity.first.id }
1056 :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => TimeEntryActivity.first.id }
1054 assert_response :success
1057 assert_response :success
1055 assert_template 'edit'
1058 assert_template 'edit'
1056
1059
1057 issue = assigns(:issue)
1060 issue = assigns(:issue)
1058 assert_not_nil issue
1061 assert_not_nil issue
1059
1062
1060 assert_equal 5, issue.status_id
1063 assert_equal 5, issue.status_id
1061 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
1064 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
1062 :child => { :tag => 'option',
1065 :child => { :tag => 'option',
1063 :content => 'Closed',
1066 :content => 'Closed',
1064 :attributes => { :selected => 'selected' } }
1067 :attributes => { :selected => 'selected' } }
1065
1068
1066 assert_equal 7, issue.priority_id
1069 assert_equal 7, issue.priority_id
1067 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
1070 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
1068 :child => { :tag => 'option',
1071 :child => { :tag => 'option',
1069 :content => 'Urgent',
1072 :content => 'Urgent',
1070 :attributes => { :selected => 'selected' } }
1073 :attributes => { :selected => 'selected' } }
1071
1074
1072 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => '2.5' }
1075 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => '2.5' }
1073 assert_tag :select, :attributes => { :name => 'time_entry[activity_id]' },
1076 assert_tag :select, :attributes => { :name => 'time_entry[activity_id]' },
1074 :child => { :tag => 'option',
1077 :child => { :tag => 'option',
1075 :attributes => { :selected => 'selected', :value => TimeEntryActivity.first.id } }
1078 :attributes => { :selected => 'selected', :value => TimeEntryActivity.first.id } }
1076 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => 'test_get_edit_with_params' }
1079 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => 'test_get_edit_with_params' }
1077 end
1080 end
1078
1081
1079 def test_update_edit_form
1082 def test_update_edit_form
1080 @request.session[:user_id] = 2
1083 @request.session[:user_id] = 2
1081 xhr :post, :new, :project_id => 1,
1084 xhr :post, :new, :project_id => 1,
1082 :id => 1,
1085 :id => 1,
1083 :issue => {:tracker_id => 2,
1086 :issue => {:tracker_id => 2,
1084 :subject => 'This is the test_new issue',
1087 :subject => 'This is the test_new issue',
1085 :description => 'This is the description',
1088 :description => 'This is the description',
1086 :priority_id => 5}
1089 :priority_id => 5}
1087 assert_response :success
1090 assert_response :success
1088 assert_template 'attributes'
1091 assert_template 'attributes'
1089
1092
1090 issue = assigns(:issue)
1093 issue = assigns(:issue)
1091 assert_kind_of Issue, issue
1094 assert_kind_of Issue, issue
1092 assert_equal 1, issue.id
1095 assert_equal 1, issue.id
1093 assert_equal 1, issue.project_id
1096 assert_equal 1, issue.project_id
1094 assert_equal 2, issue.tracker_id
1097 assert_equal 2, issue.tracker_id
1095 assert_equal 'This is the test_new issue', issue.subject
1098 assert_equal 'This is the test_new issue', issue.subject
1096 end
1099 end
1097
1100
1098 def test_update_using_invalid_http_verbs
1101 def test_update_using_invalid_http_verbs
1099 @request.session[:user_id] = 2
1102 @request.session[:user_id] = 2
1100 subject = 'Updated by an invalid http verb'
1103 subject = 'Updated by an invalid http verb'
1101
1104
1102 get :update, :id => 1, :issue => {:subject => subject}
1105 get :update, :id => 1, :issue => {:subject => subject}
1103 assert_not_equal subject, Issue.find(1).subject
1106 assert_not_equal subject, Issue.find(1).subject
1104
1107
1105 post :update, :id => 1, :issue => {:subject => subject}
1108 post :update, :id => 1, :issue => {:subject => subject}
1106 assert_not_equal subject, Issue.find(1).subject
1109 assert_not_equal subject, Issue.find(1).subject
1107
1110
1108 delete :update, :id => 1, :issue => {:subject => subject}
1111 delete :update, :id => 1, :issue => {:subject => subject}
1109 assert_not_equal subject, Issue.find(1).subject
1112 assert_not_equal subject, Issue.find(1).subject
1110 end
1113 end
1111
1114
1112 def test_put_update_without_custom_fields_param
1115 def test_put_update_without_custom_fields_param
1113 @request.session[:user_id] = 2
1116 @request.session[:user_id] = 2
1114 ActionMailer::Base.deliveries.clear
1117 ActionMailer::Base.deliveries.clear
1115
1118
1116 issue = Issue.find(1)
1119 issue = Issue.find(1)
1117 assert_equal '125', issue.custom_value_for(2).value
1120 assert_equal '125', issue.custom_value_for(2).value
1118 old_subject = issue.subject
1121 old_subject = issue.subject
1119 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
1122 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
1120
1123
1121 assert_difference('Journal.count') do
1124 assert_difference('Journal.count') do
1122 assert_difference('JournalDetail.count', 2) do
1125 assert_difference('JournalDetail.count', 2) do
1123 put :update, :id => 1, :issue => {:subject => new_subject,
1126 put :update, :id => 1, :issue => {:subject => new_subject,
1124 :priority_id => '6',
1127 :priority_id => '6',
1125 :category_id => '1' # no change
1128 :category_id => '1' # no change
1126 }
1129 }
1127 end
1130 end
1128 end
1131 end
1129 assert_redirected_to :action => 'show', :id => '1'
1132 assert_redirected_to :action => 'show', :id => '1'
1130 issue.reload
1133 issue.reload
1131 assert_equal new_subject, issue.subject
1134 assert_equal new_subject, issue.subject
1132 # Make sure custom fields were not cleared
1135 # Make sure custom fields were not cleared
1133 assert_equal '125', issue.custom_value_for(2).value
1136 assert_equal '125', issue.custom_value_for(2).value
1134
1137
1135 mail = ActionMailer::Base.deliveries.last
1138 mail = ActionMailer::Base.deliveries.last
1136 assert_kind_of TMail::Mail, mail
1139 assert_kind_of TMail::Mail, mail
1137 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
1140 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
1138 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
1141 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
1139 end
1142 end
1140
1143
1141 def test_put_update_with_custom_field_change
1144 def test_put_update_with_custom_field_change
1142 @request.session[:user_id] = 2
1145 @request.session[:user_id] = 2
1143 issue = Issue.find(1)
1146 issue = Issue.find(1)
1144 assert_equal '125', issue.custom_value_for(2).value
1147 assert_equal '125', issue.custom_value_for(2).value
1145
1148
1146 assert_difference('Journal.count') do
1149 assert_difference('Journal.count') do
1147 assert_difference('JournalDetail.count', 3) do
1150 assert_difference('JournalDetail.count', 3) do
1148 put :update, :id => 1, :issue => {:subject => 'Custom field change',
1151 put :update, :id => 1, :issue => {:subject => 'Custom field change',
1149 :priority_id => '6',
1152 :priority_id => '6',
1150 :category_id => '1', # no change
1153 :category_id => '1', # no change
1151 :custom_field_values => { '2' => 'New custom value' }
1154 :custom_field_values => { '2' => 'New custom value' }
1152 }
1155 }
1153 end
1156 end
1154 end
1157 end
1155 assert_redirected_to :action => 'show', :id => '1'
1158 assert_redirected_to :action => 'show', :id => '1'
1156 issue.reload
1159 issue.reload
1157 assert_equal 'New custom value', issue.custom_value_for(2).value
1160 assert_equal 'New custom value', issue.custom_value_for(2).value
1158
1161
1159 mail = ActionMailer::Base.deliveries.last
1162 mail = ActionMailer::Base.deliveries.last
1160 assert_kind_of TMail::Mail, mail
1163 assert_kind_of TMail::Mail, mail
1161 assert mail.body.include?("Searchable field changed from 125 to New custom value")
1164 assert mail.body.include?("Searchable field changed from 125 to New custom value")
1162 end
1165 end
1163
1166
1164 def test_put_update_with_status_and_assignee_change
1167 def test_put_update_with_status_and_assignee_change
1165 issue = Issue.find(1)
1168 issue = Issue.find(1)
1166 assert_equal 1, issue.status_id
1169 assert_equal 1, issue.status_id
1167 @request.session[:user_id] = 2
1170 @request.session[:user_id] = 2
1168 assert_difference('TimeEntry.count', 0) do
1171 assert_difference('TimeEntry.count', 0) do
1169 put :update,
1172 put :update,
1170 :id => 1,
1173 :id => 1,
1171 :issue => { :status_id => 2, :assigned_to_id => 3 },
1174 :issue => { :status_id => 2, :assigned_to_id => 3 },
1172 :notes => 'Assigned to dlopper',
1175 :notes => 'Assigned to dlopper',
1173 :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first }
1176 :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first }
1174 end
1177 end
1175 assert_redirected_to :action => 'show', :id => '1'
1178 assert_redirected_to :action => 'show', :id => '1'
1176 issue.reload
1179 issue.reload
1177 assert_equal 2, issue.status_id
1180 assert_equal 2, issue.status_id
1178 j = Journal.find(:first, :order => 'id DESC')
1181 j = Journal.find(:first, :order => 'id DESC')
1179 assert_equal 'Assigned to dlopper', j.notes
1182 assert_equal 'Assigned to dlopper', j.notes
1180 assert_equal 2, j.details.size
1183 assert_equal 2, j.details.size
1181
1184
1182 mail = ActionMailer::Base.deliveries.last
1185 mail = ActionMailer::Base.deliveries.last
1183 assert mail.body.include?("Status changed from New to Assigned")
1186 assert mail.body.include?("Status changed from New to Assigned")
1184 # subject should contain the new status
1187 # subject should contain the new status
1185 assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
1188 assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
1186 end
1189 end
1187
1190
1188 def test_put_update_with_note_only
1191 def test_put_update_with_note_only
1189 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
1192 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
1190 # anonymous user
1193 # anonymous user
1191 put :update,
1194 put :update,
1192 :id => 1,
1195 :id => 1,
1193 :notes => notes
1196 :notes => notes
1194 assert_redirected_to :action => 'show', :id => '1'
1197 assert_redirected_to :action => 'show', :id => '1'
1195 j = Journal.find(:first, :order => 'id DESC')
1198 j = Journal.find(:first, :order => 'id DESC')
1196 assert_equal notes, j.notes
1199 assert_equal notes, j.notes
1197 assert_equal 0, j.details.size
1200 assert_equal 0, j.details.size
1198 assert_equal User.anonymous, j.user
1201 assert_equal User.anonymous, j.user
1199
1202
1200 mail = ActionMailer::Base.deliveries.last
1203 mail = ActionMailer::Base.deliveries.last
1201 assert mail.body.include?(notes)
1204 assert mail.body.include?(notes)
1202 end
1205 end
1203
1206
1204 def test_put_update_with_note_and_spent_time
1207 def test_put_update_with_note_and_spent_time
1205 @request.session[:user_id] = 2
1208 @request.session[:user_id] = 2
1206 spent_hours_before = Issue.find(1).spent_hours
1209 spent_hours_before = Issue.find(1).spent_hours
1207 assert_difference('TimeEntry.count') do
1210 assert_difference('TimeEntry.count') do
1208 put :update,
1211 put :update,
1209 :id => 1,
1212 :id => 1,
1210 :notes => '2.5 hours added',
1213 :notes => '2.5 hours added',
1211 :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id }
1214 :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id }
1212 end
1215 end
1213 assert_redirected_to :action => 'show', :id => '1'
1216 assert_redirected_to :action => 'show', :id => '1'
1214
1217
1215 issue = Issue.find(1)
1218 issue = Issue.find(1)
1216
1219
1217 j = Journal.find(:first, :order => 'id DESC')
1220 j = Journal.find(:first, :order => 'id DESC')
1218 assert_equal '2.5 hours added', j.notes
1221 assert_equal '2.5 hours added', j.notes
1219 assert_equal 0, j.details.size
1222 assert_equal 0, j.details.size
1220
1223
1221 t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time')
1224 t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time')
1222 assert_not_nil t
1225 assert_not_nil t
1223 assert_equal 2.5, t.hours
1226 assert_equal 2.5, t.hours
1224 assert_equal spent_hours_before + 2.5, issue.spent_hours
1227 assert_equal spent_hours_before + 2.5, issue.spent_hours
1225 end
1228 end
1226
1229
1227 def test_put_update_with_attachment_only
1230 def test_put_update_with_attachment_only
1228 set_tmp_attachments_directory
1231 set_tmp_attachments_directory
1229
1232
1230 # Delete all fixtured journals, a race condition can occur causing the wrong
1233 # Delete all fixtured journals, a race condition can occur causing the wrong
1231 # journal to get fetched in the next find.
1234 # journal to get fetched in the next find.
1232 Journal.delete_all
1235 Journal.delete_all
1233
1236
1234 # anonymous user
1237 # anonymous user
1235 assert_difference 'Attachment.count' do
1238 assert_difference 'Attachment.count' do
1236 put :update, :id => 1,
1239 put :update, :id => 1,
1237 :notes => '',
1240 :notes => '',
1238 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
1241 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
1239 end
1242 end
1240
1243
1241 assert_redirected_to :action => 'show', :id => '1'
1244 assert_redirected_to :action => 'show', :id => '1'
1242 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
1245 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
1243 assert j.notes.blank?
1246 assert j.notes.blank?
1244 assert_equal 1, j.details.size
1247 assert_equal 1, j.details.size
1245 assert_equal 'testfile.txt', j.details.first.value
1248 assert_equal 'testfile.txt', j.details.first.value
1246 assert_equal User.anonymous, j.user
1249 assert_equal User.anonymous, j.user
1247
1250
1248 attachment = Attachment.first(:order => 'id DESC')
1251 attachment = Attachment.first(:order => 'id DESC')
1249 assert_equal Issue.find(1), attachment.container
1252 assert_equal Issue.find(1), attachment.container
1250 assert_equal User.anonymous, attachment.author
1253 assert_equal User.anonymous, attachment.author
1251 assert_equal 'testfile.txt', attachment.filename
1254 assert_equal 'testfile.txt', attachment.filename
1252 assert_equal 'text/plain', attachment.content_type
1255 assert_equal 'text/plain', attachment.content_type
1253 assert_equal 'test file', attachment.description
1256 assert_equal 'test file', attachment.description
1254 assert_equal 59, attachment.filesize
1257 assert_equal 59, attachment.filesize
1255 assert File.exists?(attachment.diskfile)
1258 assert File.exists?(attachment.diskfile)
1256 assert_equal 59, File.size(attachment.diskfile)
1259 assert_equal 59, File.size(attachment.diskfile)
1257
1260
1258 mail = ActionMailer::Base.deliveries.last
1261 mail = ActionMailer::Base.deliveries.last
1259 assert mail.body.include?('testfile.txt')
1262 assert mail.body.include?('testfile.txt')
1260 end
1263 end
1261
1264
1262 def test_put_update_with_attachment_that_fails_to_save
1265 def test_put_update_with_attachment_that_fails_to_save
1263 set_tmp_attachments_directory
1266 set_tmp_attachments_directory
1264
1267
1265 # Delete all fixtured journals, a race condition can occur causing the wrong
1268 # Delete all fixtured journals, a race condition can occur causing the wrong
1266 # journal to get fetched in the next find.
1269 # journal to get fetched in the next find.
1267 Journal.delete_all
1270 Journal.delete_all
1268
1271
1269 # Mock out the unsaved attachment
1272 # Mock out the unsaved attachment
1270 Attachment.any_instance.stubs(:create).returns(Attachment.new)
1273 Attachment.any_instance.stubs(:create).returns(Attachment.new)
1271
1274
1272 # anonymous user
1275 # anonymous user
1273 put :update,
1276 put :update,
1274 :id => 1,
1277 :id => 1,
1275 :notes => '',
1278 :notes => '',
1276 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
1279 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
1277 assert_redirected_to :action => 'show', :id => '1'
1280 assert_redirected_to :action => 'show', :id => '1'
1278 assert_equal '1 file(s) could not be saved.', flash[:warning]
1281 assert_equal '1 file(s) could not be saved.', flash[:warning]
1279
1282
1280 end if Object.const_defined?(:Mocha)
1283 end if Object.const_defined?(:Mocha)
1281
1284
1282 def test_put_update_with_no_change
1285 def test_put_update_with_no_change
1283 issue = Issue.find(1)
1286 issue = Issue.find(1)
1284 issue.journals.clear
1287 issue.journals.clear
1285 ActionMailer::Base.deliveries.clear
1288 ActionMailer::Base.deliveries.clear
1286
1289
1287 put :update,
1290 put :update,
1288 :id => 1,
1291 :id => 1,
1289 :notes => ''
1292 :notes => ''
1290 assert_redirected_to :action => 'show', :id => '1'
1293 assert_redirected_to :action => 'show', :id => '1'
1291
1294
1292 issue.reload
1295 issue.reload
1293 assert issue.journals.empty?
1296 assert issue.journals.empty?
1294 # No email should be sent
1297 # No email should be sent
1295 assert ActionMailer::Base.deliveries.empty?
1298 assert ActionMailer::Base.deliveries.empty?
1296 end
1299 end
1297
1300
1298 def test_put_update_should_send_a_notification
1301 def test_put_update_should_send_a_notification
1299 @request.session[:user_id] = 2
1302 @request.session[:user_id] = 2
1300 ActionMailer::Base.deliveries.clear
1303 ActionMailer::Base.deliveries.clear
1301 issue = Issue.find(1)
1304 issue = Issue.find(1)
1302 old_subject = issue.subject
1305 old_subject = issue.subject
1303 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
1306 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
1304
1307
1305 put :update, :id => 1, :issue => {:subject => new_subject,
1308 put :update, :id => 1, :issue => {:subject => new_subject,
1306 :priority_id => '6',
1309 :priority_id => '6',
1307 :category_id => '1' # no change
1310 :category_id => '1' # no change
1308 }
1311 }
1309 assert_equal 1, ActionMailer::Base.deliveries.size
1312 assert_equal 1, ActionMailer::Base.deliveries.size
1310 end
1313 end
1311
1314
1312 def test_put_update_with_invalid_spent_time_hours_only
1315 def test_put_update_with_invalid_spent_time_hours_only
1313 @request.session[:user_id] = 2
1316 @request.session[:user_id] = 2
1314 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
1317 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
1315
1318
1316 assert_no_difference('Journal.count') do
1319 assert_no_difference('Journal.count') do
1317 put :update,
1320 put :update,
1318 :id => 1,
1321 :id => 1,
1319 :notes => notes,
1322 :notes => notes,
1320 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
1323 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
1321 end
1324 end
1322 assert_response :success
1325 assert_response :success
1323 assert_template 'edit'
1326 assert_template 'edit'
1324
1327
1325 assert_error_tag :descendant => {:content => /Activity can't be blank/}
1328 assert_error_tag :descendant => {:content => /Activity can't be blank/}
1326 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
1329 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
1327 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" }
1330 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" }
1328 end
1331 end
1329
1332
1330 def test_put_update_with_invalid_spent_time_comments_only
1333 def test_put_update_with_invalid_spent_time_comments_only
1331 @request.session[:user_id] = 2
1334 @request.session[:user_id] = 2
1332 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
1335 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
1333
1336
1334 assert_no_difference('Journal.count') do
1337 assert_no_difference('Journal.count') do
1335 put :update,
1338 put :update,
1336 :id => 1,
1339 :id => 1,
1337 :notes => notes,
1340 :notes => notes,
1338 :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""}
1341 :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""}
1339 end
1342 end
1340 assert_response :success
1343 assert_response :success
1341 assert_template 'edit'
1344 assert_template 'edit'
1342
1345
1343 assert_error_tag :descendant => {:content => /Activity can't be blank/}
1346 assert_error_tag :descendant => {:content => /Activity can't be blank/}
1344 assert_error_tag :descendant => {:content => /Hours can't be blank/}
1347 assert_error_tag :descendant => {:content => /Hours can't be blank/}
1345 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
1348 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
1346 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => "this is my comment" }
1349 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => "this is my comment" }
1347 end
1350 end
1348
1351
1349 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject
1352 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject
1350 issue = Issue.find(2)
1353 issue = Issue.find(2)
1351 @request.session[:user_id] = 2
1354 @request.session[:user_id] = 2
1352
1355
1353 put :update,
1356 put :update,
1354 :id => issue.id,
1357 :id => issue.id,
1355 :issue => {
1358 :issue => {
1356 :fixed_version_id => 4
1359 :fixed_version_id => 4
1357 }
1360 }
1358
1361
1359 assert_response :redirect
1362 assert_response :redirect
1360 issue.reload
1363 issue.reload
1361 assert_equal 4, issue.fixed_version_id
1364 assert_equal 4, issue.fixed_version_id
1362 assert_not_equal issue.project_id, issue.fixed_version.project_id
1365 assert_not_equal issue.project_id, issue.fixed_version.project_id
1363 end
1366 end
1364
1367
1365 def test_put_update_should_redirect_back_using_the_back_url_parameter
1368 def test_put_update_should_redirect_back_using_the_back_url_parameter
1366 issue = Issue.find(2)
1369 issue = Issue.find(2)
1367 @request.session[:user_id] = 2
1370 @request.session[:user_id] = 2
1368
1371
1369 put :update,
1372 put :update,
1370 :id => issue.id,
1373 :id => issue.id,
1371 :issue => {
1374 :issue => {
1372 :fixed_version_id => 4
1375 :fixed_version_id => 4
1373 },
1376 },
1374 :back_url => '/issues'
1377 :back_url => '/issues'
1375
1378
1376 assert_response :redirect
1379 assert_response :redirect
1377 assert_redirected_to '/issues'
1380 assert_redirected_to '/issues'
1378 end
1381 end
1379
1382
1380 def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
1383 def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
1381 issue = Issue.find(2)
1384 issue = Issue.find(2)
1382 @request.session[:user_id] = 2
1385 @request.session[:user_id] = 2
1383
1386
1384 put :update,
1387 put :update,
1385 :id => issue.id,
1388 :id => issue.id,
1386 :issue => {
1389 :issue => {
1387 :fixed_version_id => 4
1390 :fixed_version_id => 4
1388 },
1391 },
1389 :back_url => 'http://google.com'
1392 :back_url => 'http://google.com'
1390
1393
1391 assert_response :redirect
1394 assert_response :redirect
1392 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id
1395 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id
1393 end
1396 end
1394
1397
1395 def test_get_bulk_edit
1398 def test_get_bulk_edit
1396 @request.session[:user_id] = 2
1399 @request.session[:user_id] = 2
1397 get :bulk_edit, :ids => [1, 2]
1400 get :bulk_edit, :ids => [1, 2]
1398 assert_response :success
1401 assert_response :success
1399 assert_template 'bulk_edit'
1402 assert_template 'bulk_edit'
1400
1403
1401 assert_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
1404 assert_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
1402
1405
1403 # Project specific custom field, date type
1406 # Project specific custom field, date type
1404 field = CustomField.find(9)
1407 field = CustomField.find(9)
1405 assert !field.is_for_all?
1408 assert !field.is_for_all?
1406 assert_equal 'date', field.field_format
1409 assert_equal 'date', field.field_format
1407 assert_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
1410 assert_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
1408
1411
1409 # System wide custom field
1412 # System wide custom field
1410 assert CustomField.find(1).is_for_all?
1413 assert CustomField.find(1).is_for_all?
1411 assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'}
1414 assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'}
1412
1415
1413 # Be sure we don't display inactive IssuePriorities
1416 # Be sure we don't display inactive IssuePriorities
1414 assert ! IssuePriority.find(15).active?
1417 assert ! IssuePriority.find(15).active?
1415 assert_no_tag :option, :attributes => {:value => '15'},
1418 assert_no_tag :option, :attributes => {:value => '15'},
1416 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
1419 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
1417 end
1420 end
1418
1421
1419 def test_get_bulk_edit_on_different_projects
1422 def test_get_bulk_edit_on_different_projects
1420 @request.session[:user_id] = 2
1423 @request.session[:user_id] = 2
1421 get :bulk_edit, :ids => [1, 2, 6]
1424 get :bulk_edit, :ids => [1, 2, 6]
1422 assert_response :success
1425 assert_response :success
1423 assert_template 'bulk_edit'
1426 assert_template 'bulk_edit'
1424
1427
1425 # Can not set issues from different projects as children of an issue
1428 # Can not set issues from different projects as children of an issue
1426 assert_no_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
1429 assert_no_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
1427
1430
1428 # Project specific custom field, date type
1431 # Project specific custom field, date type
1429 field = CustomField.find(9)
1432 field = CustomField.find(9)
1430 assert !field.is_for_all?
1433 assert !field.is_for_all?
1431 assert !field.project_ids.include?(Issue.find(6).project_id)
1434 assert !field.project_ids.include?(Issue.find(6).project_id)
1432 assert_no_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
1435 assert_no_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
1433 end
1436 end
1434
1437
1435 def test_get_bulk_edit_with_user_custom_field
1438 def test_get_bulk_edit_with_user_custom_field
1436 field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true)
1439 field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true)
1437
1440
1438 @request.session[:user_id] = 2
1441 @request.session[:user_id] = 2
1439 get :bulk_edit, :ids => [1, 2]
1442 get :bulk_edit, :ids => [1, 2]
1440 assert_response :success
1443 assert_response :success
1441 assert_template 'bulk_edit'
1444 assert_template 'bulk_edit'
1442
1445
1443 assert_tag :select,
1446 assert_tag :select,
1444 :attributes => {:name => "issue[custom_field_values][#{field.id}]"},
1447 :attributes => {:name => "issue[custom_field_values][#{field.id}]"},
1445 :children => {
1448 :children => {
1446 :only => {:tag => 'option'},
1449 :only => {:tag => 'option'},
1447 :count => Project.find(1).users.count + 1
1450 :count => Project.find(1).users.count + 1
1448 }
1451 }
1449 end
1452 end
1450
1453
1451 def test_get_bulk_edit_with_version_custom_field
1454 def test_get_bulk_edit_with_version_custom_field
1452 field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true)
1455 field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true)
1453
1456
1454 @request.session[:user_id] = 2
1457 @request.session[:user_id] = 2
1455 get :bulk_edit, :ids => [1, 2]
1458 get :bulk_edit, :ids => [1, 2]
1456 assert_response :success
1459 assert_response :success
1457 assert_template 'bulk_edit'
1460 assert_template 'bulk_edit'
1458
1461
1459 assert_tag :select,
1462 assert_tag :select,
1460 :attributes => {:name => "issue[custom_field_values][#{field.id}]"},
1463 :attributes => {:name => "issue[custom_field_values][#{field.id}]"},
1461 :children => {
1464 :children => {
1462 :only => {:tag => 'option'},
1465 :only => {:tag => 'option'},
1463 :count => Project.find(1).versions.count + 1
1466 :count => Project.find(1).versions.count + 1
1464 }
1467 }
1465 end
1468 end
1466
1469
1467 def test_bulk_update
1470 def test_bulk_update
1468 @request.session[:user_id] = 2
1471 @request.session[:user_id] = 2
1469 # update issues priority
1472 # update issues priority
1470 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
1473 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
1471 :issue => {:priority_id => 7,
1474 :issue => {:priority_id => 7,
1472 :assigned_to_id => '',
1475 :assigned_to_id => '',
1473 :custom_field_values => {'2' => ''}}
1476 :custom_field_values => {'2' => ''}}
1474
1477
1475 assert_response 302
1478 assert_response 302
1476 # check that the issues were updated
1479 # check that the issues were updated
1477 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
1480 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
1478
1481
1479 issue = Issue.find(1)
1482 issue = Issue.find(1)
1480 journal = issue.journals.find(:first, :order => 'created_on DESC')
1483 journal = issue.journals.find(:first, :order => 'created_on DESC')
1481 assert_equal '125', issue.custom_value_for(2).value
1484 assert_equal '125', issue.custom_value_for(2).value
1482 assert_equal 'Bulk editing', journal.notes
1485 assert_equal 'Bulk editing', journal.notes
1483 assert_equal 1, journal.details.size
1486 assert_equal 1, journal.details.size
1484 end
1487 end
1485
1488
1486 def test_bulk_update_with_group_assignee
1489 def test_bulk_update_with_group_assignee
1487 group = Group.find(11)
1490 group = Group.find(11)
1488 project = Project.find(1)
1491 project = Project.find(1)
1489 project.members << Member.new(:principal => group, :roles => [Role.first])
1492 project.members << Member.new(:principal => group, :roles => [Role.first])
1490
1493
1491 @request.session[:user_id] = 2
1494 @request.session[:user_id] = 2
1492 # update issues assignee
1495 # update issues assignee
1493 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
1496 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
1494 :issue => {:priority_id => '',
1497 :issue => {:priority_id => '',
1495 :assigned_to_id => group.id,
1498 :assigned_to_id => group.id,
1496 :custom_field_values => {'2' => ''}}
1499 :custom_field_values => {'2' => ''}}
1497
1500
1498 assert_response 302
1501 assert_response 302
1499 assert_equal [group, group], Issue.find_all_by_id([1, 2]).collect {|i| i.assigned_to}
1502 assert_equal [group, group], Issue.find_all_by_id([1, 2]).collect {|i| i.assigned_to}
1500 end
1503 end
1501
1504
1502 def test_bulk_update_on_different_projects
1505 def test_bulk_update_on_different_projects
1503 @request.session[:user_id] = 2
1506 @request.session[:user_id] = 2
1504 # update issues priority
1507 # update issues priority
1505 post :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing',
1508 post :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing',
1506 :issue => {:priority_id => 7,
1509 :issue => {:priority_id => 7,
1507 :assigned_to_id => '',
1510 :assigned_to_id => '',
1508 :custom_field_values => {'2' => ''}}
1511 :custom_field_values => {'2' => ''}}
1509
1512
1510 assert_response 302
1513 assert_response 302
1511 # check that the issues were updated
1514 # check that the issues were updated
1512 assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id)
1515 assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id)
1513
1516
1514 issue = Issue.find(1)
1517 issue = Issue.find(1)
1515 journal = issue.journals.find(:first, :order => 'created_on DESC')
1518 journal = issue.journals.find(:first, :order => 'created_on DESC')
1516 assert_equal '125', issue.custom_value_for(2).value
1519 assert_equal '125', issue.custom_value_for(2).value
1517 assert_equal 'Bulk editing', journal.notes
1520 assert_equal 'Bulk editing', journal.notes
1518 assert_equal 1, journal.details.size
1521 assert_equal 1, journal.details.size
1519 end
1522 end
1520
1523
1521 def test_bulk_update_on_different_projects_without_rights
1524 def test_bulk_update_on_different_projects_without_rights
1522 @request.session[:user_id] = 3
1525 @request.session[:user_id] = 3
1523 user = User.find(3)
1526 user = User.find(3)
1524 action = { :controller => "issues", :action => "bulk_update" }
1527 action = { :controller => "issues", :action => "bulk_update" }
1525 assert user.allowed_to?(action, Issue.find(1).project)
1528 assert user.allowed_to?(action, Issue.find(1).project)
1526 assert ! user.allowed_to?(action, Issue.find(6).project)
1529 assert ! user.allowed_to?(action, Issue.find(6).project)
1527 post :bulk_update, :ids => [1, 6], :notes => 'Bulk should fail',
1530 post :bulk_update, :ids => [1, 6], :notes => 'Bulk should fail',
1528 :issue => {:priority_id => 7,
1531 :issue => {:priority_id => 7,
1529 :assigned_to_id => '',
1532 :assigned_to_id => '',
1530 :custom_field_values => {'2' => ''}}
1533 :custom_field_values => {'2' => ''}}
1531 assert_response 403
1534 assert_response 403
1532 assert_not_equal "Bulk should fail", Journal.last.notes
1535 assert_not_equal "Bulk should fail", Journal.last.notes
1533 end
1536 end
1534
1537
1535 def test_bullk_update_should_send_a_notification
1538 def test_bullk_update_should_send_a_notification
1536 @request.session[:user_id] = 2
1539 @request.session[:user_id] = 2
1537 ActionMailer::Base.deliveries.clear
1540 ActionMailer::Base.deliveries.clear
1538 post(:bulk_update,
1541 post(:bulk_update,
1539 {
1542 {
1540 :ids => [1, 2],
1543 :ids => [1, 2],
1541 :notes => 'Bulk editing',
1544 :notes => 'Bulk editing',
1542 :issue => {
1545 :issue => {
1543 :priority_id => 7,
1546 :priority_id => 7,
1544 :assigned_to_id => '',
1547 :assigned_to_id => '',
1545 :custom_field_values => {'2' => ''}
1548 :custom_field_values => {'2' => ''}
1546 }
1549 }
1547 })
1550 })
1548
1551
1549 assert_response 302
1552 assert_response 302
1550 assert_equal 2, ActionMailer::Base.deliveries.size
1553 assert_equal 2, ActionMailer::Base.deliveries.size
1551 end
1554 end
1552
1555
1553 def test_bulk_update_status
1556 def test_bulk_update_status
1554 @request.session[:user_id] = 2
1557 @request.session[:user_id] = 2
1555 # update issues priority
1558 # update issues priority
1556 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing status',
1559 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing status',
1557 :issue => {:priority_id => '',
1560 :issue => {:priority_id => '',
1558 :assigned_to_id => '',
1561 :assigned_to_id => '',
1559 :status_id => '5'}
1562 :status_id => '5'}
1560
1563
1561 assert_response 302
1564 assert_response 302
1562 issue = Issue.find(1)
1565 issue = Issue.find(1)
1563 assert issue.closed?
1566 assert issue.closed?
1564 end
1567 end
1565
1568
1566 def test_bulk_update_parent_id
1569 def test_bulk_update_parent_id
1567 @request.session[:user_id] = 2
1570 @request.session[:user_id] = 2
1568 post :bulk_update, :ids => [1, 3],
1571 post :bulk_update, :ids => [1, 3],
1569 :notes => 'Bulk editing parent',
1572 :notes => 'Bulk editing parent',
1570 :issue => {:priority_id => '', :assigned_to_id => '', :status_id => '', :parent_issue_id => '2'}
1573 :issue => {:priority_id => '', :assigned_to_id => '', :status_id => '', :parent_issue_id => '2'}
1571
1574
1572 assert_response 302
1575 assert_response 302
1573 parent = Issue.find(2)
1576 parent = Issue.find(2)
1574 assert_equal parent.id, Issue.find(1).parent_id
1577 assert_equal parent.id, Issue.find(1).parent_id
1575 assert_equal parent.id, Issue.find(3).parent_id
1578 assert_equal parent.id, Issue.find(3).parent_id
1576 assert_equal [1, 3], parent.children.collect(&:id).sort
1579 assert_equal [1, 3], parent.children.collect(&:id).sort
1577 end
1580 end
1578
1581
1579 def test_bulk_update_custom_field
1582 def test_bulk_update_custom_field
1580 @request.session[:user_id] = 2
1583 @request.session[:user_id] = 2
1581 # update issues priority
1584 # update issues priority
1582 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field',
1585 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field',
1583 :issue => {:priority_id => '',
1586 :issue => {:priority_id => '',
1584 :assigned_to_id => '',
1587 :assigned_to_id => '',
1585 :custom_field_values => {'2' => '777'}}
1588 :custom_field_values => {'2' => '777'}}
1586
1589
1587 assert_response 302
1590 assert_response 302
1588
1591
1589 issue = Issue.find(1)
1592 issue = Issue.find(1)
1590 journal = issue.journals.find(:first, :order => 'created_on DESC')
1593 journal = issue.journals.find(:first, :order => 'created_on DESC')
1591 assert_equal '777', issue.custom_value_for(2).value
1594 assert_equal '777', issue.custom_value_for(2).value
1592 assert_equal 1, journal.details.size
1595 assert_equal 1, journal.details.size
1593 assert_equal '125', journal.details.first.old_value
1596 assert_equal '125', journal.details.first.old_value
1594 assert_equal '777', journal.details.first.value
1597 assert_equal '777', journal.details.first.value
1595 end
1598 end
1596
1599
1597 def test_bulk_update_unassign
1600 def test_bulk_update_unassign
1598 assert_not_nil Issue.find(2).assigned_to
1601 assert_not_nil Issue.find(2).assigned_to
1599 @request.session[:user_id] = 2
1602 @request.session[:user_id] = 2
1600 # unassign issues
1603 # unassign issues
1601 post :bulk_update, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'}
1604 post :bulk_update, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'}
1602 assert_response 302
1605 assert_response 302
1603 # check that the issues were updated
1606 # check that the issues were updated
1604 assert_nil Issue.find(2).assigned_to
1607 assert_nil Issue.find(2).assigned_to
1605 end
1608 end
1606
1609
1607 def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject
1610 def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject
1608 @request.session[:user_id] = 2
1611 @request.session[:user_id] = 2
1609
1612
1610 post :bulk_update, :ids => [1,2], :issue => {:fixed_version_id => 4}
1613 post :bulk_update, :ids => [1,2], :issue => {:fixed_version_id => 4}
1611
1614
1612 assert_response :redirect
1615 assert_response :redirect
1613 issues = Issue.find([1,2])
1616 issues = Issue.find([1,2])
1614 issues.each do |issue|
1617 issues.each do |issue|
1615 assert_equal 4, issue.fixed_version_id
1618 assert_equal 4, issue.fixed_version_id
1616 assert_not_equal issue.project_id, issue.fixed_version.project_id
1619 assert_not_equal issue.project_id, issue.fixed_version.project_id
1617 end
1620 end
1618 end
1621 end
1619
1622
1620 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
1623 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
1621 @request.session[:user_id] = 2
1624 @request.session[:user_id] = 2
1622 post :bulk_update, :ids => [1,2], :back_url => '/issues'
1625 post :bulk_update, :ids => [1,2], :back_url => '/issues'
1623
1626
1624 assert_response :redirect
1627 assert_response :redirect
1625 assert_redirected_to '/issues'
1628 assert_redirected_to '/issues'
1626 end
1629 end
1627
1630
1628 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
1631 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
1629 @request.session[:user_id] = 2
1632 @request.session[:user_id] = 2
1630 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
1633 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
1631
1634
1632 assert_response :redirect
1635 assert_response :redirect
1633 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier
1636 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier
1634 end
1637 end
1635
1638
1636 def test_destroy_issue_with_no_time_entries
1639 def test_destroy_issue_with_no_time_entries
1637 assert_nil TimeEntry.find_by_issue_id(2)
1640 assert_nil TimeEntry.find_by_issue_id(2)
1638 @request.session[:user_id] = 2
1641 @request.session[:user_id] = 2
1639 post :destroy, :id => 2
1642 post :destroy, :id => 2
1640 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1643 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1641 assert_nil Issue.find_by_id(2)
1644 assert_nil Issue.find_by_id(2)
1642 end
1645 end
1643
1646
1644 def test_destroy_issues_with_time_entries
1647 def test_destroy_issues_with_time_entries
1645 @request.session[:user_id] = 2
1648 @request.session[:user_id] = 2
1646 post :destroy, :ids => [1, 3]
1649 post :destroy, :ids => [1, 3]
1647 assert_response :success
1650 assert_response :success
1648 assert_template 'destroy'
1651 assert_template 'destroy'
1649 assert_not_nil assigns(:hours)
1652 assert_not_nil assigns(:hours)
1650 assert Issue.find_by_id(1) && Issue.find_by_id(3)
1653 assert Issue.find_by_id(1) && Issue.find_by_id(3)
1651 end
1654 end
1652
1655
1653 def test_destroy_issues_and_destroy_time_entries
1656 def test_destroy_issues_and_destroy_time_entries
1654 @request.session[:user_id] = 2
1657 @request.session[:user_id] = 2
1655 post :destroy, :ids => [1, 3], :todo => 'destroy'
1658 post :destroy, :ids => [1, 3], :todo => 'destroy'
1656 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1659 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1657 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1660 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1658 assert_nil TimeEntry.find_by_id([1, 2])
1661 assert_nil TimeEntry.find_by_id([1, 2])
1659 end
1662 end
1660
1663
1661 def test_destroy_issues_and_assign_time_entries_to_project
1664 def test_destroy_issues_and_assign_time_entries_to_project
1662 @request.session[:user_id] = 2
1665 @request.session[:user_id] = 2
1663 post :destroy, :ids => [1, 3], :todo => 'nullify'
1666 post :destroy, :ids => [1, 3], :todo => 'nullify'
1664 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1667 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1665 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1668 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1666 assert_nil TimeEntry.find(1).issue_id
1669 assert_nil TimeEntry.find(1).issue_id
1667 assert_nil TimeEntry.find(2).issue_id
1670 assert_nil TimeEntry.find(2).issue_id
1668 end
1671 end
1669
1672
1670 def test_destroy_issues_and_reassign_time_entries_to_another_issue
1673 def test_destroy_issues_and_reassign_time_entries_to_another_issue
1671 @request.session[:user_id] = 2
1674 @request.session[:user_id] = 2
1672 post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
1675 post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
1673 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1676 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1674 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1677 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1675 assert_equal 2, TimeEntry.find(1).issue_id
1678 assert_equal 2, TimeEntry.find(1).issue_id
1676 assert_equal 2, TimeEntry.find(2).issue_id
1679 assert_equal 2, TimeEntry.find(2).issue_id
1677 end
1680 end
1678
1681
1679 def test_destroy_issues_from_different_projects
1682 def test_destroy_issues_from_different_projects
1680 @request.session[:user_id] = 2
1683 @request.session[:user_id] = 2
1681 post :destroy, :ids => [1, 2, 6], :todo => 'destroy'
1684 post :destroy, :ids => [1, 2, 6], :todo => 'destroy'
1682 assert_redirected_to :controller => 'issues', :action => 'index'
1685 assert_redirected_to :controller => 'issues', :action => 'index'
1683 assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6))
1686 assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6))
1684 end
1687 end
1685
1688
1686 def test_destroy_parent_and_child_issues
1689 def test_destroy_parent_and_child_issues
1687 parent = Issue.generate!(:project_id => 1, :tracker_id => 1)
1690 parent = Issue.generate!(:project_id => 1, :tracker_id => 1)
1688 child = Issue.generate!(:project_id => 1, :tracker_id => 1, :parent_issue_id => parent.id)
1691 child = Issue.generate!(:project_id => 1, :tracker_id => 1, :parent_issue_id => parent.id)
1689 assert child.is_descendant_of?(parent.reload)
1692 assert child.is_descendant_of?(parent.reload)
1690
1693
1691 @request.session[:user_id] = 2
1694 @request.session[:user_id] = 2
1692 assert_difference 'Issue.count', -2 do
1695 assert_difference 'Issue.count', -2 do
1693 post :destroy, :ids => [parent.id, child.id], :todo => 'destroy'
1696 post :destroy, :ids => [parent.id, child.id], :todo => 'destroy'
1694 end
1697 end
1695 assert_response 302
1698 assert_response 302
1696 end
1699 end
1697
1700
1698 def test_default_search_scope
1701 def test_default_search_scope
1699 get :index
1702 get :index
1700 assert_tag :div, :attributes => {:id => 'quick-search'},
1703 assert_tag :div, :attributes => {:id => 'quick-search'},
1701 :child => {:tag => 'form',
1704 :child => {:tag => 'form',
1702 :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}}
1705 :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}}
1703 end
1706 end
1704 end
1707 end
General Comments 0
You need to be logged in to leave comments. Login now