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