comparison test/functional/attachments_controller_test.rb @ 1295:622f24f53b42 redmine-2.3

Update to Redmine SVN revision 11972 on 2.3-stable branch
author Chris Cannam
date Fri, 14 Jun 2013 09:02:21 +0100
parents 433d4f72a19b
children 4f746d8966dd e248c7af89ec
comparison
equal deleted inserted replaced
1294:3e4c3460b6ca 1295:622f24f53b42
1 # encoding: utf-8 1 # encoding: utf-8
2 # 2 #
3 # Redmine - project management software 3 # Redmine - project management software
4 # Copyright (C) 2006-2012 Jean-Philippe Lang 4 # Copyright (C) 2006-2013 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.
16 # You should have received a copy of the GNU General Public License 16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software 17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 19
20 require File.expand_path('../../test_helper', __FILE__) 20 require File.expand_path('../../test_helper', __FILE__)
21 require 'attachments_controller'
22
23 # Re-raise errors caught by the controller.
24 class AttachmentsController; def rescue_action(e) raise e end; end
25 21
26 class AttachmentsControllerTest < ActionController::TestCase 22 class AttachmentsControllerTest < ActionController::TestCase
27 fixtures :users, :projects, :roles, :members, :member_roles, 23 fixtures :users, :projects, :roles, :members, :member_roles,
28 :enabled_modules, :issues, :trackers, :attachments, 24 :enabled_modules, :issues, :trackers, :attachments,
29 :versions, :wiki_pages, :wikis, :documents 25 :versions, :wiki_pages, :wikis, :documents
30 26
31 def setup 27 def setup
32 @controller = AttachmentsController.new
33 @request = ActionController::TestRequest.new
34 @response = ActionController::TestResponse.new
35 User.current = nil 28 User.current = nil
36 set_fixtures_attachments_directory 29 set_fixtures_attachments_directory
37 end 30 end
38 31
39 def teardown 32 def teardown
55 :content => /Demande créée avec succès/ 48 :content => /Demande créée avec succès/
56 end 49 end
57 set_tmp_attachments_directory 50 set_tmp_attachments_directory
58 end 51 end
59 52
60 def test_show_diff_replcace_cannot_convert_content 53 def test_show_diff_replace_cannot_convert_content
61 with_settings :repositories_encodings => 'UTF-8' do 54 with_settings :repositories_encodings => 'UTF-8' do
62 ['inline', 'sbs'].each do |dt| 55 ['inline', 'sbs'].each do |dt|
63 # 060719210727_changeset_iso8859-1.diff 56 # 060719210727_changeset_iso8859-1.diff
64 get :show, :id => 5, :type => dt 57 get :show, :id => 5, :type => dt
65 assert_response :success 58 assert_response :success
157 :content => '1', 150 :content => '1',
158 :attributes => { :class => 'line-num' }, 151 :attributes => { :class => 'line-num' },
159 :sibling => { :tag => 'td', :content => /#{str_japanese}/ } 152 :sibling => { :tag => 'td', :content => /#{str_japanese}/ }
160 end 153 end
161 154
162 def test_show_text_file_replcace_cannot_convert_content 155 def test_show_text_file_replace_cannot_convert_content
163 set_tmp_attachments_directory 156 set_tmp_attachments_directory
164 with_settings :repositories_encodings => 'UTF-8' do 157 with_settings :repositories_encodings => 'UTF-8' do
165 a = Attachment.new(:container => Issue.find(1), 158 a = Attachment.new(:container => Issue.find(1),
166 :file => uploaded_test_file("iso8859-1.txt", "text/plain"), 159 :file => uploaded_test_file("iso8859-1.txt", "text/plain"),
167 :author => User.find(1)) 160 :author => User.find(1))
228 assert_response :success 221 assert_response :success
229 assert_tag 'h2', :content => /private.diff/ 222 assert_tag 'h2', :content => /private.diff/
230 set_tmp_attachments_directory 223 set_tmp_attachments_directory
231 end 224 end
232 225
233 def test_show_file_without_container_should_be_denied 226 def test_show_file_without_container_should_be_allowed_to_author
234 set_tmp_attachments_directory 227 set_tmp_attachments_directory
235 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2) 228 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
236 229
237 @request.session[:user_id] = 2 230 @request.session[:user_id] = 2
231 get :show, :id => attachment.id
232 assert_response 200
233 end
234
235 def test_show_file_without_container_should_be_denied_to_other_users
236 set_tmp_attachments_directory
237 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
238
239 @request.session[:user_id] = 3
238 get :show, :id => attachment.id 240 get :show, :id => attachment.id
239 assert_response 403 241 assert_response 403
240 end 242 end
241 243
242 def test_show_invalid_should_respond_with_404 244 def test_show_invalid_should_respond_with_404