annotate test/functional/attachments_controller_test.rb @ 1452:d6b9fd02bb89 feature_36_js_refactoring

Deprecated develoment branch.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Fri, 11 Oct 2013 17:01:24 +0100
parents 753f1380d6bc
children 5e80956cc792
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@441 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@441 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@441 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@441 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@441 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@441 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@441 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@441 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@441 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@441 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@441 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@441 88
Chris@441 89 def test_show_file_from_private_issue_without_permission
Chris@441 90 get :show, :id => 15
Chris@441 91 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2F15'
Chris@441 92 end
Chris@441 93
Chris@441 94 def test_show_file_from_private_issue_with_permission
Chris@441 95 @request.session[:user_id] = 2
Chris@441 96 get :show, :id => 15
Chris@441 97 assert_response :success
Chris@441 98 assert_tag 'h2', :content => /private.diff/
Chris@441 99 end
Chris@441 100
Chris@0 101 def test_download_text_file
Chris@0 102 get :download, :id => 4
Chris@0 103 assert_response :success
Chris@0 104 assert_equal 'application/x-ruby', @response.content_type
Chris@0 105 end
Chris@441 106
Chris@0 107 def test_download_should_assign_content_type_if_blank
Chris@0 108 Attachment.find(4).update_attribute(:content_type, '')
Chris@441 109
Chris@0 110 get :download, :id => 4
Chris@0 111 assert_response :success
Chris@0 112 assert_equal 'text/x-ruby', @response.content_type
Chris@0 113 end
Chris@441 114
Chris@0 115 def test_download_missing_file
Chris@0 116 get :download, :id => 2
Chris@0 117 assert_response 404
Chris@0 118 end
Chris@441 119
Chris@0 120 def test_anonymous_on_private_private
Chris@0 121 get :download, :id => 7
Chris@0 122 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdownload%2F7'
Chris@0 123 end
Chris@441 124
Chris@0 125 def test_destroy_issue_attachment
Chris@0 126 issue = Issue.find(3)
Chris@0 127 @request.session[:user_id] = 2
Chris@441 128
Chris@0 129 assert_difference 'issue.attachments.count', -1 do
Chris@0 130 post :destroy, :id => 1
Chris@0 131 end
Chris@0 132 # no referrer
chris@37 133 assert_redirected_to '/projects/ecookbook'
Chris@0 134 assert_nil Attachment.find_by_id(1)
Chris@0 135 j = issue.journals.find(:first, :order => 'created_on DESC')
Chris@0 136 assert_equal 'attachment', j.details.first.property
Chris@0 137 assert_equal '1', j.details.first.prop_key
Chris@0 138 assert_equal 'error281.txt', j.details.first.old_value
Chris@0 139 end
Chris@441 140
Chris@0 141 def test_destroy_wiki_page_attachment
Chris@0 142 @request.session[:user_id] = 2
Chris@0 143 assert_difference 'Attachment.count', -1 do
Chris@0 144 post :destroy, :id => 3
Chris@0 145 assert_response 302
Chris@0 146 end
Chris@0 147 end
Chris@441 148
Chris@0 149 def test_destroy_project_attachment
Chris@0 150 @request.session[:user_id] = 2
Chris@0 151 assert_difference 'Attachment.count', -1 do
Chris@0 152 post :destroy, :id => 8
Chris@0 153 assert_response 302
Chris@0 154 end
Chris@0 155 end
Chris@441 156
Chris@0 157 def test_destroy_version_attachment
Chris@0 158 @request.session[:user_id] = 2
Chris@0 159 assert_difference 'Attachment.count', -1 do
Chris@0 160 post :destroy, :id => 9
Chris@0 161 assert_response 302
Chris@0 162 end
Chris@0 163 end
Chris@441 164
Chris@0 165 def test_destroy_without_permission
Chris@0 166 post :destroy, :id => 3
Chris@0 167 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdestroy%2F3'
Chris@0 168 assert Attachment.find_by_id(3)
Chris@0 169 end
Chris@0 170 end