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