##// END OF EJS Templates
Merged r10501 from trunk...
Toshi MARUYAMA -
r10296:f27a0eca5b14
parent child
Show More
@@ -1,363 +1,368
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 user1 = User.find(1)
100 user1.pref[:diff_type] = nil
101 user1.preference.save
100 user = User.find(1)
102 user = User.find(1)
103 assert_nil user.pref[:diff_type]
104
105 @request.session[:user_id] = 1 # admin
101 get :show, :id => 5
106 get :show, :id => 5
102 assert_response :success
107 assert_response :success
103 assert_template 'diff'
108 assert_template 'diff'
104 user.reload
109 user.reload
105 assert_equal "inline", user.pref[:diff_type]
110 assert_equal "inline", user.pref[:diff_type]
106 get :show, :id => 5, :type => 'sbs'
111 get :show, :id => 5, :type => 'sbs'
107 assert_response :success
112 assert_response :success
108 assert_template 'diff'
113 assert_template 'diff'
109 user.reload
114 user.reload
110 assert_equal "sbs", user.pref[:diff_type]
115 assert_equal "sbs", user.pref[:diff_type]
111 end
116 end
112
117
113 def test_show_text_file
118 def test_show_text_file
114 get :show, :id => 4
119 get :show, :id => 4
115 assert_response :success
120 assert_response :success
116 assert_template 'file'
121 assert_template 'file'
117 assert_equal 'text/html', @response.content_type
122 assert_equal 'text/html', @response.content_type
118 set_tmp_attachments_directory
123 set_tmp_attachments_directory
119 end
124 end
120
125
121 def test_show_text_file_utf_8
126 def test_show_text_file_utf_8
122 set_tmp_attachments_directory
127 set_tmp_attachments_directory
123 a = Attachment.new(:container => Issue.find(1),
128 a = Attachment.new(:container => Issue.find(1),
124 :file => uploaded_test_file("japanese-utf-8.txt", "text/plain"),
129 :file => uploaded_test_file("japanese-utf-8.txt", "text/plain"),
125 :author => User.find(1))
130 :author => User.find(1))
126 assert a.save
131 assert a.save
127 assert_equal 'japanese-utf-8.txt', a.filename
132 assert_equal 'japanese-utf-8.txt', a.filename
128
133
129 str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e"
134 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)
135 str_japanese.force_encoding('UTF-8') if str_japanese.respond_to?(:force_encoding)
131
136
132 get :show, :id => a.id
137 get :show, :id => a.id
133 assert_response :success
138 assert_response :success
134 assert_template 'file'
139 assert_template 'file'
135 assert_equal 'text/html', @response.content_type
140 assert_equal 'text/html', @response.content_type
136 assert_tag :tag => 'th',
141 assert_tag :tag => 'th',
137 :content => '1',
142 :content => '1',
138 :attributes => { :class => 'line-num' },
143 :attributes => { :class => 'line-num' },
139 :sibling => { :tag => 'td', :content => /#{str_japanese}/ }
144 :sibling => { :tag => 'td', :content => /#{str_japanese}/ }
140 end
145 end
141
146
142 def test_show_text_file_replcace_cannot_convert_content
147 def test_show_text_file_replcace_cannot_convert_content
143 set_tmp_attachments_directory
148 set_tmp_attachments_directory
144 with_settings :repositories_encodings => 'UTF-8' do
149 with_settings :repositories_encodings => 'UTF-8' do
145 a = Attachment.new(:container => Issue.find(1),
150 a = Attachment.new(:container => Issue.find(1),
146 :file => uploaded_test_file("iso8859-1.txt", "text/plain"),
151 :file => uploaded_test_file("iso8859-1.txt", "text/plain"),
147 :author => User.find(1))
152 :author => User.find(1))
148 assert a.save
153 assert a.save
149 assert_equal 'iso8859-1.txt', a.filename
154 assert_equal 'iso8859-1.txt', a.filename
150
155
151 get :show, :id => a.id
156 get :show, :id => a.id
152 assert_response :success
157 assert_response :success
153 assert_template 'file'
158 assert_template 'file'
154 assert_equal 'text/html', @response.content_type
159 assert_equal 'text/html', @response.content_type
155 assert_tag :tag => 'th',
160 assert_tag :tag => 'th',
156 :content => '7',
161 :content => '7',
157 :attributes => { :class => 'line-num' },
162 :attributes => { :class => 'line-num' },
158 :sibling => { :tag => 'td', :content => /Demande cr\?\?e avec succ\?s/ }
163 :sibling => { :tag => 'td', :content => /Demande cr\?\?e avec succ\?s/ }
159 end
164 end
160 end
165 end
161
166
162 def test_show_text_file_latin_1
167 def test_show_text_file_latin_1
163 set_tmp_attachments_directory
168 set_tmp_attachments_directory
164 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
169 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
165 a = Attachment.new(:container => Issue.find(1),
170 a = Attachment.new(:container => Issue.find(1),
166 :file => uploaded_test_file("iso8859-1.txt", "text/plain"),
171 :file => uploaded_test_file("iso8859-1.txt", "text/plain"),
167 :author => User.find(1))
172 :author => User.find(1))
168 assert a.save
173 assert a.save
169 assert_equal 'iso8859-1.txt', a.filename
174 assert_equal 'iso8859-1.txt', a.filename
170
175
171 get :show, :id => a.id
176 get :show, :id => a.id
172 assert_response :success
177 assert_response :success
173 assert_template 'file'
178 assert_template 'file'
174 assert_equal 'text/html', @response.content_type
179 assert_equal 'text/html', @response.content_type
175 assert_tag :tag => 'th',
180 assert_tag :tag => 'th',
176 :content => '7',
181 :content => '7',
177 :attributes => { :class => 'line-num' },
182 :attributes => { :class => 'line-num' },
178 :sibling => { :tag => 'td', :content => /Demande créée avec succès/ }
183 :sibling => { :tag => 'td', :content => /Demande créée avec succès/ }
179 end
184 end
180 end
185 end
181
186
182 def test_show_text_file_should_send_if_too_big
187 def test_show_text_file_should_send_if_too_big
183 Setting.file_max_size_displayed = 512
188 Setting.file_max_size_displayed = 512
184 Attachment.find(4).update_attribute :filesize, 754.kilobyte
189 Attachment.find(4).update_attribute :filesize, 754.kilobyte
185
190
186 get :show, :id => 4
191 get :show, :id => 4
187 assert_response :success
192 assert_response :success
188 assert_equal 'application/x-ruby', @response.content_type
193 assert_equal 'application/x-ruby', @response.content_type
189 set_tmp_attachments_directory
194 set_tmp_attachments_directory
190 end
195 end
191
196
192 def test_show_other
197 def test_show_other
193 get :show, :id => 6
198 get :show, :id => 6
194 assert_response :success
199 assert_response :success
195 assert_equal 'application/octet-stream', @response.content_type
200 assert_equal 'application/octet-stream', @response.content_type
196 set_tmp_attachments_directory
201 set_tmp_attachments_directory
197 end
202 end
198
203
199 def test_show_file_from_private_issue_without_permission
204 def test_show_file_from_private_issue_without_permission
200 get :show, :id => 15
205 get :show, :id => 15
201 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2F15'
206 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2F15'
202 set_tmp_attachments_directory
207 set_tmp_attachments_directory
203 end
208 end
204
209
205 def test_show_file_from_private_issue_with_permission
210 def test_show_file_from_private_issue_with_permission
206 @request.session[:user_id] = 2
211 @request.session[:user_id] = 2
207 get :show, :id => 15
212 get :show, :id => 15
208 assert_response :success
213 assert_response :success
209 assert_tag 'h2', :content => /private.diff/
214 assert_tag 'h2', :content => /private.diff/
210 set_tmp_attachments_directory
215 set_tmp_attachments_directory
211 end
216 end
212
217
213 def test_show_file_without_container_should_be_denied
218 def test_show_file_without_container_should_be_denied
214 set_tmp_attachments_directory
219 set_tmp_attachments_directory
215 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
220 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
216
221
217 @request.session[:user_id] = 2
222 @request.session[:user_id] = 2
218 get :show, :id => attachment.id
223 get :show, :id => attachment.id
219 assert_response 403
224 assert_response 403
220 end
225 end
221
226
222 def test_show_invalid_should_respond_with_404
227 def test_show_invalid_should_respond_with_404
223 get :show, :id => 999
228 get :show, :id => 999
224 assert_response 404
229 assert_response 404
225 end
230 end
226
231
227 def test_download_text_file
232 def test_download_text_file
228 get :download, :id => 4
233 get :download, :id => 4
229 assert_response :success
234 assert_response :success
230 assert_equal 'application/x-ruby', @response.content_type
235 assert_equal 'application/x-ruby', @response.content_type
231 set_tmp_attachments_directory
236 set_tmp_attachments_directory
232 end
237 end
233
238
234 def test_download_version_file_with_issue_tracking_disabled
239 def test_download_version_file_with_issue_tracking_disabled
235 Project.find(1).disable_module! :issue_tracking
240 Project.find(1).disable_module! :issue_tracking
236 get :download, :id => 9
241 get :download, :id => 9
237 assert_response :success
242 assert_response :success
238 end
243 end
239
244
240 def test_download_should_assign_content_type_if_blank
245 def test_download_should_assign_content_type_if_blank
241 Attachment.find(4).update_attribute(:content_type, '')
246 Attachment.find(4).update_attribute(:content_type, '')
242
247
243 get :download, :id => 4
248 get :download, :id => 4
244 assert_response :success
249 assert_response :success
245 assert_equal 'text/x-ruby', @response.content_type
250 assert_equal 'text/x-ruby', @response.content_type
246 set_tmp_attachments_directory
251 set_tmp_attachments_directory
247 end
252 end
248
253
249 def test_download_missing_file
254 def test_download_missing_file
250 get :download, :id => 2
255 get :download, :id => 2
251 assert_response 404
256 assert_response 404
252 set_tmp_attachments_directory
257 set_tmp_attachments_directory
253 end
258 end
254
259
255 def test_download_should_be_denied_without_permission
260 def test_download_should_be_denied_without_permission
256 get :download, :id => 7
261 get :download, :id => 7
257 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdownload%2F7'
262 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdownload%2F7'
258 set_tmp_attachments_directory
263 set_tmp_attachments_directory
259 end
264 end
260
265
261 if convert_installed?
266 if convert_installed?
262 def test_thumbnail
267 def test_thumbnail
263 Attachment.clear_thumbnails
268 Attachment.clear_thumbnails
264 @request.session[:user_id] = 2
269 @request.session[:user_id] = 2
265
270
266 get :thumbnail, :id => 16
271 get :thumbnail, :id => 16
267 assert_response :success
272 assert_response :success
268 assert_equal 'image/png', response.content_type
273 assert_equal 'image/png', response.content_type
269 end
274 end
270
275
271 def test_thumbnail_should_not_exceed_maximum_size
276 def test_thumbnail_should_not_exceed_maximum_size
272 Redmine::Thumbnail.expects(:generate).with {|source, target, size| size == 800}
277 Redmine::Thumbnail.expects(:generate).with {|source, target, size| size == 800}
273
278
274 @request.session[:user_id] = 2
279 @request.session[:user_id] = 2
275 get :thumbnail, :id => 16, :size => 2000
280 get :thumbnail, :id => 16, :size => 2000
276 end
281 end
277
282
278 def test_thumbnail_should_round_size
283 def test_thumbnail_should_round_size
279 Redmine::Thumbnail.expects(:generate).with {|source, target, size| size == 250}
284 Redmine::Thumbnail.expects(:generate).with {|source, target, size| size == 250}
280
285
281 @request.session[:user_id] = 2
286 @request.session[:user_id] = 2
282 get :thumbnail, :id => 16, :size => 260
287 get :thumbnail, :id => 16, :size => 260
283 end
288 end
284
289
285 def test_thumbnail_should_return_404_for_non_image_attachment
290 def test_thumbnail_should_return_404_for_non_image_attachment
286 @request.session[:user_id] = 2
291 @request.session[:user_id] = 2
287
292
288 get :thumbnail, :id => 15
293 get :thumbnail, :id => 15
289 assert_response 404
294 assert_response 404
290 end
295 end
291
296
292 def test_thumbnail_should_return_404_if_thumbnail_generation_failed
297 def test_thumbnail_should_return_404_if_thumbnail_generation_failed
293 Attachment.any_instance.stubs(:thumbnail).returns(nil)
298 Attachment.any_instance.stubs(:thumbnail).returns(nil)
294 @request.session[:user_id] = 2
299 @request.session[:user_id] = 2
295
300
296 get :thumbnail, :id => 16
301 get :thumbnail, :id => 16
297 assert_response 404
302 assert_response 404
298 end
303 end
299
304
300 def test_thumbnail_should_be_denied_without_permission
305 def test_thumbnail_should_be_denied_without_permission
301 get :thumbnail, :id => 16
306 get :thumbnail, :id => 16
302 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fthumbnail%2F16'
307 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fthumbnail%2F16'
303 end
308 end
304 else
309 else
305 puts '(ImageMagick convert not available)'
310 puts '(ImageMagick convert not available)'
306 end
311 end
307
312
308 def test_destroy_issue_attachment
313 def test_destroy_issue_attachment
309 set_tmp_attachments_directory
314 set_tmp_attachments_directory
310 issue = Issue.find(3)
315 issue = Issue.find(3)
311 @request.session[:user_id] = 2
316 @request.session[:user_id] = 2
312
317
313 assert_difference 'issue.attachments.count', -1 do
318 assert_difference 'issue.attachments.count', -1 do
314 assert_difference 'Journal.count' do
319 assert_difference 'Journal.count' do
315 delete :destroy, :id => 1
320 delete :destroy, :id => 1
316 assert_redirected_to '/projects/ecookbook'
321 assert_redirected_to '/projects/ecookbook'
317 end
322 end
318 end
323 end
319 assert_nil Attachment.find_by_id(1)
324 assert_nil Attachment.find_by_id(1)
320 j = Journal.first(:order => 'id DESC')
325 j = Journal.first(:order => 'id DESC')
321 assert_equal issue, j.journalized
326 assert_equal issue, j.journalized
322 assert_equal 'attachment', j.details.first.property
327 assert_equal 'attachment', j.details.first.property
323 assert_equal '1', j.details.first.prop_key
328 assert_equal '1', j.details.first.prop_key
324 assert_equal 'error281.txt', j.details.first.old_value
329 assert_equal 'error281.txt', j.details.first.old_value
325 assert_equal User.find(2), j.user
330 assert_equal User.find(2), j.user
326 end
331 end
327
332
328 def test_destroy_wiki_page_attachment
333 def test_destroy_wiki_page_attachment
329 set_tmp_attachments_directory
334 set_tmp_attachments_directory
330 @request.session[:user_id] = 2
335 @request.session[:user_id] = 2
331 assert_difference 'Attachment.count', -1 do
336 assert_difference 'Attachment.count', -1 do
332 delete :destroy, :id => 3
337 delete :destroy, :id => 3
333 assert_response 302
338 assert_response 302
334 end
339 end
335 end
340 end
336
341
337 def test_destroy_project_attachment
342 def test_destroy_project_attachment
338 set_tmp_attachments_directory
343 set_tmp_attachments_directory
339 @request.session[:user_id] = 2
344 @request.session[:user_id] = 2
340 assert_difference 'Attachment.count', -1 do
345 assert_difference 'Attachment.count', -1 do
341 delete :destroy, :id => 8
346 delete :destroy, :id => 8
342 assert_response 302
347 assert_response 302
343 end
348 end
344 end
349 end
345
350
346 def test_destroy_version_attachment
351 def test_destroy_version_attachment
347 set_tmp_attachments_directory
352 set_tmp_attachments_directory
348 @request.session[:user_id] = 2
353 @request.session[:user_id] = 2
349 assert_difference 'Attachment.count', -1 do
354 assert_difference 'Attachment.count', -1 do
350 delete :destroy, :id => 9
355 delete :destroy, :id => 9
351 assert_response 302
356 assert_response 302
352 end
357 end
353 end
358 end
354
359
355 def test_destroy_without_permission
360 def test_destroy_without_permission
356 set_tmp_attachments_directory
361 set_tmp_attachments_directory
357 assert_no_difference 'Attachment.count' do
362 assert_no_difference 'Attachment.count' do
358 delete :destroy, :id => 3
363 delete :destroy, :id => 3
359 end
364 end
360 assert_response 302
365 assert_response 302
361 assert Attachment.find_by_id(3)
366 assert Attachment.find_by_id(3)
362 end
367 end
363 end
368 end
@@ -1,560 +1,565
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
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
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.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19
19
20 class RepositoriesGitControllerTest < ActionController::TestCase
20 class RepositoriesGitControllerTest < ActionController::TestCase
21 tests RepositoriesController
21 tests RepositoriesController
22
22
23 fixtures :projects, :users, :roles, :members, :member_roles,
23 fixtures :projects, :users, :roles, :members, :member_roles,
24 :repositories, :enabled_modules
24 :repositories, :enabled_modules
25
25
26 REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
26 REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
27 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
27 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
28 PRJ_ID = 3
28 PRJ_ID = 3
29 CHAR_1_HEX = "\xc3\x9c"
29 CHAR_1_HEX = "\xc3\x9c"
30 NUM_REV = 28
30 NUM_REV = 28
31
31
32 ## Git, Mercurial and CVS path encodings are binary.
32 ## Git, Mercurial and CVS path encodings are binary.
33 ## Subversion supports URL encoding for path.
33 ## Subversion supports URL encoding for path.
34 ## Redmine Mercurial adapter and extension use URL encoding.
34 ## Redmine Mercurial adapter and extension use URL encoding.
35 ## Git accepts only binary path in command line parameter.
35 ## Git accepts only binary path in command line parameter.
36 ## So, there is no way to use binary command line parameter in JRuby.
36 ## So, there is no way to use binary command line parameter in JRuby.
37 JRUBY_SKIP = (RUBY_PLATFORM == 'java')
37 JRUBY_SKIP = (RUBY_PLATFORM == 'java')
38 JRUBY_SKIP_STR = "TODO: This test fails in JRuby"
38 JRUBY_SKIP_STR = "TODO: This test fails in JRuby"
39
39
40 def setup
40 def setup
41 @ruby19_non_utf8_pass =
41 @ruby19_non_utf8_pass =
42 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
42 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
43
43
44 User.current = nil
44 User.current = nil
45 @project = Project.find(PRJ_ID)
45 @project = Project.find(PRJ_ID)
46 @repository = Repository::Git.create(
46 @repository = Repository::Git.create(
47 :project => @project,
47 :project => @project,
48 :url => REPOSITORY_PATH,
48 :url => REPOSITORY_PATH,
49 :path_encoding => 'ISO-8859-1'
49 :path_encoding => 'ISO-8859-1'
50 )
50 )
51 assert @repository
51 assert @repository
52 @char_1 = CHAR_1_HEX.dup
52 @char_1 = CHAR_1_HEX.dup
53 if @char_1.respond_to?(:force_encoding)
53 if @char_1.respond_to?(:force_encoding)
54 @char_1.force_encoding('UTF-8')
54 @char_1.force_encoding('UTF-8')
55 end
55 end
56 end
56 end
57
57
58 def test_create_and_update
58 def test_create_and_update
59 @request.session[:user_id] = 1
59 @request.session[:user_id] = 1
60 assert_difference 'Repository.count' do
60 assert_difference 'Repository.count' do
61 post :create, :project_id => 'subproject1',
61 post :create, :project_id => 'subproject1',
62 :repository_scm => 'Git',
62 :repository_scm => 'Git',
63 :repository => {
63 :repository => {
64 :url => '/test',
64 :url => '/test',
65 :is_default => '0',
65 :is_default => '0',
66 :identifier => 'test-create',
66 :identifier => 'test-create',
67 :extra_report_last_commit => '1',
67 :extra_report_last_commit => '1',
68 }
68 }
69 end
69 end
70 assert_response 302
70 assert_response 302
71 repository = Repository.first(:order => 'id DESC')
71 repository = Repository.first(:order => 'id DESC')
72 assert_kind_of Repository::Git, repository
72 assert_kind_of Repository::Git, repository
73 assert_equal '/test', repository.url
73 assert_equal '/test', repository.url
74 assert_equal true, repository.extra_report_last_commit
74 assert_equal true, repository.extra_report_last_commit
75
75
76 put :update, :id => repository.id,
76 put :update, :id => repository.id,
77 :repository => {
77 :repository => {
78 :extra_report_last_commit => '0'
78 :extra_report_last_commit => '0'
79 }
79 }
80 assert_response 302
80 assert_response 302
81 repo2 = Repository.find(repository.id)
81 repo2 = Repository.find(repository.id)
82 assert_equal false, repo2.extra_report_last_commit
82 assert_equal false, repo2.extra_report_last_commit
83 end
83 end
84
84
85 if File.directory?(REPOSITORY_PATH)
85 if File.directory?(REPOSITORY_PATH)
86 ## Ruby uses ANSI api to fork a process on Windows.
86 ## Ruby uses ANSI api to fork a process on Windows.
87 ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem
87 ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem
88 ## and these are incompatible with ASCII.
88 ## and these are incompatible with ASCII.
89 ## Git for Windows (msysGit) changed internal API from ANSI to Unicode in 1.7.10
89 ## Git for Windows (msysGit) changed internal API from ANSI to Unicode in 1.7.10
90 ## http://code.google.com/p/msysgit/issues/detail?id=80
90 ## http://code.google.com/p/msysgit/issues/detail?id=80
91 ## So, Latin-1 path tests fail on Japanese Windows
91 ## So, Latin-1 path tests fail on Japanese Windows
92 WINDOWS_PASS = (Redmine::Platform.mswin? &&
92 WINDOWS_PASS = (Redmine::Platform.mswin? &&
93 Redmine::Scm::Adapters::GitAdapter.client_version_above?([1, 7, 10]))
93 Redmine::Scm::Adapters::GitAdapter.client_version_above?([1, 7, 10]))
94 WINDOWS_SKIP_STR = "TODO: This test fails in Git for Windows above 1.7.10"
94 WINDOWS_SKIP_STR = "TODO: This test fails in Git for Windows above 1.7.10"
95
95
96 def test_get_new
96 def test_get_new
97 @request.session[:user_id] = 1
97 @request.session[:user_id] = 1
98 @project.repository.destroy
98 @project.repository.destroy
99 get :new, :project_id => 'subproject1', :repository_scm => 'Git'
99 get :new, :project_id => 'subproject1', :repository_scm => 'Git'
100 assert_response :success
100 assert_response :success
101 assert_template 'new'
101 assert_template 'new'
102 assert_kind_of Repository::Git, assigns(:repository)
102 assert_kind_of Repository::Git, assigns(:repository)
103 assert assigns(:repository).new_record?
103 assert assigns(:repository).new_record?
104 end
104 end
105
105
106 def test_browse_root
106 def test_browse_root
107 assert_equal 0, @repository.changesets.count
107 assert_equal 0, @repository.changesets.count
108 @repository.fetch_changesets
108 @repository.fetch_changesets
109 @project.reload
109 @project.reload
110 assert_equal NUM_REV, @repository.changesets.count
110 assert_equal NUM_REV, @repository.changesets.count
111
111
112 get :show, :id => PRJ_ID
112 get :show, :id => PRJ_ID
113 assert_response :success
113 assert_response :success
114 assert_template 'show'
114 assert_template 'show'
115 assert_not_nil assigns(:entries)
115 assert_not_nil assigns(:entries)
116 assert_equal 9, assigns(:entries).size
116 assert_equal 9, assigns(:entries).size
117 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
117 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
118 assert assigns(:entries).detect {|e| e.name == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir'}
118 assert assigns(:entries).detect {|e| e.name == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir'}
119 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
119 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
120 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
120 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
121 assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'}
121 assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'}
122 assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'}
122 assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'}
123 assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'}
123 assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'}
124 assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'}
124 assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'}
125 assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'}
125 assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'}
126 assert_not_nil assigns(:changesets)
126 assert_not_nil assigns(:changesets)
127 assert assigns(:changesets).size > 0
127 assert assigns(:changesets).size > 0
128 end
128 end
129
129
130 def test_browse_branch
130 def test_browse_branch
131 assert_equal 0, @repository.changesets.count
131 assert_equal 0, @repository.changesets.count
132 @repository.fetch_changesets
132 @repository.fetch_changesets
133 @project.reload
133 @project.reload
134 assert_equal NUM_REV, @repository.changesets.count
134 assert_equal NUM_REV, @repository.changesets.count
135 get :show, :id => PRJ_ID, :rev => 'test_branch'
135 get :show, :id => PRJ_ID, :rev => 'test_branch'
136 assert_response :success
136 assert_response :success
137 assert_template 'show'
137 assert_template 'show'
138 assert_not_nil assigns(:entries)
138 assert_not_nil assigns(:entries)
139 assert_equal 4, assigns(:entries).size
139 assert_equal 4, assigns(:entries).size
140 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
140 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
141 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
141 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
142 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
142 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
143 assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'}
143 assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'}
144 assert_not_nil assigns(:changesets)
144 assert_not_nil assigns(:changesets)
145 assert assigns(:changesets).size > 0
145 assert assigns(:changesets).size > 0
146 end
146 end
147
147
148 def test_browse_tag
148 def test_browse_tag
149 assert_equal 0, @repository.changesets.count
149 assert_equal 0, @repository.changesets.count
150 @repository.fetch_changesets
150 @repository.fetch_changesets
151 @project.reload
151 @project.reload
152 assert_equal NUM_REV, @repository.changesets.count
152 assert_equal NUM_REV, @repository.changesets.count
153 [
153 [
154 "tag00.lightweight",
154 "tag00.lightweight",
155 "tag01.annotated",
155 "tag01.annotated",
156 ].each do |t1|
156 ].each do |t1|
157 get :show, :id => PRJ_ID, :rev => t1
157 get :show, :id => PRJ_ID, :rev => t1
158 assert_response :success
158 assert_response :success
159 assert_template 'show'
159 assert_template 'show'
160 assert_not_nil assigns(:entries)
160 assert_not_nil assigns(:entries)
161 assert assigns(:entries).size > 0
161 assert assigns(:entries).size > 0
162 assert_not_nil assigns(:changesets)
162 assert_not_nil assigns(:changesets)
163 assert assigns(:changesets).size > 0
163 assert assigns(:changesets).size > 0
164 end
164 end
165 end
165 end
166
166
167 def test_browse_directory
167 def test_browse_directory
168 assert_equal 0, @repository.changesets.count
168 assert_equal 0, @repository.changesets.count
169 @repository.fetch_changesets
169 @repository.fetch_changesets
170 @project.reload
170 @project.reload
171 assert_equal NUM_REV, @repository.changesets.count
171 assert_equal NUM_REV, @repository.changesets.count
172 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param]
172 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param]
173 assert_response :success
173 assert_response :success
174 assert_template 'show'
174 assert_template 'show'
175 assert_not_nil assigns(:entries)
175 assert_not_nil assigns(:entries)
176 assert_equal ['edit.png'], assigns(:entries).collect(&:name)
176 assert_equal ['edit.png'], assigns(:entries).collect(&:name)
177 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
177 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
178 assert_not_nil entry
178 assert_not_nil entry
179 assert_equal 'file', entry.kind
179 assert_equal 'file', entry.kind
180 assert_equal 'images/edit.png', entry.path
180 assert_equal 'images/edit.png', entry.path
181 assert_not_nil assigns(:changesets)
181 assert_not_nil assigns(:changesets)
182 assert assigns(:changesets).size > 0
182 assert assigns(:changesets).size > 0
183 end
183 end
184
184
185 def test_browse_at_given_revision
185 def test_browse_at_given_revision
186 assert_equal 0, @repository.changesets.count
186 assert_equal 0, @repository.changesets.count
187 @repository.fetch_changesets
187 @repository.fetch_changesets
188 @project.reload
188 @project.reload
189 assert_equal NUM_REV, @repository.changesets.count
189 assert_equal NUM_REV, @repository.changesets.count
190 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param],
190 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param],
191 :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
191 :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
192 assert_response :success
192 assert_response :success
193 assert_template 'show'
193 assert_template 'show'
194 assert_not_nil assigns(:entries)
194 assert_not_nil assigns(:entries)
195 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
195 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
196 assert_not_nil assigns(:changesets)
196 assert_not_nil assigns(:changesets)
197 assert assigns(:changesets).size > 0
197 assert assigns(:changesets).size > 0
198 end
198 end
199
199
200 def test_changes
200 def test_changes
201 get :changes, :id => PRJ_ID,
201 get :changes, :id => PRJ_ID,
202 :path => repository_path_hash(['images', 'edit.png'])[:param]
202 :path => repository_path_hash(['images', 'edit.png'])[:param]
203 assert_response :success
203 assert_response :success
204 assert_template 'changes'
204 assert_template 'changes'
205 assert_tag :tag => 'h2', :content => 'edit.png'
205 assert_tag :tag => 'h2', :content => 'edit.png'
206 end
206 end
207
207
208 def test_entry_show
208 def test_entry_show
209 get :entry, :id => PRJ_ID,
209 get :entry, :id => PRJ_ID,
210 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
210 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
211 assert_response :success
211 assert_response :success
212 assert_template 'entry'
212 assert_template 'entry'
213 # Line 19
213 # Line 19
214 assert_tag :tag => 'th',
214 assert_tag :tag => 'th',
215 :content => '11',
215 :content => '11',
216 :attributes => { :class => 'line-num' },
216 :attributes => { :class => 'line-num' },
217 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
217 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
218 end
218 end
219
219
220 def test_entry_show_latin_1
220 def test_entry_show_latin_1
221 if @ruby19_non_utf8_pass
221 if @ruby19_non_utf8_pass
222 puts_ruby19_non_utf8_pass()
222 puts_ruby19_non_utf8_pass()
223 elsif WINDOWS_PASS
223 elsif WINDOWS_PASS
224 puts WINDOWS_SKIP_STR
224 puts WINDOWS_SKIP_STR
225 elsif JRUBY_SKIP
225 elsif JRUBY_SKIP
226 puts JRUBY_SKIP_STR
226 puts JRUBY_SKIP_STR
227 else
227 else
228 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
228 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
229 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
229 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
230 get :entry, :id => PRJ_ID,
230 get :entry, :id => PRJ_ID,
231 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
231 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
232 :rev => r1
232 :rev => r1
233 assert_response :success
233 assert_response :success
234 assert_template 'entry'
234 assert_template 'entry'
235 assert_tag :tag => 'th',
235 assert_tag :tag => 'th',
236 :content => '1',
236 :content => '1',
237 :attributes => { :class => 'line-num' },
237 :attributes => { :class => 'line-num' },
238 :sibling => { :tag => 'td',
238 :sibling => { :tag => 'td',
239 :content => /test-#{@char_1}.txt/ }
239 :content => /test-#{@char_1}.txt/ }
240 end
240 end
241 end
241 end
242 end
242 end
243 end
243 end
244
244
245 def test_entry_download
245 def test_entry_download
246 get :entry, :id => PRJ_ID,
246 get :entry, :id => PRJ_ID,
247 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
247 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
248 :format => 'raw'
248 :format => 'raw'
249 assert_response :success
249 assert_response :success
250 # File content
250 # File content
251 assert @response.body.include?('WITHOUT ANY WARRANTY')
251 assert @response.body.include?('WITHOUT ANY WARRANTY')
252 end
252 end
253
253
254 def test_directory_entry
254 def test_directory_entry
255 get :entry, :id => PRJ_ID,
255 get :entry, :id => PRJ_ID,
256 :path => repository_path_hash(['sources'])[:param]
256 :path => repository_path_hash(['sources'])[:param]
257 assert_response :success
257 assert_response :success
258 assert_template 'show'
258 assert_template 'show'
259 assert_not_nil assigns(:entry)
259 assert_not_nil assigns(:entry)
260 assert_equal 'sources', assigns(:entry).name
260 assert_equal 'sources', assigns(:entry).name
261 end
261 end
262
262
263 def test_diff
263 def test_diff
264 assert_equal 0, @repository.changesets.count
264 assert_equal 0, @repository.changesets.count
265 @repository.fetch_changesets
265 @repository.fetch_changesets
266 @project.reload
266 @project.reload
267 assert_equal NUM_REV, @repository.changesets.count
267 assert_equal NUM_REV, @repository.changesets.count
268 # Full diff of changeset 2f9c0091
268 # Full diff of changeset 2f9c0091
269 ['inline', 'sbs'].each do |dt|
269 ['inline', 'sbs'].each do |dt|
270 get :diff,
270 get :diff,
271 :id => PRJ_ID,
271 :id => PRJ_ID,
272 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
272 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
273 :type => dt
273 :type => dt
274 assert_response :success
274 assert_response :success
275 assert_template 'diff'
275 assert_template 'diff'
276 # Line 22 removed
276 # Line 22 removed
277 assert_tag :tag => 'th',
277 assert_tag :tag => 'th',
278 :content => /22/,
278 :content => /22/,
279 :sibling => { :tag => 'td',
279 :sibling => { :tag => 'td',
280 :attributes => { :class => /diff_out/ },
280 :attributes => { :class => /diff_out/ },
281 :content => /def remove/ }
281 :content => /def remove/ }
282 assert_tag :tag => 'h2', :content => /2f9c0091/
282 assert_tag :tag => 'h2', :content => /2f9c0091/
283 end
283 end
284 end
284 end
285
285
286 def test_diff_with_rev_and_path
286 def test_diff_with_rev_and_path
287 assert_equal 0, @repository.changesets.count
287 assert_equal 0, @repository.changesets.count
288 @repository.fetch_changesets
288 @repository.fetch_changesets
289 @project.reload
289 @project.reload
290 assert_equal NUM_REV, @repository.changesets.count
290 assert_equal NUM_REV, @repository.changesets.count
291 with_settings :diff_max_lines_displayed => 1000 do
291 with_settings :diff_max_lines_displayed => 1000 do
292 # Full diff of changeset 2f9c0091
292 # Full diff of changeset 2f9c0091
293 ['inline', 'sbs'].each do |dt|
293 ['inline', 'sbs'].each do |dt|
294 get :diff,
294 get :diff,
295 :id => PRJ_ID,
295 :id => PRJ_ID,
296 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
296 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
297 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
297 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
298 :type => dt
298 :type => dt
299 assert_response :success
299 assert_response :success
300 assert_template 'diff'
300 assert_template 'diff'
301 # Line 22 removed
301 # Line 22 removed
302 assert_tag :tag => 'th',
302 assert_tag :tag => 'th',
303 :content => '22',
303 :content => '22',
304 :sibling => { :tag => 'td',
304 :sibling => { :tag => 'td',
305 :attributes => { :class => /diff_out/ },
305 :attributes => { :class => /diff_out/ },
306 :content => /def remove/ }
306 :content => /def remove/ }
307 assert_tag :tag => 'h2', :content => /2f9c0091/
307 assert_tag :tag => 'h2', :content => /2f9c0091/
308 end
308 end
309 end
309 end
310 end
310 end
311
311
312 def test_diff_truncated
312 def test_diff_truncated
313 assert_equal 0, @repository.changesets.count
313 assert_equal 0, @repository.changesets.count
314 @repository.fetch_changesets
314 @repository.fetch_changesets
315 @project.reload
315 @project.reload
316 assert_equal NUM_REV, @repository.changesets.count
316 assert_equal NUM_REV, @repository.changesets.count
317
317
318 with_settings :diff_max_lines_displayed => 5 do
318 with_settings :diff_max_lines_displayed => 5 do
319 # Truncated diff of changeset 2f9c0091
319 # Truncated diff of changeset 2f9c0091
320 with_cache do
320 with_cache do
321 with_settings :default_language => 'en' do
321 with_settings :default_language => 'en' do
322 get :diff, :id => PRJ_ID, :type => 'inline',
322 get :diff, :id => PRJ_ID, :type => 'inline',
323 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
323 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
324 assert_response :success
324 assert_response :success
325 assert @response.body.include?("... This diff was truncated")
325 assert @response.body.include?("... This diff was truncated")
326 end
326 end
327 with_settings :default_language => 'fr' do
327 with_settings :default_language => 'fr' do
328 get :diff, :id => PRJ_ID, :type => 'inline',
328 get :diff, :id => PRJ_ID, :type => 'inline',
329 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
329 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
330 assert_response :success
330 assert_response :success
331 assert ! @response.body.include?("... This diff was truncated")
331 assert ! @response.body.include?("... This diff was truncated")
332 assert @response.body.include?("... Ce diff")
332 assert @response.body.include?("... Ce diff")
333 end
333 end
334 end
334 end
335 end
335 end
336 end
336 end
337
337
338 def test_diff_two_revs
338 def test_diff_two_revs
339 assert_equal 0, @repository.changesets.count
339 assert_equal 0, @repository.changesets.count
340 @repository.fetch_changesets
340 @repository.fetch_changesets
341 @project.reload
341 @project.reload
342 assert_equal NUM_REV, @repository.changesets.count
342 assert_equal NUM_REV, @repository.changesets.count
343 ['inline', 'sbs'].each do |dt|
343 ['inline', 'sbs'].each do |dt|
344 get :diff,
344 get :diff,
345 :id => PRJ_ID,
345 :id => PRJ_ID,
346 :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
346 :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
347 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
347 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
348 :type => dt
348 :type => dt
349 assert_response :success
349 assert_response :success
350 assert_template 'diff'
350 assert_template 'diff'
351 diff = assigns(:diff)
351 diff = assigns(:diff)
352 assert_not_nil diff
352 assert_not_nil diff
353 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
353 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
354 end
354 end
355 end
355 end
356
356
357 def test_diff_latin_1
357 def test_diff_latin_1
358 if @ruby19_non_utf8_pass
358 if @ruby19_non_utf8_pass
359 puts_ruby19_non_utf8_pass()
359 puts_ruby19_non_utf8_pass()
360 else
360 else
361 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
361 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
362 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
362 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
363 ['inline', 'sbs'].each do |dt|
363 ['inline', 'sbs'].each do |dt|
364 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
364 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
365 assert_response :success
365 assert_response :success
366 assert_template 'diff'
366 assert_template 'diff'
367 assert_tag :tag => 'thead',
367 assert_tag :tag => 'thead',
368 :descendant => {
368 :descendant => {
369 :tag => 'th',
369 :tag => 'th',
370 :attributes => { :class => 'filename' } ,
370 :attributes => { :class => 'filename' } ,
371 :content => /latin-1-dir\/test-#{@char_1}.txt/ ,
371 :content => /latin-1-dir\/test-#{@char_1}.txt/ ,
372 },
372 },
373 :sibling => {
373 :sibling => {
374 :tag => 'tbody',
374 :tag => 'tbody',
375 :descendant => {
375 :descendant => {
376 :tag => 'td',
376 :tag => 'td',
377 :attributes => { :class => /diff_in/ },
377 :attributes => { :class => /diff_in/ },
378 :content => /test-#{@char_1}.txt/
378 :content => /test-#{@char_1}.txt/
379 }
379 }
380 }
380 }
381 end
381 end
382 end
382 end
383 end
383 end
384 end
384 end
385 end
385 end
386
386
387 def test_save_diff_type
387 def test_save_diff_type
388 @request.session[:user_id] = 1 # admin
388 user1 = User.find(1)
389 user1.pref[:diff_type] = nil
390 user1.preference.save
389 user = User.find(1)
391 user = User.find(1)
392 assert_nil user.pref[:diff_type]
393
394 @request.session[:user_id] = 1 # admin
390 get :diff,
395 get :diff,
391 :id => PRJ_ID,
396 :id => PRJ_ID,
392 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
397 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
393 assert_response :success
398 assert_response :success
394 assert_template 'diff'
399 assert_template 'diff'
395 user.reload
400 user.reload
396 assert_equal "inline", user.pref[:diff_type]
401 assert_equal "inline", user.pref[:diff_type]
397 get :diff,
402 get :diff,
398 :id => PRJ_ID,
403 :id => PRJ_ID,
399 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
404 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
400 :type => 'sbs'
405 :type => 'sbs'
401 assert_response :success
406 assert_response :success
402 assert_template 'diff'
407 assert_template 'diff'
403 user.reload
408 user.reload
404 assert_equal "sbs", user.pref[:diff_type]
409 assert_equal "sbs", user.pref[:diff_type]
405 end
410 end
406
411
407 def test_annotate
412 def test_annotate
408 get :annotate, :id => PRJ_ID,
413 get :annotate, :id => PRJ_ID,
409 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
414 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
410 assert_response :success
415 assert_response :success
411 assert_template 'annotate'
416 assert_template 'annotate'
412
417
413 # Line 23, changeset 2f9c0091
418 # Line 23, changeset 2f9c0091
414 assert_select 'tr' do
419 assert_select 'tr' do
415 assert_select 'th.line-num', :text => '23'
420 assert_select 'th.line-num', :text => '23'
416 assert_select 'td.revision', :text => /2f9c0091/
421 assert_select 'td.revision', :text => /2f9c0091/
417 assert_select 'td.author', :text => 'jsmith'
422 assert_select 'td.author', :text => 'jsmith'
418 assert_select 'td', :text => /remove_watcher/
423 assert_select 'td', :text => /remove_watcher/
419 end
424 end
420 end
425 end
421
426
422 def test_annotate_at_given_revision
427 def test_annotate_at_given_revision
423 assert_equal 0, @repository.changesets.count
428 assert_equal 0, @repository.changesets.count
424 @repository.fetch_changesets
429 @repository.fetch_changesets
425 @project.reload
430 @project.reload
426 assert_equal NUM_REV, @repository.changesets.count
431 assert_equal NUM_REV, @repository.changesets.count
427 get :annotate, :id => PRJ_ID, :rev => 'deff7',
432 get :annotate, :id => PRJ_ID, :rev => 'deff7',
428 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
433 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
429 assert_response :success
434 assert_response :success
430 assert_template 'annotate'
435 assert_template 'annotate'
431 assert_tag :tag => 'h2', :content => /@ deff712f/
436 assert_tag :tag => 'h2', :content => /@ deff712f/
432 end
437 end
433
438
434 def test_annotate_binary_file
439 def test_annotate_binary_file
435 get :annotate, :id => PRJ_ID,
440 get :annotate, :id => PRJ_ID,
436 :path => repository_path_hash(['images', 'edit.png'])[:param]
441 :path => repository_path_hash(['images', 'edit.png'])[:param]
437 assert_response 500
442 assert_response 500
438 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
443 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
439 :content => /cannot be annotated/
444 :content => /cannot be annotated/
440 end
445 end
441
446
442 def test_annotate_error_when_too_big
447 def test_annotate_error_when_too_big
443 with_settings :file_max_size_displayed => 1 do
448 with_settings :file_max_size_displayed => 1 do
444 get :annotate, :id => PRJ_ID,
449 get :annotate, :id => PRJ_ID,
445 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
450 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
446 :rev => 'deff712f'
451 :rev => 'deff712f'
447 assert_response 500
452 assert_response 500
448 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
453 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
449 :content => /exceeds the maximum text file size/
454 :content => /exceeds the maximum text file size/
450
455
451 get :annotate, :id => PRJ_ID,
456 get :annotate, :id => PRJ_ID,
452 :path => repository_path_hash(['README'])[:param],
457 :path => repository_path_hash(['README'])[:param],
453 :rev => '7234cb2'
458 :rev => '7234cb2'
454 assert_response :success
459 assert_response :success
455 assert_template 'annotate'
460 assert_template 'annotate'
456 end
461 end
457 end
462 end
458
463
459 def test_annotate_latin_1
464 def test_annotate_latin_1
460 if @ruby19_non_utf8_pass
465 if @ruby19_non_utf8_pass
461 puts_ruby19_non_utf8_pass()
466 puts_ruby19_non_utf8_pass()
462 elsif WINDOWS_PASS
467 elsif WINDOWS_PASS
463 puts WINDOWS_SKIP_STR
468 puts WINDOWS_SKIP_STR
464 elsif JRUBY_SKIP
469 elsif JRUBY_SKIP
465 puts JRUBY_SKIP_STR
470 puts JRUBY_SKIP_STR
466 else
471 else
467 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
472 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
468 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
473 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
469 get :annotate, :id => PRJ_ID,
474 get :annotate, :id => PRJ_ID,
470 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
475 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
471 :rev => r1
476 :rev => r1
472 assert_tag :tag => 'th',
477 assert_tag :tag => 'th',
473 :content => '1',
478 :content => '1',
474 :attributes => { :class => 'line-num' },
479 :attributes => { :class => 'line-num' },
475 :sibling => { :tag => 'td',
480 :sibling => { :tag => 'td',
476 :content => /test-#{@char_1}.txt/ }
481 :content => /test-#{@char_1}.txt/ }
477 end
482 end
478 end
483 end
479 end
484 end
480 end
485 end
481
486
482 def test_revision
487 def test_revision
483 assert_equal 0, @repository.changesets.count
488 assert_equal 0, @repository.changesets.count
484 @repository.fetch_changesets
489 @repository.fetch_changesets
485 @project.reload
490 @project.reload
486 assert_equal NUM_REV, @repository.changesets.count
491 assert_equal NUM_REV, @repository.changesets.count
487 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
492 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
488 get :revision, :id => PRJ_ID, :rev => r
493 get :revision, :id => PRJ_ID, :rev => r
489 assert_response :success
494 assert_response :success
490 assert_template 'revision'
495 assert_template 'revision'
491 end
496 end
492 end
497 end
493
498
494 def test_empty_revision
499 def test_empty_revision
495 assert_equal 0, @repository.changesets.count
500 assert_equal 0, @repository.changesets.count
496 @repository.fetch_changesets
501 @repository.fetch_changesets
497 @project.reload
502 @project.reload
498 assert_equal NUM_REV, @repository.changesets.count
503 assert_equal NUM_REV, @repository.changesets.count
499 ['', ' ', nil].each do |r|
504 ['', ' ', nil].each do |r|
500 get :revision, :id => PRJ_ID, :rev => r
505 get :revision, :id => PRJ_ID, :rev => r
501 assert_response 404
506 assert_response 404
502 assert_error_tag :content => /was not found/
507 assert_error_tag :content => /was not found/
503 end
508 end
504 end
509 end
505
510
506 def test_destroy_valid_repository
511 def test_destroy_valid_repository
507 @request.session[:user_id] = 1 # admin
512 @request.session[:user_id] = 1 # admin
508 assert_equal 0, @repository.changesets.count
513 assert_equal 0, @repository.changesets.count
509 @repository.fetch_changesets
514 @repository.fetch_changesets
510 @project.reload
515 @project.reload
511 assert_equal NUM_REV, @repository.changesets.count
516 assert_equal NUM_REV, @repository.changesets.count
512
517
513 assert_difference 'Repository.count', -1 do
518 assert_difference 'Repository.count', -1 do
514 delete :destroy, :id => @repository.id
519 delete :destroy, :id => @repository.id
515 end
520 end
516 assert_response 302
521 assert_response 302
517 @project.reload
522 @project.reload
518 assert_nil @project.repository
523 assert_nil @project.repository
519 end
524 end
520
525
521 def test_destroy_invalid_repository
526 def test_destroy_invalid_repository
522 @request.session[:user_id] = 1 # admin
527 @request.session[:user_id] = 1 # admin
523 @project.repository.destroy
528 @project.repository.destroy
524 @repository = Repository::Git.create!(
529 @repository = Repository::Git.create!(
525 :project => @project,
530 :project => @project,
526 :url => "/invalid",
531 :url => "/invalid",
527 :path_encoding => 'ISO-8859-1'
532 :path_encoding => 'ISO-8859-1'
528 )
533 )
529 @repository.fetch_changesets
534 @repository.fetch_changesets
530 @repository.reload
535 @repository.reload
531 assert_equal 0, @repository.changesets.count
536 assert_equal 0, @repository.changesets.count
532
537
533 assert_difference 'Repository.count', -1 do
538 assert_difference 'Repository.count', -1 do
534 delete :destroy, :id => @repository.id
539 delete :destroy, :id => @repository.id
535 end
540 end
536 assert_response 302
541 assert_response 302
537 @project.reload
542 @project.reload
538 assert_nil @project.repository
543 assert_nil @project.repository
539 end
544 end
540
545
541 private
546 private
542
547
543 def puts_ruby19_non_utf8_pass
548 def puts_ruby19_non_utf8_pass
544 puts "TODO: This test fails in Ruby 1.9 " +
549 puts "TODO: This test fails in Ruby 1.9 " +
545 "and Encoding.default_external is not UTF-8. " +
550 "and Encoding.default_external is not UTF-8. " +
546 "Current value is '#{Encoding.default_external.to_s}'"
551 "Current value is '#{Encoding.default_external.to_s}'"
547 end
552 end
548 else
553 else
549 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
554 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
550 def test_fake; assert true end
555 def test_fake; assert true end
551 end
556 end
552
557
553 private
558 private
554 def with_cache(&block)
559 def with_cache(&block)
555 before = ActionController::Base.perform_caching
560 before = ActionController::Base.perform_caching
556 ActionController::Base.perform_caching = true
561 ActionController::Base.perform_caching = true
557 block.call
562 block.call
558 ActionController::Base.perform_caching = before
563 ActionController::Base.perform_caching = before
559 end
564 end
560 end
565 end
General Comments 0
You need to be logged in to leave comments. Login now