##// END OF EJS Templates
add functional attachment test of mercurial export file (#11868)...
Toshi MARUYAMA -
r10246:551c024b454d
parent child
Show More
@@ -0,0 +1,13
1 # HG changeset patch
2 # User test
3 # Date 1348014182 -32400
4 # Node ID d1c871b8ef113df7f1c56d41e6e3bfbaff976e1f
5 # Parent 180b6605936cdc7909c5f08b59746ec1a7c99b3e
6 modify test1.txt
7
8 diff -r 180b6605936c -r d1c871b8ef11 test1.txt
9 --- a/test1.txt
10 +++ b/test1.txt
11 @@ -1,1 +1,1 @@
12 -test1
13 +modify test1
@@ -1,363 +1,378
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-2012 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.
10 #
10 #
11 # This program is distributed in the hope that it will be useful,
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
14 # GNU General Public License for more details.
15 #
15 #
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'
21 require 'attachments_controller'
22
22
23 # Re-raise errors caught by the controller.
23 # Re-raise errors caught by the controller.
24 class AttachmentsController; def rescue_action(e) raise e end; end
24 class AttachmentsController; def rescue_action(e) raise e end; end
25
25
26 class AttachmentsControllerTest < ActionController::TestCase
26 class AttachmentsControllerTest < ActionController::TestCase
27 fixtures :users, :projects, :roles, :members, :member_roles,
27 fixtures :users, :projects, :roles, :members, :member_roles,
28 :enabled_modules, :issues, :trackers, :attachments,
28 :enabled_modules, :issues, :trackers, :attachments,
29 :versions, :wiki_pages, :wikis, :documents
29 :versions, :wiki_pages, :wikis, :documents
30
30
31 def setup
31 def setup
32 @controller = AttachmentsController.new
32 @controller = AttachmentsController.new
33 @request = ActionController::TestRequest.new
33 @request = ActionController::TestRequest.new
34 @response = ActionController::TestResponse.new
34 @response = ActionController::TestResponse.new
35 User.current = nil
35 User.current = nil
36 set_fixtures_attachments_directory
36 set_fixtures_attachments_directory
37 end
37 end
38
38
39 def teardown
39 def teardown
40 set_tmp_attachments_directory
40 set_tmp_attachments_directory
41 end
41 end
42
42
43 def test_show_diff
43 def test_show_diff
44 ['inline', 'sbs'].each do |dt|
44 ['inline', 'sbs'].each do |dt|
45 # 060719210727_changeset_utf8.diff
45 # 060719210727_changeset_utf8.diff
46 get :show, :id => 14, :type => dt
46 get :show, :id => 14, :type => dt
47 assert_response :success
47 assert_response :success
48 assert_template 'diff'
48 assert_template 'diff'
49 assert_equal 'text/html', @response.content_type
49 assert_equal 'text/html', @response.content_type
50 assert_tag 'th',
50 assert_tag 'th',
51 :attributes => {:class => /filename/},
51 :attributes => {:class => /filename/},
52 :content => /issues_controller.rb\t\(rΓ©vision 1484\)/
52 :content => /issues_controller.rb\t\(rΓ©vision 1484\)/
53 assert_tag 'td',
53 assert_tag 'td',
54 :attributes => {:class => /line-code/},
54 :attributes => {:class => /line-code/},
55 :content => /Demande créée avec succès/
55 :content => /Demande créée avec succès/
56 end
56 end
57 set_tmp_attachments_directory
57 set_tmp_attachments_directory
58 end
58 end
59
59
60 def test_show_diff_replcace_cannot_convert_content
60 def test_show_diff_replcace_cannot_convert_content
61 with_settings :repositories_encodings => 'UTF-8' do
61 with_settings :repositories_encodings => 'UTF-8' do
62 ['inline', 'sbs'].each do |dt|
62 ['inline', 'sbs'].each do |dt|
63 # 060719210727_changeset_iso8859-1.diff
63 # 060719210727_changeset_iso8859-1.diff
64 get :show, :id => 5, :type => dt
64 get :show, :id => 5, :type => dt
65 assert_response :success
65 assert_response :success
66 assert_template 'diff'
66 assert_template 'diff'
67 assert_equal 'text/html', @response.content_type
67 assert_equal 'text/html', @response.content_type
68 assert_tag 'th',
68 assert_tag 'th',
69 :attributes => {:class => "filename"},
69 :attributes => {:class => "filename"},
70 :content => /issues_controller.rb\t\(r\?vision 1484\)/
70 :content => /issues_controller.rb\t\(r\?vision 1484\)/
71 assert_tag 'td',
71 assert_tag 'td',
72 :attributes => {:class => /line-code/},
72 :attributes => {:class => /line-code/},
73 :content => /Demande cr\?\?e avec succ\?s/
73 :content => /Demande cr\?\?e avec succ\?s/
74 end
74 end
75 end
75 end
76 set_tmp_attachments_directory
76 set_tmp_attachments_directory
77 end
77 end
78
78
79 def test_show_diff_latin_1
79 def test_show_diff_latin_1
80 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
80 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
81 ['inline', 'sbs'].each do |dt|
81 ['inline', 'sbs'].each do |dt|
82 # 060719210727_changeset_iso8859-1.diff
82 # 060719210727_changeset_iso8859-1.diff
83 get :show, :id => 5, :type => dt
83 get :show, :id => 5, :type => dt
84 assert_response :success
84 assert_response :success
85 assert_template 'diff'
85 assert_template 'diff'
86 assert_equal 'text/html', @response.content_type
86 assert_equal 'text/html', @response.content_type
87 assert_tag 'th',
87 assert_tag 'th',
88 :attributes => {:class => "filename"},
88 :attributes => {:class => "filename"},
89 :content => /issues_controller.rb\t\(rΓ©vision 1484\)/
89 :content => /issues_controller.rb\t\(rΓ©vision 1484\)/
90 assert_tag 'td',
90 assert_tag 'td',
91 :attributes => {:class => /line-code/},
91 :attributes => {:class => /line-code/},
92 :content => /Demande créée avec succès/
92 :content => /Demande créée avec succès/
93 end
93 end
94 end
94 end
95 set_tmp_attachments_directory
95 set_tmp_attachments_directory
96 end
96 end
97
97
98 def test_save_diff_type
98 def test_save_diff_type
99 @request.session[:user_id] = 1 # admin
99 @request.session[:user_id] = 1 # admin
100 user = User.find(1)
100 user = User.find(1)
101 get :show, :id => 5
101 get :show, :id => 5
102 assert_response :success
102 assert_response :success
103 assert_template 'diff'
103 assert_template 'diff'
104 user.reload
104 user.reload
105 assert_equal "inline", user.pref[:diff_type]
105 assert_equal "inline", user.pref[:diff_type]
106 get :show, :id => 5, :type => 'sbs'
106 get :show, :id => 5, :type => 'sbs'
107 assert_response :success
107 assert_response :success
108 assert_template 'diff'
108 assert_template 'diff'
109 user.reload
109 user.reload
110 assert_equal "sbs", user.pref[:diff_type]
110 assert_equal "sbs", user.pref[:diff_type]
111 end
111 end
112
112
113 def test_diff_show_filename_in_mercurial_export
114 set_tmp_attachments_directory
115 a = Attachment.new(:container => Issue.find(1),
116 :file => uploaded_test_file("hg-export.diff", "text/plain"),
117 :author => User.find(1))
118 assert a.save
119 assert_equal 'hg-export.diff', a.filename
120
121 get :show, :id => a.id, :type => 'inline'
122 assert_response :success
123 assert_template 'diff'
124 assert_equal 'text/html', @response.content_type
125 assert_select 'th.filename', :text => 'test1.txt'
126 end
127
113 def test_show_text_file
128 def test_show_text_file
114 get :show, :id => 4
129 get :show, :id => 4
115 assert_response :success
130 assert_response :success
116 assert_template 'file'
131 assert_template 'file'
117 assert_equal 'text/html', @response.content_type
132 assert_equal 'text/html', @response.content_type
118 set_tmp_attachments_directory
133 set_tmp_attachments_directory
119 end
134 end
120
135
121 def test_show_text_file_utf_8
136 def test_show_text_file_utf_8
122 set_tmp_attachments_directory
137 set_tmp_attachments_directory
123 a = Attachment.new(:container => Issue.find(1),
138 a = Attachment.new(:container => Issue.find(1),
124 :file => uploaded_test_file("japanese-utf-8.txt", "text/plain"),
139 :file => uploaded_test_file("japanese-utf-8.txt", "text/plain"),
125 :author => User.find(1))
140 :author => User.find(1))
126 assert a.save
141 assert a.save
127 assert_equal 'japanese-utf-8.txt', a.filename
142 assert_equal 'japanese-utf-8.txt', a.filename
128
143
129 str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e"
144 str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e"
130 str_japanese.force_encoding('UTF-8') if str_japanese.respond_to?(:force_encoding)
145 str_japanese.force_encoding('UTF-8') if str_japanese.respond_to?(:force_encoding)
131
146
132 get :show, :id => a.id
147 get :show, :id => a.id
133 assert_response :success
148 assert_response :success
134 assert_template 'file'
149 assert_template 'file'
135 assert_equal 'text/html', @response.content_type
150 assert_equal 'text/html', @response.content_type
136 assert_tag :tag => 'th',
151 assert_tag :tag => 'th',
137 :content => '1',
152 :content => '1',
138 :attributes => { :class => 'line-num' },
153 :attributes => { :class => 'line-num' },
139 :sibling => { :tag => 'td', :content => /#{str_japanese}/ }
154 :sibling => { :tag => 'td', :content => /#{str_japanese}/ }
140 end
155 end
141
156
142 def test_show_text_file_replcace_cannot_convert_content
157 def test_show_text_file_replcace_cannot_convert_content
143 set_tmp_attachments_directory
158 set_tmp_attachments_directory
144 with_settings :repositories_encodings => 'UTF-8' do
159 with_settings :repositories_encodings => 'UTF-8' do
145 a = Attachment.new(:container => Issue.find(1),
160 a = Attachment.new(:container => Issue.find(1),
146 :file => uploaded_test_file("iso8859-1.txt", "text/plain"),
161 :file => uploaded_test_file("iso8859-1.txt", "text/plain"),
147 :author => User.find(1))
162 :author => User.find(1))
148 assert a.save
163 assert a.save
149 assert_equal 'iso8859-1.txt', a.filename
164 assert_equal 'iso8859-1.txt', a.filename
150
165
151 get :show, :id => a.id
166 get :show, :id => a.id
152 assert_response :success
167 assert_response :success
153 assert_template 'file'
168 assert_template 'file'
154 assert_equal 'text/html', @response.content_type
169 assert_equal 'text/html', @response.content_type
155 assert_tag :tag => 'th',
170 assert_tag :tag => 'th',
156 :content => '7',
171 :content => '7',
157 :attributes => { :class => 'line-num' },
172 :attributes => { :class => 'line-num' },
158 :sibling => { :tag => 'td', :content => /Demande cr\?\?e avec succ\?s/ }
173 :sibling => { :tag => 'td', :content => /Demande cr\?\?e avec succ\?s/ }
159 end
174 end
160 end
175 end
161
176
162 def test_show_text_file_latin_1
177 def test_show_text_file_latin_1
163 set_tmp_attachments_directory
178 set_tmp_attachments_directory
164 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
179 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
165 a = Attachment.new(:container => Issue.find(1),
180 a = Attachment.new(:container => Issue.find(1),
166 :file => uploaded_test_file("iso8859-1.txt", "text/plain"),
181 :file => uploaded_test_file("iso8859-1.txt", "text/plain"),
167 :author => User.find(1))
182 :author => User.find(1))
168 assert a.save
183 assert a.save
169 assert_equal 'iso8859-1.txt', a.filename
184 assert_equal 'iso8859-1.txt', a.filename
170
185
171 get :show, :id => a.id
186 get :show, :id => a.id
172 assert_response :success
187 assert_response :success
173 assert_template 'file'
188 assert_template 'file'
174 assert_equal 'text/html', @response.content_type
189 assert_equal 'text/html', @response.content_type
175 assert_tag :tag => 'th',
190 assert_tag :tag => 'th',
176 :content => '7',
191 :content => '7',
177 :attributes => { :class => 'line-num' },
192 :attributes => { :class => 'line-num' },
178 :sibling => { :tag => 'td', :content => /Demande créée avec succès/ }
193 :sibling => { :tag => 'td', :content => /Demande créée avec succès/ }
179 end
194 end
180 end
195 end
181
196
182 def test_show_text_file_should_send_if_too_big
197 def test_show_text_file_should_send_if_too_big
183 Setting.file_max_size_displayed = 512
198 Setting.file_max_size_displayed = 512
184 Attachment.find(4).update_attribute :filesize, 754.kilobyte
199 Attachment.find(4).update_attribute :filesize, 754.kilobyte
185
200
186 get :show, :id => 4
201 get :show, :id => 4
187 assert_response :success
202 assert_response :success
188 assert_equal 'application/x-ruby', @response.content_type
203 assert_equal 'application/x-ruby', @response.content_type
189 set_tmp_attachments_directory
204 set_tmp_attachments_directory
190 end
205 end
191
206
192 def test_show_other
207 def test_show_other
193 get :show, :id => 6
208 get :show, :id => 6
194 assert_response :success
209 assert_response :success
195 assert_equal 'application/octet-stream', @response.content_type
210 assert_equal 'application/octet-stream', @response.content_type
196 set_tmp_attachments_directory
211 set_tmp_attachments_directory
197 end
212 end
198
213
199 def test_show_file_from_private_issue_without_permission
214 def test_show_file_from_private_issue_without_permission
200 get :show, :id => 15
215 get :show, :id => 15
201 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2F15'
216 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2F15'
202 set_tmp_attachments_directory
217 set_tmp_attachments_directory
203 end
218 end
204
219
205 def test_show_file_from_private_issue_with_permission
220 def test_show_file_from_private_issue_with_permission
206 @request.session[:user_id] = 2
221 @request.session[:user_id] = 2
207 get :show, :id => 15
222 get :show, :id => 15
208 assert_response :success
223 assert_response :success
209 assert_tag 'h2', :content => /private.diff/
224 assert_tag 'h2', :content => /private.diff/
210 set_tmp_attachments_directory
225 set_tmp_attachments_directory
211 end
226 end
212
227
213 def test_show_file_without_container_should_be_denied
228 def test_show_file_without_container_should_be_denied
214 set_tmp_attachments_directory
229 set_tmp_attachments_directory
215 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
230 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
216
231
217 @request.session[:user_id] = 2
232 @request.session[:user_id] = 2
218 get :show, :id => attachment.id
233 get :show, :id => attachment.id
219 assert_response 403
234 assert_response 403
220 end
235 end
221
236
222 def test_show_invalid_should_respond_with_404
237 def test_show_invalid_should_respond_with_404
223 get :show, :id => 999
238 get :show, :id => 999
224 assert_response 404
239 assert_response 404
225 end
240 end
226
241
227 def test_download_text_file
242 def test_download_text_file
228 get :download, :id => 4
243 get :download, :id => 4
229 assert_response :success
244 assert_response :success
230 assert_equal 'application/x-ruby', @response.content_type
245 assert_equal 'application/x-ruby', @response.content_type
231 set_tmp_attachments_directory
246 set_tmp_attachments_directory
232 end
247 end
233
248
234 def test_download_version_file_with_issue_tracking_disabled
249 def test_download_version_file_with_issue_tracking_disabled
235 Project.find(1).disable_module! :issue_tracking
250 Project.find(1).disable_module! :issue_tracking
236 get :download, :id => 9
251 get :download, :id => 9
237 assert_response :success
252 assert_response :success
238 end
253 end
239
254
240 def test_download_should_assign_content_type_if_blank
255 def test_download_should_assign_content_type_if_blank
241 Attachment.find(4).update_attribute(:content_type, '')
256 Attachment.find(4).update_attribute(:content_type, '')
242
257
243 get :download, :id => 4
258 get :download, :id => 4
244 assert_response :success
259 assert_response :success
245 assert_equal 'text/x-ruby', @response.content_type
260 assert_equal 'text/x-ruby', @response.content_type
246 set_tmp_attachments_directory
261 set_tmp_attachments_directory
247 end
262 end
248
263
249 def test_download_missing_file
264 def test_download_missing_file
250 get :download, :id => 2
265 get :download, :id => 2
251 assert_response 404
266 assert_response 404
252 set_tmp_attachments_directory
267 set_tmp_attachments_directory
253 end
268 end
254
269
255 def test_download_should_be_denied_without_permission
270 def test_download_should_be_denied_without_permission
256 get :download, :id => 7
271 get :download, :id => 7
257 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdownload%2F7'
272 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdownload%2F7'
258 set_tmp_attachments_directory
273 set_tmp_attachments_directory
259 end
274 end
260
275
261 if convert_installed?
276 if convert_installed?
262 def test_thumbnail
277 def test_thumbnail
263 Attachment.clear_thumbnails
278 Attachment.clear_thumbnails
264 @request.session[:user_id] = 2
279 @request.session[:user_id] = 2
265
280
266 get :thumbnail, :id => 16
281 get :thumbnail, :id => 16
267 assert_response :success
282 assert_response :success
268 assert_equal 'image/png', response.content_type
283 assert_equal 'image/png', response.content_type
269 end
284 end
270
285
271 def test_thumbnail_should_not_exceed_maximum_size
286 def test_thumbnail_should_not_exceed_maximum_size
272 Redmine::Thumbnail.expects(:generate).with {|source, target, size| size == 800}
287 Redmine::Thumbnail.expects(:generate).with {|source, target, size| size == 800}
273
288
274 @request.session[:user_id] = 2
289 @request.session[:user_id] = 2
275 get :thumbnail, :id => 16, :size => 2000
290 get :thumbnail, :id => 16, :size => 2000
276 end
291 end
277
292
278 def test_thumbnail_should_round_size
293 def test_thumbnail_should_round_size
279 Redmine::Thumbnail.expects(:generate).with {|source, target, size| size == 250}
294 Redmine::Thumbnail.expects(:generate).with {|source, target, size| size == 250}
280
295
281 @request.session[:user_id] = 2
296 @request.session[:user_id] = 2
282 get :thumbnail, :id => 16, :size => 260
297 get :thumbnail, :id => 16, :size => 260
283 end
298 end
284
299
285 def test_thumbnail_should_return_404_for_non_image_attachment
300 def test_thumbnail_should_return_404_for_non_image_attachment
286 @request.session[:user_id] = 2
301 @request.session[:user_id] = 2
287
302
288 get :thumbnail, :id => 15
303 get :thumbnail, :id => 15
289 assert_response 404
304 assert_response 404
290 end
305 end
291
306
292 def test_thumbnail_should_return_404_if_thumbnail_generation_failed
307 def test_thumbnail_should_return_404_if_thumbnail_generation_failed
293 Attachment.any_instance.stubs(:thumbnail).returns(nil)
308 Attachment.any_instance.stubs(:thumbnail).returns(nil)
294 @request.session[:user_id] = 2
309 @request.session[:user_id] = 2
295
310
296 get :thumbnail, :id => 16
311 get :thumbnail, :id => 16
297 assert_response 404
312 assert_response 404
298 end
313 end
299
314
300 def test_thumbnail_should_be_denied_without_permission
315 def test_thumbnail_should_be_denied_without_permission
301 get :thumbnail, :id => 16
316 get :thumbnail, :id => 16
302 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fthumbnail%2F16'
317 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fthumbnail%2F16'
303 end
318 end
304 else
319 else
305 puts '(ImageMagick convert not available)'
320 puts '(ImageMagick convert not available)'
306 end
321 end
307
322
308 def test_destroy_issue_attachment
323 def test_destroy_issue_attachment
309 set_tmp_attachments_directory
324 set_tmp_attachments_directory
310 issue = Issue.find(3)
325 issue = Issue.find(3)
311 @request.session[:user_id] = 2
326 @request.session[:user_id] = 2
312
327
313 assert_difference 'issue.attachments.count', -1 do
328 assert_difference 'issue.attachments.count', -1 do
314 assert_difference 'Journal.count' do
329 assert_difference 'Journal.count' do
315 delete :destroy, :id => 1
330 delete :destroy, :id => 1
316 assert_redirected_to '/projects/ecookbook'
331 assert_redirected_to '/projects/ecookbook'
317 end
332 end
318 end
333 end
319 assert_nil Attachment.find_by_id(1)
334 assert_nil Attachment.find_by_id(1)
320 j = Journal.first(:order => 'id DESC')
335 j = Journal.first(:order => 'id DESC')
321 assert_equal issue, j.journalized
336 assert_equal issue, j.journalized
322 assert_equal 'attachment', j.details.first.property
337 assert_equal 'attachment', j.details.first.property
323 assert_equal '1', j.details.first.prop_key
338 assert_equal '1', j.details.first.prop_key
324 assert_equal 'error281.txt', j.details.first.old_value
339 assert_equal 'error281.txt', j.details.first.old_value
325 assert_equal User.find(2), j.user
340 assert_equal User.find(2), j.user
326 end
341 end
327
342
328 def test_destroy_wiki_page_attachment
343 def test_destroy_wiki_page_attachment
329 set_tmp_attachments_directory
344 set_tmp_attachments_directory
330 @request.session[:user_id] = 2
345 @request.session[:user_id] = 2
331 assert_difference 'Attachment.count', -1 do
346 assert_difference 'Attachment.count', -1 do
332 delete :destroy, :id => 3
347 delete :destroy, :id => 3
333 assert_response 302
348 assert_response 302
334 end
349 end
335 end
350 end
336
351
337 def test_destroy_project_attachment
352 def test_destroy_project_attachment
338 set_tmp_attachments_directory
353 set_tmp_attachments_directory
339 @request.session[:user_id] = 2
354 @request.session[:user_id] = 2
340 assert_difference 'Attachment.count', -1 do
355 assert_difference 'Attachment.count', -1 do
341 delete :destroy, :id => 8
356 delete :destroy, :id => 8
342 assert_response 302
357 assert_response 302
343 end
358 end
344 end
359 end
345
360
346 def test_destroy_version_attachment
361 def test_destroy_version_attachment
347 set_tmp_attachments_directory
362 set_tmp_attachments_directory
348 @request.session[:user_id] = 2
363 @request.session[:user_id] = 2
349 assert_difference 'Attachment.count', -1 do
364 assert_difference 'Attachment.count', -1 do
350 delete :destroy, :id => 9
365 delete :destroy, :id => 9
351 assert_response 302
366 assert_response 302
352 end
367 end
353 end
368 end
354
369
355 def test_destroy_without_permission
370 def test_destroy_without_permission
356 set_tmp_attachments_directory
371 set_tmp_attachments_directory
357 assert_no_difference 'Attachment.count' do
372 assert_no_difference 'Attachment.count' do
358 delete :destroy, :id => 3
373 delete :destroy, :id => 3
359 end
374 end
360 assert_response 302
375 assert_response 302
361 assert Attachment.find_by_id(3)
376 assert Attachment.find_by_id(3)
362 end
377 end
363 end
378 end
General Comments 0
You need to be logged in to leave comments. Login now