annotate test/functional/attachments_controller_test.rb @ 8:0c83d98252d9 yuya

* Add custom repo prefix and proper auth realm, remove auth cache (seems like an unwise feature), pass DB handle around, various other bits of tidying
author Chris Cannam
date Thu, 12 Aug 2010 15:31:37 +0100
parents 513646585e45
children 94944d00e43c
rev   line source
Chris@0 1 # redMine - project management software
Chris@0 2 # Copyright (C) 2006-2008 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@0 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@0 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@0 18 require File.dirname(__FILE__) + '/../test_helper'
Chris@0 19 require 'attachments_controller'
Chris@0 20
Chris@0 21 # Re-raise errors caught by the controller.
Chris@0 22 class AttachmentsController; def rescue_action(e) raise e end; end
Chris@0 23
Chris@0 24
Chris@0 25 class AttachmentsControllerTest < ActionController::TestCase
Chris@0 26 fixtures :users, :projects, :roles, :members, :member_roles, :enabled_modules, :issues, :trackers, :attachments,
Chris@0 27 :versions, :wiki_pages, :wikis, :documents
Chris@0 28
Chris@0 29 def setup
Chris@0 30 @controller = AttachmentsController.new
Chris@0 31 @request = ActionController::TestRequest.new
Chris@0 32 @response = ActionController::TestResponse.new
Chris@0 33 Attachment.storage_path = "#{RAILS_ROOT}/test/fixtures/files"
Chris@0 34 User.current = nil
Chris@0 35 end
Chris@0 36
Chris@0 37 def test_show_diff
Chris@0 38 get :show, :id => 5
Chris@0 39 assert_response :success
Chris@0 40 assert_template 'diff'
Chris@0 41 assert_equal 'text/html', @response.content_type
Chris@0 42 end
Chris@0 43
Chris@0 44 def test_show_text_file
Chris@0 45 get :show, :id => 4
Chris@0 46 assert_response :success
Chris@0 47 assert_template 'file'
Chris@0 48 assert_equal 'text/html', @response.content_type
Chris@0 49 end
Chris@0 50
Chris@0 51 def test_show_text_file_should_send_if_too_big
Chris@0 52 Setting.file_max_size_displayed = 512
Chris@0 53 Attachment.find(4).update_attribute :filesize, 754.kilobyte
Chris@0 54
Chris@0 55 get :show, :id => 4
Chris@0 56 assert_response :success
Chris@0 57 assert_equal 'application/x-ruby', @response.content_type
Chris@0 58 end
Chris@0 59
Chris@0 60 def test_show_other
Chris@0 61 get :show, :id => 6
Chris@0 62 assert_response :success
Chris@0 63 assert_equal 'application/octet-stream', @response.content_type
Chris@0 64 end
Chris@0 65
Chris@0 66 def test_download_text_file
Chris@0 67 get :download, :id => 4
Chris@0 68 assert_response :success
Chris@0 69 assert_equal 'application/x-ruby', @response.content_type
Chris@0 70 end
Chris@0 71
Chris@0 72 def test_download_should_assign_content_type_if_blank
Chris@0 73 Attachment.find(4).update_attribute(:content_type, '')
Chris@0 74
Chris@0 75 get :download, :id => 4
Chris@0 76 assert_response :success
Chris@0 77 assert_equal 'text/x-ruby', @response.content_type
Chris@0 78 end
Chris@0 79
Chris@0 80 def test_download_missing_file
Chris@0 81 get :download, :id => 2
Chris@0 82 assert_response 404
Chris@0 83 end
Chris@0 84
Chris@0 85 def test_anonymous_on_private_private
Chris@0 86 get :download, :id => 7
Chris@0 87 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdownload%2F7'
Chris@0 88 end
Chris@0 89
Chris@0 90 def test_destroy_issue_attachment
Chris@0 91 issue = Issue.find(3)
Chris@0 92 @request.session[:user_id] = 2
Chris@0 93
Chris@0 94 assert_difference 'issue.attachments.count', -1 do
Chris@0 95 post :destroy, :id => 1
Chris@0 96 end
Chris@0 97 # no referrer
Chris@0 98 assert_redirected_to 'projects/ecookbook'
Chris@0 99 assert_nil Attachment.find_by_id(1)
Chris@0 100 j = issue.journals.find(:first, :order => 'created_on DESC')
Chris@0 101 assert_equal 'attachment', j.details.first.property
Chris@0 102 assert_equal '1', j.details.first.prop_key
Chris@0 103 assert_equal 'error281.txt', j.details.first.old_value
Chris@0 104 end
Chris@0 105
Chris@0 106 def test_destroy_wiki_page_attachment
Chris@0 107 @request.session[:user_id] = 2
Chris@0 108 assert_difference 'Attachment.count', -1 do
Chris@0 109 post :destroy, :id => 3
Chris@0 110 assert_response 302
Chris@0 111 end
Chris@0 112 end
Chris@0 113
Chris@0 114 def test_destroy_project_attachment
Chris@0 115 @request.session[:user_id] = 2
Chris@0 116 assert_difference 'Attachment.count', -1 do
Chris@0 117 post :destroy, :id => 8
Chris@0 118 assert_response 302
Chris@0 119 end
Chris@0 120 end
Chris@0 121
Chris@0 122 def test_destroy_version_attachment
Chris@0 123 @request.session[:user_id] = 2
Chris@0 124 assert_difference 'Attachment.count', -1 do
Chris@0 125 post :destroy, :id => 9
Chris@0 126 assert_response 302
Chris@0 127 end
Chris@0 128 end
Chris@0 129
Chris@0 130 def test_destroy_without_permission
Chris@0 131 post :destroy, :id => 3
Chris@0 132 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdestroy%2F3'
Chris@0 133 assert Attachment.find_by_id(3)
Chris@0 134 end
Chris@0 135 end