Mercurial > hg > soundsoftware-site
comparison test/functional/attachments_controller_test.rb @ 1115:433d4f72a19b redmine-2.2
Update to Redmine SVN revision 11137 on 2.2-stable branch
author | Chris Cannam |
---|---|
date | Mon, 07 Jan 2013 12:01:42 +0000 |
parents | cbb26bc654de |
children | bb32da3bea34 622f24f53b42 |
comparison
equal
deleted
inserted
replaced
929:5f33065ddc4b | 1115:433d4f72a19b |
---|---|
1 # encoding: utf-8 | 1 # encoding: utf-8 |
2 # | 2 # |
3 # Redmine - project management software | 3 # Redmine - project management software |
4 # Copyright (C) 2006-2011 Jean-Philippe Lang | 4 # Copyright (C) 2006-2012 Jean-Philippe Lang |
5 # | 5 # |
6 # This program is free software; you can redistribute it and/or | 6 # This program is free software; you can redistribute it and/or |
7 # modify it under the terms of the GNU General Public License | 7 # modify it under the terms of the GNU General Public License |
8 # as published by the Free Software Foundation; either version 2 | 8 # as published by the Free Software Foundation; either version 2 |
9 # of the License, or (at your option) any later version. | 9 # of the License, or (at your option) any later version. |
30 | 30 |
31 def setup | 31 def setup |
32 @controller = AttachmentsController.new | 32 @controller = AttachmentsController.new |
33 @request = ActionController::TestRequest.new | 33 @request = ActionController::TestRequest.new |
34 @response = ActionController::TestResponse.new | 34 @response = ActionController::TestResponse.new |
35 Attachment.storage_path = "#{Rails.root}/test/fixtures/files" | |
36 User.current = nil | 35 User.current = nil |
36 set_fixtures_attachments_directory | |
37 end | |
38 | |
39 def teardown | |
40 set_tmp_attachments_directory | |
37 end | 41 end |
38 | 42 |
39 def test_show_diff | 43 def test_show_diff |
40 ['inline', 'sbs'].each do |dt| | 44 ['inline', 'sbs'].each do |dt| |
41 # 060719210727_changeset_utf8.diff | 45 # 060719210727_changeset_utf8.diff |
90 end | 94 end |
91 set_tmp_attachments_directory | 95 set_tmp_attachments_directory |
92 end | 96 end |
93 | 97 |
94 def test_save_diff_type | 98 def test_save_diff_type |
99 user1 = User.find(1) | |
100 user1.pref[:diff_type] = nil | |
101 user1.preference.save | |
102 user = User.find(1) | |
103 assert_nil user.pref[:diff_type] | |
104 | |
95 @request.session[:user_id] = 1 # admin | 105 @request.session[:user_id] = 1 # admin |
96 user = User.find(1) | |
97 get :show, :id => 5 | 106 get :show, :id => 5 |
98 assert_response :success | 107 assert_response :success |
99 assert_template 'diff' | 108 assert_template 'diff' |
100 user.reload | 109 user.reload |
101 assert_equal "inline", user.pref[:diff_type] | 110 assert_equal "inline", user.pref[:diff_type] |
102 get :show, :id => 5, :type => 'sbs' | 111 get :show, :id => 5, :type => 'sbs' |
103 assert_response :success | 112 assert_response :success |
104 assert_template 'diff' | 113 assert_template 'diff' |
105 user.reload | 114 user.reload |
106 assert_equal "sbs", user.pref[:diff_type] | 115 assert_equal "sbs", user.pref[:diff_type] |
116 end | |
117 | |
118 def test_diff_show_filename_in_mercurial_export | |
119 set_tmp_attachments_directory | |
120 a = Attachment.new(:container => Issue.find(1), | |
121 :file => uploaded_test_file("hg-export.diff", "text/plain"), | |
122 :author => User.find(1)) | |
123 assert a.save | |
124 assert_equal 'hg-export.diff', a.filename | |
125 | |
126 get :show, :id => a.id, :type => 'inline' | |
127 assert_response :success | |
128 assert_template 'diff' | |
129 assert_equal 'text/html', @response.content_type | |
130 assert_select 'th.filename', :text => 'test1.txt' | |
107 end | 131 end |
108 | 132 |
109 def test_show_text_file | 133 def test_show_text_file |
110 get :show, :id => 4 | 134 get :show, :id => 4 |
111 assert_response :success | 135 assert_response :success |
204 assert_response :success | 228 assert_response :success |
205 assert_tag 'h2', :content => /private.diff/ | 229 assert_tag 'h2', :content => /private.diff/ |
206 set_tmp_attachments_directory | 230 set_tmp_attachments_directory |
207 end | 231 end |
208 | 232 |
233 def test_show_file_without_container_should_be_denied | |
234 set_tmp_attachments_directory | |
235 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2) | |
236 | |
237 @request.session[:user_id] = 2 | |
238 get :show, :id => attachment.id | |
239 assert_response 403 | |
240 end | |
241 | |
242 def test_show_invalid_should_respond_with_404 | |
243 get :show, :id => 999 | |
244 assert_response 404 | |
245 end | |
246 | |
209 def test_download_text_file | 247 def test_download_text_file |
210 get :download, :id => 4 | 248 get :download, :id => 4 |
211 assert_response :success | 249 assert_response :success |
212 assert_equal 'application/x-ruby', @response.content_type | 250 assert_equal 'application/x-ruby', @response.content_type |
213 set_tmp_attachments_directory | 251 set_tmp_attachments_directory |
232 get :download, :id => 2 | 270 get :download, :id => 2 |
233 assert_response 404 | 271 assert_response 404 |
234 set_tmp_attachments_directory | 272 set_tmp_attachments_directory |
235 end | 273 end |
236 | 274 |
237 def test_anonymous_on_private_private | 275 def test_download_should_be_denied_without_permission |
238 get :download, :id => 7 | 276 get :download, :id => 7 |
239 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdownload%2F7' | 277 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdownload%2F7' |
240 set_tmp_attachments_directory | 278 set_tmp_attachments_directory |
241 end | 279 end |
242 | 280 |
281 if convert_installed? | |
282 def test_thumbnail | |
283 Attachment.clear_thumbnails | |
284 @request.session[:user_id] = 2 | |
285 | |
286 get :thumbnail, :id => 16 | |
287 assert_response :success | |
288 assert_equal 'image/png', response.content_type | |
289 end | |
290 | |
291 def test_thumbnail_should_not_exceed_maximum_size | |
292 Redmine::Thumbnail.expects(:generate).with {|source, target, size| size == 800} | |
293 | |
294 @request.session[:user_id] = 2 | |
295 get :thumbnail, :id => 16, :size => 2000 | |
296 end | |
297 | |
298 def test_thumbnail_should_round_size | |
299 Redmine::Thumbnail.expects(:generate).with {|source, target, size| size == 250} | |
300 | |
301 @request.session[:user_id] = 2 | |
302 get :thumbnail, :id => 16, :size => 260 | |
303 end | |
304 | |
305 def test_thumbnail_should_return_404_for_non_image_attachment | |
306 @request.session[:user_id] = 2 | |
307 | |
308 get :thumbnail, :id => 15 | |
309 assert_response 404 | |
310 end | |
311 | |
312 def test_thumbnail_should_return_404_if_thumbnail_generation_failed | |
313 Attachment.any_instance.stubs(:thumbnail).returns(nil) | |
314 @request.session[:user_id] = 2 | |
315 | |
316 get :thumbnail, :id => 16 | |
317 assert_response 404 | |
318 end | |
319 | |
320 def test_thumbnail_should_be_denied_without_permission | |
321 get :thumbnail, :id => 16 | |
322 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fthumbnail%2F16' | |
323 end | |
324 else | |
325 puts '(ImageMagick convert not available)' | |
326 end | |
327 | |
243 def test_destroy_issue_attachment | 328 def test_destroy_issue_attachment |
244 set_tmp_attachments_directory | 329 set_tmp_attachments_directory |
245 issue = Issue.find(3) | 330 issue = Issue.find(3) |
246 @request.session[:user_id] = 2 | 331 @request.session[:user_id] = 2 |
247 | 332 |
248 assert_difference 'issue.attachments.count', -1 do | 333 assert_difference 'issue.attachments.count', -1 do |
249 delete :destroy, :id => 1 | 334 assert_difference 'Journal.count' do |
250 end | 335 delete :destroy, :id => 1 |
251 # no referrer | 336 assert_redirected_to '/projects/ecookbook' |
252 assert_redirected_to '/projects/ecookbook' | 337 end |
338 end | |
253 assert_nil Attachment.find_by_id(1) | 339 assert_nil Attachment.find_by_id(1) |
254 j = issue.journals.find(:first, :order => 'created_on DESC') | 340 j = Journal.first(:order => 'id DESC') |
341 assert_equal issue, j.journalized | |
255 assert_equal 'attachment', j.details.first.property | 342 assert_equal 'attachment', j.details.first.property |
256 assert_equal '1', j.details.first.prop_key | 343 assert_equal '1', j.details.first.prop_key |
257 assert_equal 'error281.txt', j.details.first.old_value | 344 assert_equal 'error281.txt', j.details.first.old_value |
345 assert_equal User.find(2), j.user | |
258 end | 346 end |
259 | 347 |
260 def test_destroy_wiki_page_attachment | 348 def test_destroy_wiki_page_attachment |
261 set_tmp_attachments_directory | 349 set_tmp_attachments_directory |
262 @request.session[:user_id] = 2 | 350 @request.session[:user_id] = 2 |