##// END OF EJS Templates
Adds a few functional tests....
Jean-Philippe Lang -
r13336:c084ef509f11
parent child
Show More
@@ -1,152 +1,160
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19
20 20 class ActivitiesControllerTest < ActionController::TestCase
21 21 fixtures :projects, :trackers, :issue_statuses, :issues,
22 22 :enumerations, :users, :issue_categories,
23 23 :projects_trackers,
24 24 :roles,
25 25 :member_roles,
26 26 :members,
27 27 :groups_users,
28 28 :enabled_modules,
29 29 :journals, :journal_details
30 30
31 31
32 32 def test_project_index
33 33 get :index, :id => 1, :with_subprojects => 0
34 34 assert_response :success
35 35 assert_template 'index'
36 36 assert_not_nil assigns(:events_by_day)
37 37
38 38 assert_select 'h3', :text => /#{2.days.ago.to_date.day}/
39 39 assert_select 'dl dt.issue-edit a', :text => /(#{IssueStatus.find(2).name})/
40 40 end
41 41
42 42 def test_project_index_with_invalid_project_id_should_respond_404
43 43 get :index, :id => 299
44 44 assert_response 404
45 45 end
46 46
47 47 def test_previous_project_index
48 48 get :index, :id => 1, :from => 2.days.ago.to_date
49 49 assert_response :success
50 50 assert_template 'index'
51 51 assert_not_nil assigns(:events_by_day)
52 52
53 53 assert_select 'h3', :text => /#{3.days.ago.to_date.day}/
54 54 assert_select 'dl dt.issue a', :text => /#{ESCAPED_UCANT} print recipes/
55 55 end
56 56
57 57 def test_global_index
58 58 @request.session[:user_id] = 1
59 59 get :index
60 60 assert_response :success
61 61 assert_template 'index'
62 62 assert_not_nil assigns(:events_by_day)
63 63
64 64 i5 = Issue.find(5)
65 65 d5 = User.find(1).time_to_date(i5.created_on)
66 66
67 67 assert_select 'h3', :text => /#{d5.day}/
68 68 assert_select 'dl dt.issue a', :text => /Subproject issue/
69 69 end
70 70
71 71 def test_user_index
72 72 @request.session[:user_id] = 1
73 73 get :index, :user_id => 2
74 74 assert_response :success
75 75 assert_template 'index'
76 76 assert_not_nil assigns(:events_by_day)
77 77
78 78 assert_select 'h2 a[href="/users/2"]', :text => 'John Smith'
79 79
80 80 i1 = Issue.find(1)
81 81 d1 = User.find(1).time_to_date(i1.created_on)
82 82
83 83 assert_select 'h3', :text => /#{d1.day}/
84 84 assert_select 'dl dt.issue a', :text => /#{ESCAPED_UCANT} print recipes/
85 85 end
86 86
87 87 def test_user_index_with_invalid_user_id_should_respond_404
88 88 get :index, :user_id => 299
89 89 assert_response 404
90 90 end
91 91
92 92 def test_index_atom_feed
93 93 get :index, :format => 'atom', :with_subprojects => 0
94 94 assert_response :success
95 95 assert_template 'common/feed'
96 96
97 97 assert_select 'feed' do
98 98 assert_select 'link[rel=self][href=?]', 'http://test.host/activity.atom?with_subprojects=0'
99 99 assert_select 'link[rel=alternate][href=?]', 'http://test.host/activity?with_subprojects=0'
100 100 assert_select 'entry' do
101 101 assert_select 'link[href=?]', 'http://test.host/issues/11'
102 102 end
103 103 end
104 104 end
105 105
106 106 def test_index_atom_feed_with_explicit_selection
107 107 get :index, :format => 'atom', :with_subprojects => 0,
108 108 :show_changesets => 1,
109 109 :show_documents => 1,
110 110 :show_files => 1,
111 111 :show_issues => 1,
112 112 :show_messages => 1,
113 113 :show_news => 1,
114 114 :show_time_entries => 1,
115 115 :show_wiki_edits => 1
116 116
117 117 assert_response :success
118 118 assert_template 'common/feed'
119 119
120 120 assert_select 'feed' do
121 121 assert_select 'link[rel=self][href=?]', 'http://test.host/activity.atom?show_changesets=1&amp;show_documents=1&amp;show_files=1&amp;show_issues=1&amp;show_messages=1&amp;show_news=1&amp;show_time_entries=1&amp;show_wiki_edits=1&amp;with_subprojects=0'
122 122 assert_select 'link[rel=alternate][href=?]', 'http://test.host/activity?show_changesets=1&amp;show_documents=1&amp;show_files=1&amp;show_issues=1&amp;show_messages=1&amp;show_news=1&amp;show_time_entries=1&amp;show_wiki_edits=1&amp;with_subprojects=0'
123 123 assert_select 'entry' do
124 124 assert_select 'link[href=?]', 'http://test.host/issues/11'
125 125 end
126 126 end
127 127 end
128 128
129 129 def test_index_atom_feed_with_one_item_type
130 130 with_settings :default_language => 'en' do
131 131 get :index, :format => 'atom', :show_issues => '1'
132 132 assert_response :success
133 133 assert_template 'common/feed'
134 134
135 135 assert_select 'title', :text => /Issues/
136 136 end
137 137 end
138 138
139 def test_index_atom_feed_with_user
140 get :index, :user_id => 2, :format => 'atom'
141
142 assert_response :success
143 assert_template 'common/feed'
144 assert_select 'title', :text => "Redmine: #{User.find(2).name}"
145 end
146
139 147 def test_index_should_show_private_notes_with_permission_only
140 148 journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Private notes with searchkeyword', :private_notes => true)
141 149 @request.session[:user_id] = 2
142 150
143 151 get :index
144 152 assert_response :success
145 153 assert_include journal, assigns(:events_by_day).values.flatten
146 154
147 155 Role.find(1).remove_permission! :view_private_notes
148 156 get :index
149 157 assert_response :success
150 158 assert_not_include journal, assigns(:events_by_day).values.flatten
151 159 end
152 160 end
@@ -1,453 +1,458
1 1 # encoding: utf-8
2 2 #
3 3 # Redmine - project management software
4 4 # Copyright (C) 2006-2014 Jean-Philippe Lang
5 5 #
6 6 # This program is free software; you can redistribute it and/or
7 7 # modify it under the terms of the GNU General Public License
8 8 # as published by the Free Software Foundation; either version 2
9 9 # of the License, or (at your option) any later version.
10 10 #
11 11 # This program is distributed in the hope that it will be useful,
12 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 14 # GNU General Public License for more details.
15 15 #
16 16 # You should have received a copy of the GNU General Public License
17 17 # along with this program; if not, write to the Free Software
18 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 19
20 20 require File.expand_path('../../test_helper', __FILE__)
21 21
22 22 class AttachmentsControllerTest < ActionController::TestCase
23 23 fixtures :users, :projects, :roles, :members, :member_roles,
24 24 :enabled_modules, :issues, :trackers, :attachments,
25 25 :versions, :wiki_pages, :wikis, :documents
26 26
27 27 def setup
28 28 User.current = nil
29 29 set_fixtures_attachments_directory
30 30 end
31 31
32 32 def teardown
33 33 set_tmp_attachments_directory
34 34 end
35 35
36 36 def test_show_diff
37 37 ['inline', 'sbs'].each do |dt|
38 38 # 060719210727_changeset_utf8.diff
39 39 get :show, :id => 14, :type => dt
40 40 assert_response :success
41 41 assert_template 'diff'
42 42 assert_equal 'text/html', @response.content_type
43 43 assert_select 'th.filename', :text => /issues_controller.rb\t\(rΓ©vision 1484\)/
44 44 assert_select 'td.line-code', :text => /Demande créée avec succès/
45 45 end
46 46 set_tmp_attachments_directory
47 47 end
48 48
49 49 def test_show_diff_replace_cannot_convert_content
50 50 with_settings :repositories_encodings => 'UTF-8' do
51 51 ['inline', 'sbs'].each do |dt|
52 52 # 060719210727_changeset_iso8859-1.diff
53 53 get :show, :id => 5, :type => dt
54 54 assert_response :success
55 55 assert_template 'diff'
56 56 assert_equal 'text/html', @response.content_type
57 57 assert_select 'th.filename', :text => /issues_controller.rb\t\(r\?vision 1484\)/
58 58 assert_select 'td.line-code', :text => /Demande cr\?\?e avec succ\?s/
59 59 end
60 60 end
61 61 set_tmp_attachments_directory
62 62 end
63 63
64 64 def test_show_diff_latin_1
65 65 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
66 66 ['inline', 'sbs'].each do |dt|
67 67 # 060719210727_changeset_iso8859-1.diff
68 68 get :show, :id => 5, :type => dt
69 69 assert_response :success
70 70 assert_template 'diff'
71 71 assert_equal 'text/html', @response.content_type
72 72 assert_select 'th.filename', :text => /issues_controller.rb\t\(rΓ©vision 1484\)/
73 73 assert_select 'td.line-code', :text => /Demande créée avec succès/
74 74 end
75 75 end
76 76 set_tmp_attachments_directory
77 77 end
78 78
79 79 def test_save_diff_type
80 80 user1 = User.find(1)
81 81 user1.pref[:diff_type] = nil
82 82 user1.preference.save
83 83 user = User.find(1)
84 84 assert_nil user.pref[:diff_type]
85 85
86 86 @request.session[:user_id] = 1 # admin
87 87 get :show, :id => 5
88 88 assert_response :success
89 89 assert_template 'diff'
90 90 user.reload
91 91 assert_equal "inline", user.pref[:diff_type]
92 92 get :show, :id => 5, :type => 'sbs'
93 93 assert_response :success
94 94 assert_template 'diff'
95 95 user.reload
96 96 assert_equal "sbs", user.pref[:diff_type]
97 97 end
98 98
99 99 def test_diff_show_filename_in_mercurial_export
100 100 set_tmp_attachments_directory
101 101 a = Attachment.new(:container => Issue.find(1),
102 102 :file => uploaded_test_file("hg-export.diff", "text/plain"),
103 103 :author => User.find(1))
104 104 assert a.save
105 105 assert_equal 'hg-export.diff', a.filename
106 106
107 107 get :show, :id => a.id, :type => 'inline'
108 108 assert_response :success
109 109 assert_template 'diff'
110 110 assert_equal 'text/html', @response.content_type
111 111 assert_select 'th.filename', :text => 'test1.txt'
112 112 end
113 113
114 114 def test_show_text_file
115 115 get :show, :id => 4
116 116 assert_response :success
117 117 assert_template 'file'
118 118 assert_equal 'text/html', @response.content_type
119 119 set_tmp_attachments_directory
120 120 end
121 121
122 122 def test_show_text_file_utf_8
123 123 set_tmp_attachments_directory
124 124 a = Attachment.new(:container => Issue.find(1),
125 125 :file => uploaded_test_file("japanese-utf-8.txt", "text/plain"),
126 126 :author => User.find(1))
127 127 assert a.save
128 128 assert_equal 'japanese-utf-8.txt', a.filename
129 129
130 130 str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e".force_encoding('UTF-8')
131 131
132 132 get :show, :id => a.id
133 133 assert_response :success
134 134 assert_template 'file'
135 135 assert_equal 'text/html', @response.content_type
136 136 assert_select 'tr#L1' do
137 137 assert_select 'th.line-num', :text => '1'
138 138 assert_select 'td', :text => /#{str_japanese}/
139 139 end
140 140 end
141 141
142 142 def test_show_text_file_replace_cannot_convert_content
143 143 set_tmp_attachments_directory
144 144 with_settings :repositories_encodings => 'UTF-8' do
145 145 a = Attachment.new(:container => Issue.find(1),
146 146 :file => uploaded_test_file("iso8859-1.txt", "text/plain"),
147 147 :author => User.find(1))
148 148 assert a.save
149 149 assert_equal 'iso8859-1.txt', a.filename
150 150
151 151 get :show, :id => a.id
152 152 assert_response :success
153 153 assert_template 'file'
154 154 assert_equal 'text/html', @response.content_type
155 155 assert_select 'tr#L7' do
156 156 assert_select 'th.line-num', :text => '7'
157 157 assert_select 'td', :text => /Demande cr\?\?e avec succ\?s/
158 158 end
159 159 end
160 160 end
161 161
162 162 def test_show_text_file_latin_1
163 163 set_tmp_attachments_directory
164 164 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
165 165 a = Attachment.new(:container => Issue.find(1),
166 166 :file => uploaded_test_file("iso8859-1.txt", "text/plain"),
167 167 :author => User.find(1))
168 168 assert a.save
169 169 assert_equal 'iso8859-1.txt', a.filename
170 170
171 171 get :show, :id => a.id
172 172 assert_response :success
173 173 assert_template 'file'
174 174 assert_equal 'text/html', @response.content_type
175 175 assert_select 'tr#L7' do
176 176 assert_select 'th.line-num', :text => '7'
177 177 assert_select 'td', :text => /Demande créée avec succès/
178 178 end
179 179 end
180 180 end
181 181
182 182 def test_show_text_file_should_send_if_too_big
183 183 with_settings :file_max_size_displayed => 512 do
184 184 Attachment.find(4).update_attribute :filesize, 754.kilobyte
185 185 get :show, :id => 4
186 186 assert_response :success
187 187 assert_equal 'application/x-ruby', @response.content_type
188 188 end
189 189 set_tmp_attachments_directory
190 190 end
191 191
192 192 def test_show_other
193 193 get :show, :id => 6
194 194 assert_response :success
195 195 assert_equal 'application/octet-stream', @response.content_type
196 196 set_tmp_attachments_directory
197 197 end
198 198
199 199 def test_show_file_from_private_issue_without_permission
200 200 get :show, :id => 15
201 201 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2F15'
202 202 set_tmp_attachments_directory
203 203 end
204 204
205 205 def test_show_file_from_private_issue_with_permission
206 206 @request.session[:user_id] = 2
207 207 get :show, :id => 15
208 208 assert_response :success
209 209 assert_select 'h2', :text => /private.diff/
210 210 set_tmp_attachments_directory
211 211 end
212 212
213 213 def test_show_file_without_container_should_be_allowed_to_author
214 214 set_tmp_attachments_directory
215 215 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
216 216
217 217 @request.session[:user_id] = 2
218 218 get :show, :id => attachment.id
219 219 assert_response 200
220 220 end
221 221
222 222 def test_show_file_without_container_should_be_denied_to_other_users
223 223 set_tmp_attachments_directory
224 224 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
225 225
226 226 @request.session[:user_id] = 3
227 227 get :show, :id => attachment.id
228 228 assert_response 403
229 229 end
230 230
231 231 def test_show_invalid_should_respond_with_404
232 232 get :show, :id => 999
233 233 assert_response 404
234 234 end
235 235
236 236 def test_download_text_file
237 237 get :download, :id => 4
238 238 assert_response :success
239 239 assert_equal 'application/x-ruby', @response.content_type
240 240 etag = @response.etag
241 241 assert_not_nil etag
242 242
243 243 @request.env["HTTP_IF_NONE_MATCH"] = etag
244 244 get :download, :id => 4
245 245 assert_response 304
246 246
247 247 set_tmp_attachments_directory
248 248 end
249 249
250 250 def test_download_version_file_with_issue_tracking_disabled
251 251 Project.find(1).disable_module! :issue_tracking
252 252 get :download, :id => 9
253 253 assert_response :success
254 254 end
255 255
256 256 def test_download_should_assign_content_type_if_blank
257 257 Attachment.find(4).update_attribute(:content_type, '')
258 258
259 259 get :download, :id => 4
260 260 assert_response :success
261 261 assert_equal 'text/x-ruby', @response.content_type
262 262 set_tmp_attachments_directory
263 263 end
264 264
265 265 def test_download_missing_file
266 266 get :download, :id => 2
267 267 assert_response 404
268 268 set_tmp_attachments_directory
269 269 end
270 270
271 271 def test_download_should_be_denied_without_permission
272 272 get :download, :id => 7
273 273 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdownload%2F7'
274 274 set_tmp_attachments_directory
275 275 end
276 276
277 277 if convert_installed?
278 278 def test_thumbnail
279 279 Attachment.clear_thumbnails
280 280 @request.session[:user_id] = 2
281 281 get :thumbnail, :id => 16
282 282 assert_response :success
283 283 assert_equal 'image/png', response.content_type
284 284
285 285 etag = @response.etag
286 286 assert_not_nil etag
287 287
288 288 @request.env["HTTP_IF_NONE_MATCH"] = etag
289 289 get :thumbnail, :id => 16
290 290 assert_response 304
291 291 end
292 292
293 293 def test_thumbnail_should_not_exceed_maximum_size
294 294 Redmine::Thumbnail.expects(:generate).with {|source, target, size| size == 800}
295 295
296 296 @request.session[:user_id] = 2
297 297 get :thumbnail, :id => 16, :size => 2000
298 298 end
299 299
300 300 def test_thumbnail_should_round_size
301 301 Redmine::Thumbnail.expects(:generate).with {|source, target, size| size == 250}
302 302
303 303 @request.session[:user_id] = 2
304 304 get :thumbnail, :id => 16, :size => 260
305 305 end
306 306
307 307 def test_thumbnail_should_return_404_for_non_image_attachment
308 308 @request.session[:user_id] = 2
309 309
310 310 get :thumbnail, :id => 15
311 311 assert_response 404
312 312 end
313 313
314 314 def test_thumbnail_should_return_404_if_thumbnail_generation_failed
315 315 Attachment.any_instance.stubs(:thumbnail).returns(nil)
316 316 @request.session[:user_id] = 2
317 317
318 318 get :thumbnail, :id => 16
319 319 assert_response 404
320 320 end
321 321
322 322 def test_thumbnail_should_be_denied_without_permission
323 323 get :thumbnail, :id => 16
324 324 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fthumbnail%2F16'
325 325 end
326 326 else
327 327 puts '(ImageMagick convert not available)'
328 328 end
329 329
330 330 def test_edit
331 331 @request.session[:user_id] = 2
332 332 get :edit, :object_type => 'issues', :object_id => '3'
333 333 assert_response :success
334 334 assert_template 'edit'
335 335
336 336 container = Issue.find(3)
337 337 assert_equal container, assigns(:container)
338 338 assert_equal container.attachments.size, assigns(:attachments).size
339 339
340 340 assert_select 'form[action=?]', '/attachments/issues/3' do
341 341 assert_select 'tr#attachment-4' do
342 342 assert_select 'input[name=?][value=?]', 'attachments[4][filename]', 'source.rb'
343 343 assert_select 'input[name=?][value=?]', 'attachments[4][description]', 'This is a Ruby source file'
344 344 end
345 345 end
346 346 end
347 347
348 348 def test_edit_invalid_container_class_should_return_404
349 349 get :edit, :object_type => 'nuggets', :object_id => '3'
350 350 assert_response 404
351 351 end
352 352
353 def test_edit_invalid_object_should_return_404
354 get :edit, :object_type => 'issues', :object_id => '999'
355 assert_response 404
356 end
357
353 358 def test_edit_for_object_that_is_not_visible_should_return_403
354 359 get :edit, :object_type => 'issues', :object_id => '4'
355 360 assert_response 403
356 361 end
357 362
358 363 def test_update
359 364 @request.session[:user_id] = 2
360 365 patch :update, :object_type => 'issues', :object_id => '3', :attachments => {
361 366 '1' => {:filename => 'newname.text', :description => ''},
362 367 '4' => {:filename => 'newname.rb', :description => 'Renamed'},
363 368 }
364 369
365 370 assert_response 302
366 371 attachment = Attachment.find(4)
367 372 assert_equal 'newname.rb', attachment.filename
368 373 assert_equal 'Renamed', attachment.description
369 374 end
370 375
371 376 def test_update_with_failure
372 377 @request.session[:user_id] = 2
373 378 patch :update, :object_type => 'issues', :object_id => '3', :attachments => {
374 379 '1' => {:filename => '', :description => ''},
375 380 '4' => {:filename => 'newname.rb', :description => 'Renamed'},
376 381 }
377 382
378 383 assert_response :success
379 384 assert_template 'edit'
380 385 assert_select_error /file #{ESCAPED_CANT} be blank/i
381 386
382 387 # The other attachment should not be updated
383 388 attachment = Attachment.find(4)
384 389 assert_equal 'source.rb', attachment.filename
385 390 assert_equal 'This is a Ruby source file', attachment.description
386 391 end
387 392
388 393 def test_destroy_issue_attachment
389 394 set_tmp_attachments_directory
390 395 issue = Issue.find(3)
391 396 @request.session[:user_id] = 2
392 397
393 398 assert_difference 'issue.attachments.count', -1 do
394 399 assert_difference 'Journal.count' do
395 400 delete :destroy, :id => 1
396 401 assert_redirected_to '/projects/ecookbook'
397 402 end
398 403 end
399 404 assert_nil Attachment.find_by_id(1)
400 405 j = Journal.order('id DESC').first
401 406 assert_equal issue, j.journalized
402 407 assert_equal 'attachment', j.details.first.property
403 408 assert_equal '1', j.details.first.prop_key
404 409 assert_equal 'error281.txt', j.details.first.old_value
405 410 assert_equal User.find(2), j.user
406 411 end
407 412
408 413 def test_destroy_wiki_page_attachment
409 414 set_tmp_attachments_directory
410 415 @request.session[:user_id] = 2
411 416 assert_difference 'Attachment.count', -1 do
412 417 delete :destroy, :id => 3
413 418 assert_response 302
414 419 end
415 420 end
416 421
417 422 def test_destroy_project_attachment
418 423 set_tmp_attachments_directory
419 424 @request.session[:user_id] = 2
420 425 assert_difference 'Attachment.count', -1 do
421 426 delete :destroy, :id => 8
422 427 assert_response 302
423 428 end
424 429 end
425 430
426 431 def test_destroy_version_attachment
427 432 set_tmp_attachments_directory
428 433 @request.session[:user_id] = 2
429 434 assert_difference 'Attachment.count', -1 do
430 435 delete :destroy, :id => 9
431 436 assert_response 302
432 437 end
433 438 end
434 439
435 440 def test_destroy_version_attachment_with_issue_tracking_disabled
436 441 Project.find(1).disable_module! :issue_tracking
437 442 set_tmp_attachments_directory
438 443 @request.session[:user_id] = 2
439 444 assert_difference 'Attachment.count', -1 do
440 445 delete :destroy, :id => 9
441 446 assert_response 302
442 447 end
443 448 end
444 449
445 450 def test_destroy_without_permission
446 451 set_tmp_attachments_directory
447 452 assert_no_difference 'Attachment.count' do
448 453 delete :destroy, :id => 3
449 454 end
450 455 assert_response 302
451 456 assert Attachment.find_by_id(3)
452 457 end
453 458 end
@@ -1,279 +1,288
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19
20 20 class ContextMenusControllerTest < ActionController::TestCase
21 21 fixtures :projects,
22 22 :trackers,
23 23 :projects_trackers,
24 24 :roles,
25 25 :member_roles,
26 26 :members,
27 27 :enabled_modules,
28 28 :workflows,
29 29 :journals, :journal_details,
30 30 :versions,
31 31 :issues, :issue_statuses, :issue_categories,
32 32 :users,
33 33 :enumerations,
34 34 :time_entries
35 35
36 36 def test_context_menu_one_issue
37 37 @request.session[:user_id] = 2
38 38 get :issues, :ids => [1]
39 39 assert_response :success
40 40 assert_template 'context_menus/issues'
41 41
42 42 assert_select 'a.icon-edit[href=?]', '/issues/1/edit', :text => 'Edit'
43 43 assert_select 'a.icon-copy[href=?]', '/projects/ecookbook/issues/1/copy', :text => 'Copy'
44 44 assert_select 'a.icon-del[href=?]', '/issues?ids%5B%5D=1', :text => 'Delete'
45 45
46 46 # Statuses
47 47 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bstatus_id%5D=5', :text => 'Closed'
48 48 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bpriority_id%5D=8', :text => 'Immediate'
49 49 # No inactive priorities
50 50 assert_select 'a', :text => /Inactive Priority/, :count => 0
51 51 # Versions
52 52 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bfixed_version_id%5D=3', :text => '2.0'
53 53 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bfixed_version_id%5D=4', :text => 'eCookbook Subproject 1 - 2.0'
54 54 # Assignees
55 55 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bassigned_to_id%5D=3', :text => 'Dave Lopper'
56 56 end
57 57
58 58 def test_context_menu_one_issue_by_anonymous
59 59 with_settings :default_language => 'en' do
60 60 get :issues, :ids => [1]
61 61 assert_response :success
62 62 assert_template 'context_menus/issues'
63 63 assert_select 'a.icon-del.disabled[href="#"]', :text => 'Delete'
64 64 end
65 65 end
66 66
67 67 def test_context_menu_multiple_issues_of_same_project
68 68 @request.session[:user_id] = 2
69 69 get :issues, :ids => [1, 2]
70 70 assert_response :success
71 71 assert_template 'context_menus/issues'
72 72 assert_not_nil assigns(:issues)
73 73 assert_equal [1, 2], assigns(:issues).map(&:id).sort
74 74
75 75 ids = assigns(:issues).map(&:id).sort.map {|i| "ids%5B%5D=#{i}"}.join('&amp;')
76 76
77 77 assert_select 'a.icon-edit[href=?]', "/issues/bulk_edit?#{ids}", :text => 'Edit'
78 78 assert_select 'a.icon-copy[href=?]', "/issues/bulk_edit?copy=1&amp;#{ids}", :text => 'Copy'
79 79 assert_select 'a.icon-del[href=?]', "/issues?#{ids}", :text => 'Delete'
80 80
81 81 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bstatus_id%5D=5", :text => 'Closed'
82 82 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bpriority_id%5D=8", :text => 'Immediate'
83 83 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bassigned_to_id%5D=3", :text => 'Dave Lopper'
84 84 end
85 85
86 86 def test_context_menu_multiple_issues_of_different_projects
87 87 @request.session[:user_id] = 2
88 88 get :issues, :ids => [1, 2, 6]
89 89 assert_response :success
90 90 assert_template 'context_menus/issues'
91 91 assert_not_nil assigns(:issues)
92 92 assert_equal [1, 2, 6], assigns(:issues).map(&:id).sort
93 93
94 94 ids = assigns(:issues).map(&:id).sort.map {|i| "ids%5B%5D=#{i}"}.join('&amp;')
95 95
96 96 assert_select 'a.icon-edit[href=?]', "/issues/bulk_edit?#{ids}", :text => 'Edit'
97 97 assert_select 'a.icon-del[href=?]', "/issues?#{ids}", :text => 'Delete'
98 98
99 99 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bstatus_id%5D=5", :text => 'Closed'
100 100 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bpriority_id%5D=8", :text => 'Immediate'
101 101 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bassigned_to_id%5D=2", :text => 'John Smith'
102 102 end
103 103
104 104 def test_context_menu_should_include_list_custom_fields
105 105 field = IssueCustomField.create!(:name => 'List', :field_format => 'list',
106 106 :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
107 107 @request.session[:user_id] = 2
108 108 get :issues, :ids => [1]
109 109
110 110 assert_select "li.cf_#{field.id}" do
111 111 assert_select 'a[href=#]', :text => 'List'
112 112 assert_select 'ul' do
113 113 assert_select 'a', 3
114 114 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=Foo", :text => 'Foo'
115 115 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
116 116 end
117 117 end
118 118 end
119 119
120 120 def test_context_menu_should_not_include_null_value_for_required_custom_fields
121 121 field = IssueCustomField.create!(:name => 'List', :is_required => true, :field_format => 'list',
122 122 :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
123 123 @request.session[:user_id] = 2
124 124 get :issues, :ids => [1, 2]
125 125
126 126 assert_select "li.cf_#{field.id}" do
127 127 assert_select 'a[href=#]', :text => 'List'
128 128 assert_select 'ul' do
129 129 assert_select 'a', 2
130 130 assert_select 'a', :text => 'none', :count => 0
131 131 end
132 132 end
133 133 end
134 134
135 135 def test_context_menu_on_single_issue_should_select_current_custom_field_value
136 136 field = IssueCustomField.create!(:name => 'List', :field_format => 'list',
137 137 :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
138 138 issue = Issue.find(1)
139 139 issue.custom_field_values = {field.id => 'Bar'}
140 140 issue.save!
141 141 @request.session[:user_id] = 2
142 142 get :issues, :ids => [1]
143 143
144 144 assert_select "li.cf_#{field.id}" do
145 145 assert_select 'a[href=#]', :text => 'List'
146 146 assert_select 'ul' do
147 147 assert_select 'a', 3
148 148 assert_select 'a.icon-checked', :text => 'Bar'
149 149 end
150 150 end
151 151 end
152 152
153 153 def test_context_menu_should_include_bool_custom_fields
154 154 field = IssueCustomField.create!(:name => 'Bool', :field_format => 'bool',
155 155 :is_for_all => true, :tracker_ids => [1, 2, 3])
156 156 @request.session[:user_id] = 2
157 157 get :issues, :ids => [1]
158 158
159 159 assert_select "li.cf_#{field.id}" do
160 160 assert_select 'a[href=#]', :text => 'Bool'
161 161 assert_select 'ul' do
162 162 assert_select 'a', 3
163 163 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=0", :text => 'No'
164 164 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=1", :text => 'Yes'
165 165 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
166 166 end
167 167 end
168 168 end
169 169
170 170 def test_context_menu_should_include_user_custom_fields
171 171 field = IssueCustomField.create!(:name => 'User', :field_format => 'user',
172 172 :is_for_all => true, :tracker_ids => [1, 2, 3])
173 173 @request.session[:user_id] = 2
174 174 get :issues, :ids => [1]
175 175
176 176 assert_select "li.cf_#{field.id}" do
177 177 assert_select 'a[href=#]', :text => 'User'
178 178 assert_select 'ul' do
179 179 assert_select 'a', Project.find(1).members.count + 1
180 180 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=2", :text => 'John Smith'
181 181 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
182 182 end
183 183 end
184 184 end
185 185
186 186 def test_context_menu_should_include_version_custom_fields
187 187 field = IssueCustomField.create!(:name => 'Version', :field_format => 'version', :is_for_all => true, :tracker_ids => [1, 2, 3])
188 188 @request.session[:user_id] = 2
189 189 get :issues, :ids => [1]
190 190
191 191 assert_select "li.cf_#{field.id}" do
192 192 assert_select 'a[href=#]', :text => 'Version'
193 193 assert_select 'ul' do
194 194 assert_select 'a', Project.find(1).shared_versions.count + 1
195 195 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=3", :text => '2.0'
196 196 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
197 197 end
198 198 end
199 199 end
200 200
201 201 def test_context_menu_should_show_enabled_custom_fields_for_the_role_only
202 202 enabled_cf = IssueCustomField.generate!(:field_format => 'bool', :is_for_all => true, :tracker_ids => [1], :visible => false, :role_ids => [1,2])
203 203 disabled_cf = IssueCustomField.generate!(:field_format => 'bool', :is_for_all => true, :tracker_ids => [1], :visible => false, :role_ids => [2])
204 204 issue = Issue.generate!(:project_id => 1, :tracker_id => 1)
205 205
206 206 @request.session[:user_id] = 2
207 207 get :issues, :ids => [issue.id]
208 208
209 209 assert_select "li.cf_#{enabled_cf.id}"
210 210 assert_select "li.cf_#{disabled_cf.id}", 0
211 211 end
212 212
213 213 def test_context_menu_by_assignable_user_should_include_assigned_to_me_link
214 214 @request.session[:user_id] = 2
215 215 get :issues, :ids => [1]
216 216 assert_response :success
217 217 assert_template 'context_menus/issues'
218 218
219 219 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bassigned_to_id%5D=2', :text => / me /
220 220 end
221 221
222 222 def test_context_menu_should_propose_shared_versions_for_issues_from_different_projects
223 223 @request.session[:user_id] = 2
224 224 version = Version.create!(:name => 'Shared', :sharing => 'system', :project_id => 1)
225 225
226 226 get :issues, :ids => [1, 4]
227 227 assert_response :success
228 228 assert_template 'context_menus/issues'
229 229
230 230 assert_include version, assigns(:versions)
231 231 assert_select 'a', :text => 'eCookbook - Shared'
232 232 end
233 233
234 234 def test_context_menu_with_issue_that_is_not_visible_should_fail
235 235 get :issues, :ids => [1, 4] # issue 4 is not visible
236 236 assert_response 302
237 237 end
238 238
239 239 def test_should_respond_with_404_without_ids
240 240 get :issues
241 241 assert_response 404
242 242 end
243 243
244 244 def test_time_entries_context_menu
245 245 @request.session[:user_id] = 2
246 246 get :time_entries, :ids => [1, 2]
247 247 assert_response :success
248 248 assert_template 'context_menus/time_entries'
249 249
250 250 assert_select 'a:not(.disabled)', :text => 'Edit'
251 251 end
252 252
253 def test_context_menu_for_one_time_entry
254 @request.session[:user_id] = 2
255 get :time_entries, :ids => [1]
256 assert_response :success
257 assert_template 'context_menus/time_entries'
258
259 assert_select 'a:not(.disabled)', :text => 'Edit'
260 end
261
253 262 def test_time_entries_context_menu_should_include_custom_fields
254 263 field = TimeEntryCustomField.generate!(:name => "Field", :field_format => "list", :possible_values => ["foo", "bar"])
255 264
256 265 @request.session[:user_id] = 2
257 266 get :time_entries, :ids => [1, 2]
258 267 assert_response :success
259 268 assert_select "li.cf_#{field.id}" do
260 269 assert_select 'a[href=#]', :text => "Field"
261 270 assert_select 'ul' do
262 271 assert_select 'a', 3
263 272 assert_select 'a[href=?]', "/time_entries/bulk_update?ids%5B%5D=1&amp;ids%5B%5D=2&amp;time_entry%5Bcustom_field_values%5D%5B#{field.id}%5D=foo", :text => 'foo'
264 273 assert_select 'a[href=?]', "/time_entries/bulk_update?ids%5B%5D=1&amp;ids%5B%5D=2&amp;time_entry%5Bcustom_field_values%5D%5B#{field.id}%5D=bar", :text => 'bar'
265 274 assert_select 'a[href=?]', "/time_entries/bulk_update?ids%5B%5D=1&amp;ids%5B%5D=2&amp;time_entry%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
266 275 end
267 276 end
268 277 end
269 278
270 279 def test_time_entries_context_menu_without_edit_permission
271 280 @request.session[:user_id] = 2
272 281 Role.find_by_name('Manager').remove_permission! :edit_time_entries
273 282
274 283 get :time_entries, :ids => [1, 2]
275 284 assert_response :success
276 285 assert_template 'context_menus/time_entries'
277 286 assert_select 'a.disabled', :text => 'Edit'
278 287 end
279 288 end
General Comments 0
You need to be logged in to leave comments. Login now