annotate test/functional/.svn/text-base/attachments_controller_test.rb.svn-base @ 119:8661b858af72

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