##// END OF EJS Templates
Prevent fixture files from being deleted....
Jean-Philippe Lang -
r7863:9ed5d1dd027c
parent child
Show More
@@ -1,274 +1,274
1 1 # encoding: utf-8
2 2 #
3 3 # Redmine - project management software
4 4 # Copyright (C) 2006-2011 Jean-Philippe Lang
5 5 #
6 6 # This program is free software; you can redistribute it and/or
7 7 # modify it under the terms of the GNU General Public License
8 8 # as published by the Free Software Foundation; either version 2
9 9 # of the License, or (at your option) any later version.
10 10 #
11 11 # This program is distributed in the hope that it will be useful,
12 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 14 # GNU General Public License for more details.
15 15 #
16 16 # You should have received a copy of the GNU General Public License
17 17 # along with this program; if not, write to the Free Software
18 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 19
20 20 require File.expand_path('../../test_helper', __FILE__)
21 21 require 'attachments_controller'
22 22
23 23 # Re-raise errors caught by the controller.
24 24 class AttachmentsController; def rescue_action(e) raise e end; end
25 25
26 26 class AttachmentsControllerTest < ActionController::TestCase
27 27 fixtures :users, :projects, :roles, :members, :member_roles,
28 28 :enabled_modules, :issues, :trackers, :attachments,
29 29 :versions, :wiki_pages, :wikis, :documents
30 30
31 31 def setup
32 32 @controller = AttachmentsController.new
33 33 @request = ActionController::TestRequest.new
34 34 @response = ActionController::TestResponse.new
35 35 Attachment.storage_path = "#{Rails.root}/test/fixtures/files"
36 36 User.current = nil
37 37 end
38 38
39 39 def test_show_diff
40 40 ['inline', 'sbs'].each do |dt|
41 41 # 060719210727_changeset_utf8.diff
42 42 get :show, :id => 14, :type => dt
43 43 assert_response :success
44 44 assert_template 'diff'
45 45 assert_equal 'text/html', @response.content_type
46 46 assert_tag 'th',
47 47 :attributes => {:class => /filename/},
48 48 :content => /issues_controller.rb\t\(rΓ©vision 1484\)/
49 49 assert_tag 'td',
50 50 :attributes => {:class => /line-code/},
51 51 :content => /Demande créée avec succès/
52 52 end
53 53 set_tmp_attachments_directory
54 54 end
55 55
56 56 def test_show_diff_replcace_cannot_convert_content
57 57 with_settings :repositories_encodings => 'UTF-8' do
58 58 ['inline', 'sbs'].each do |dt|
59 59 # 060719210727_changeset_iso8859-1.diff
60 60 get :show, :id => 5, :type => dt
61 61 assert_response :success
62 62 assert_template 'diff'
63 63 assert_equal 'text/html', @response.content_type
64 64 assert_tag 'th',
65 65 :attributes => {:class => "filename"},
66 66 :content => /issues_controller.rb\t\(r\?vision 1484\)/
67 67 assert_tag 'td',
68 68 :attributes => {:class => /line-code/},
69 69 :content => /Demande cr\?\?e avec succ\?s/
70 70 end
71 71 end
72 72 set_tmp_attachments_directory
73 73 end
74 74
75 75 def test_show_diff_latin_1
76 76 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
77 77 ['inline', 'sbs'].each do |dt|
78 78 # 060719210727_changeset_iso8859-1.diff
79 79 get :show, :id => 5, :type => dt
80 80 assert_response :success
81 81 assert_template 'diff'
82 82 assert_equal 'text/html', @response.content_type
83 83 assert_tag 'th',
84 84 :attributes => {:class => "filename"},
85 85 :content => /issues_controller.rb\t\(rΓ©vision 1484\)/
86 86 assert_tag 'td',
87 87 :attributes => {:class => /line-code/},
88 88 :content => /Demande créée avec succès/
89 89 end
90 90 end
91 91 set_tmp_attachments_directory
92 92 end
93 93
94 94 def test_show_text_file
95 95 get :show, :id => 4
96 96 assert_response :success
97 97 assert_template 'file'
98 98 assert_equal 'text/html', @response.content_type
99 99 set_tmp_attachments_directory
100 100 end
101 101
102 102 def test_show_text_file_utf_8
103 103 set_tmp_attachments_directory
104 104 a = Attachment.new(:container => Issue.find(1),
105 105 :file => uploaded_test_file("japanese-utf-8.txt", "text/plain"),
106 106 :author => User.find(1))
107 107 assert a.save
108 108 assert_equal 'japanese-utf-8.txt', a.filename
109 109
110 110 str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e"
111 111 str_japanese.force_encoding('UTF-8') if str_japanese.respond_to?(:force_encoding)
112 112
113 113 get :show, :id => a.id
114 114 assert_response :success
115 115 assert_template 'file'
116 116 assert_equal 'text/html', @response.content_type
117 117 assert_tag :tag => 'th',
118 118 :content => '1',
119 119 :attributes => { :class => 'line-num' },
120 120 :sibling => { :tag => 'td', :content => /#{str_japanese}/ }
121 121 end
122 122
123 123 def test_show_text_file_replcace_cannot_convert_content
124 124 set_tmp_attachments_directory
125 125 with_settings :repositories_encodings => 'UTF-8' do
126 126 a = Attachment.new(:container => Issue.find(1),
127 127 :file => uploaded_test_file("iso8859-1.txt", "text/plain"),
128 128 :author => User.find(1))
129 129 assert a.save
130 130 assert_equal 'iso8859-1.txt', a.filename
131 131
132 132 get :show, :id => a.id
133 133 assert_response :success
134 134 assert_template 'file'
135 135 assert_equal 'text/html', @response.content_type
136 136 assert_tag :tag => 'th',
137 137 :content => '7',
138 138 :attributes => { :class => 'line-num' },
139 139 :sibling => { :tag => 'td', :content => /Demande cr\?\?e avec succ\?s/ }
140 140 end
141 141 end
142 142
143 143 def test_show_text_file_latin_1
144 144 set_tmp_attachments_directory
145 145 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
146 146 a = Attachment.new(:container => Issue.find(1),
147 147 :file => uploaded_test_file("iso8859-1.txt", "text/plain"),
148 148 :author => User.find(1))
149 149 assert a.save
150 150 assert_equal 'iso8859-1.txt', a.filename
151 151
152 152 get :show, :id => a.id
153 153 assert_response :success
154 154 assert_template 'file'
155 155 assert_equal 'text/html', @response.content_type
156 156 assert_tag :tag => 'th',
157 157 :content => '7',
158 158 :attributes => { :class => 'line-num' },
159 159 :sibling => { :tag => 'td', :content => /Demande créée avec succès/ }
160 160 end
161 161 end
162 162
163 163 def test_show_text_file_should_send_if_too_big
164 164 Setting.file_max_size_displayed = 512
165 165 Attachment.find(4).update_attribute :filesize, 754.kilobyte
166 166
167 167 get :show, :id => 4
168 168 assert_response :success
169 169 assert_equal 'application/x-ruby', @response.content_type
170 170 set_tmp_attachments_directory
171 171 end
172 172
173 173 def test_show_other
174 174 get :show, :id => 6
175 175 assert_response :success
176 176 assert_equal 'application/octet-stream', @response.content_type
177 177 set_tmp_attachments_directory
178 178 end
179 179
180 180 def test_show_file_from_private_issue_without_permission
181 181 get :show, :id => 15
182 182 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2F15'
183 183 set_tmp_attachments_directory
184 184 end
185 185
186 186 def test_show_file_from_private_issue_with_permission
187 187 @request.session[:user_id] = 2
188 188 get :show, :id => 15
189 189 assert_response :success
190 190 assert_tag 'h2', :content => /private.diff/
191 191 set_tmp_attachments_directory
192 192 end
193 193
194 194 def test_download_text_file
195 195 get :download, :id => 4
196 196 assert_response :success
197 197 assert_equal 'application/x-ruby', @response.content_type
198 198 set_tmp_attachments_directory
199 199 end
200 200
201 201 def test_download_should_assign_content_type_if_blank
202 202 Attachment.find(4).update_attribute(:content_type, '')
203 203
204 204 get :download, :id => 4
205 205 assert_response :success
206 206 assert_equal 'text/x-ruby', @response.content_type
207 207 set_tmp_attachments_directory
208 208 end
209 209
210 210 def test_download_missing_file
211 211 get :download, :id => 2
212 212 assert_response 404
213 213 set_tmp_attachments_directory
214 214 end
215 215
216 216 def test_anonymous_on_private_private
217 217 get :download, :id => 7
218 218 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdownload%2F7'
219 219 set_tmp_attachments_directory
220 220 end
221 221
222 222 def test_destroy_issue_attachment
223 set_tmp_attachments_directory
223 224 issue = Issue.find(3)
224 225 @request.session[:user_id] = 2
225 226
226 227 assert_difference 'issue.attachments.count', -1 do
227 228 delete :destroy, :id => 1
228 229 end
229 230 # no referrer
230 231 assert_redirected_to '/projects/ecookbook'
231 232 assert_nil Attachment.find_by_id(1)
232 233 j = issue.journals.find(:first, :order => 'created_on DESC')
233 234 assert_equal 'attachment', j.details.first.property
234 235 assert_equal '1', j.details.first.prop_key
235 236 assert_equal 'error281.txt', j.details.first.old_value
236 set_tmp_attachments_directory
237 237 end
238 238
239 239 def test_destroy_wiki_page_attachment
240 set_tmp_attachments_directory
240 241 @request.session[:user_id] = 2
241 242 assert_difference 'Attachment.count', -1 do
242 243 delete :destroy, :id => 3
243 244 assert_response 302
244 245 end
245 set_tmp_attachments_directory
246 246 end
247 247
248 248 def test_destroy_project_attachment
249 set_tmp_attachments_directory
249 250 @request.session[:user_id] = 2
250 251 assert_difference 'Attachment.count', -1 do
251 252 delete :destroy, :id => 8
252 253 assert_response 302
253 254 end
254 set_tmp_attachments_directory
255 255 end
256 256
257 257 def test_destroy_version_attachment
258 set_tmp_attachments_directory
258 259 @request.session[:user_id] = 2
259 260 assert_difference 'Attachment.count', -1 do
260 261 delete :destroy, :id => 9
261 262 assert_response 302
262 263 end
263 set_tmp_attachments_directory
264 264 end
265 265
266 266 def test_destroy_without_permission
267 set_tmp_attachments_directory
267 268 assert_no_difference 'Attachment.count' do
268 269 delete :destroy, :id => 3
269 270 end
270 271 assert_response 302
271 272 assert Attachment.find_by_id(3)
272 set_tmp_attachments_directory
273 273 end
274 274 end
General Comments 0
You need to be logged in to leave comments. Login now