##// END OF EJS Templates
Merged r10501 from trunk...
Toshi MARUYAMA -
r10296:f27a0eca5b14
parent child
Show More
@@ -1,363 +1,368
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_show_text_file
114 119 get :show, :id => 4
115 120 assert_response :success
116 121 assert_template 'file'
117 122 assert_equal 'text/html', @response.content_type
118 123 set_tmp_attachments_directory
119 124 end
120 125
121 126 def test_show_text_file_utf_8
122 127 set_tmp_attachments_directory
123 128 a = Attachment.new(:container => Issue.find(1),
124 129 :file => uploaded_test_file("japanese-utf-8.txt", "text/plain"),
125 130 :author => User.find(1))
126 131 assert a.save
127 132 assert_equal 'japanese-utf-8.txt', a.filename
128 133
129 134 str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e"
130 135 str_japanese.force_encoding('UTF-8') if str_japanese.respond_to?(:force_encoding)
131 136
132 137 get :show, :id => a.id
133 138 assert_response :success
134 139 assert_template 'file'
135 140 assert_equal 'text/html', @response.content_type
136 141 assert_tag :tag => 'th',
137 142 :content => '1',
138 143 :attributes => { :class => 'line-num' },
139 144 :sibling => { :tag => 'td', :content => /#{str_japanese}/ }
140 145 end
141 146
142 147 def test_show_text_file_replcace_cannot_convert_content
143 148 set_tmp_attachments_directory
144 149 with_settings :repositories_encodings => 'UTF-8' do
145 150 a = Attachment.new(:container => Issue.find(1),
146 151 :file => uploaded_test_file("iso8859-1.txt", "text/plain"),
147 152 :author => User.find(1))
148 153 assert a.save
149 154 assert_equal 'iso8859-1.txt', a.filename
150 155
151 156 get :show, :id => a.id
152 157 assert_response :success
153 158 assert_template 'file'
154 159 assert_equal 'text/html', @response.content_type
155 160 assert_tag :tag => 'th',
156 161 :content => '7',
157 162 :attributes => { :class => 'line-num' },
158 163 :sibling => { :tag => 'td', :content => /Demande cr\?\?e avec succ\?s/ }
159 164 end
160 165 end
161 166
162 167 def test_show_text_file_latin_1
163 168 set_tmp_attachments_directory
164 169 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
165 170 a = Attachment.new(:container => Issue.find(1),
166 171 :file => uploaded_test_file("iso8859-1.txt", "text/plain"),
167 172 :author => User.find(1))
168 173 assert a.save
169 174 assert_equal 'iso8859-1.txt', a.filename
170 175
171 176 get :show, :id => a.id
172 177 assert_response :success
173 178 assert_template 'file'
174 179 assert_equal 'text/html', @response.content_type
175 180 assert_tag :tag => 'th',
176 181 :content => '7',
177 182 :attributes => { :class => 'line-num' },
178 183 :sibling => { :tag => 'td', :content => /Demande créée avec succès/ }
179 184 end
180 185 end
181 186
182 187 def test_show_text_file_should_send_if_too_big
183 188 Setting.file_max_size_displayed = 512
184 189 Attachment.find(4).update_attribute :filesize, 754.kilobyte
185 190
186 191 get :show, :id => 4
187 192 assert_response :success
188 193 assert_equal 'application/x-ruby', @response.content_type
189 194 set_tmp_attachments_directory
190 195 end
191 196
192 197 def test_show_other
193 198 get :show, :id => 6
194 199 assert_response :success
195 200 assert_equal 'application/octet-stream', @response.content_type
196 201 set_tmp_attachments_directory
197 202 end
198 203
199 204 def test_show_file_from_private_issue_without_permission
200 205 get :show, :id => 15
201 206 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2F15'
202 207 set_tmp_attachments_directory
203 208 end
204 209
205 210 def test_show_file_from_private_issue_with_permission
206 211 @request.session[:user_id] = 2
207 212 get :show, :id => 15
208 213 assert_response :success
209 214 assert_tag 'h2', :content => /private.diff/
210 215 set_tmp_attachments_directory
211 216 end
212 217
213 218 def test_show_file_without_container_should_be_denied
214 219 set_tmp_attachments_directory
215 220 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
216 221
217 222 @request.session[:user_id] = 2
218 223 get :show, :id => attachment.id
219 224 assert_response 403
220 225 end
221 226
222 227 def test_show_invalid_should_respond_with_404
223 228 get :show, :id => 999
224 229 assert_response 404
225 230 end
226 231
227 232 def test_download_text_file
228 233 get :download, :id => 4
229 234 assert_response :success
230 235 assert_equal 'application/x-ruby', @response.content_type
231 236 set_tmp_attachments_directory
232 237 end
233 238
234 239 def test_download_version_file_with_issue_tracking_disabled
235 240 Project.find(1).disable_module! :issue_tracking
236 241 get :download, :id => 9
237 242 assert_response :success
238 243 end
239 244
240 245 def test_download_should_assign_content_type_if_blank
241 246 Attachment.find(4).update_attribute(:content_type, '')
242 247
243 248 get :download, :id => 4
244 249 assert_response :success
245 250 assert_equal 'text/x-ruby', @response.content_type
246 251 set_tmp_attachments_directory
247 252 end
248 253
249 254 def test_download_missing_file
250 255 get :download, :id => 2
251 256 assert_response 404
252 257 set_tmp_attachments_directory
253 258 end
254 259
255 260 def test_download_should_be_denied_without_permission
256 261 get :download, :id => 7
257 262 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdownload%2F7'
258 263 set_tmp_attachments_directory
259 264 end
260 265
261 266 if convert_installed?
262 267 def test_thumbnail
263 268 Attachment.clear_thumbnails
264 269 @request.session[:user_id] = 2
265 270
266 271 get :thumbnail, :id => 16
267 272 assert_response :success
268 273 assert_equal 'image/png', response.content_type
269 274 end
270 275
271 276 def test_thumbnail_should_not_exceed_maximum_size
272 277 Redmine::Thumbnail.expects(:generate).with {|source, target, size| size == 800}
273 278
274 279 @request.session[:user_id] = 2
275 280 get :thumbnail, :id => 16, :size => 2000
276 281 end
277 282
278 283 def test_thumbnail_should_round_size
279 284 Redmine::Thumbnail.expects(:generate).with {|source, target, size| size == 250}
280 285
281 286 @request.session[:user_id] = 2
282 287 get :thumbnail, :id => 16, :size => 260
283 288 end
284 289
285 290 def test_thumbnail_should_return_404_for_non_image_attachment
286 291 @request.session[:user_id] = 2
287 292
288 293 get :thumbnail, :id => 15
289 294 assert_response 404
290 295 end
291 296
292 297 def test_thumbnail_should_return_404_if_thumbnail_generation_failed
293 298 Attachment.any_instance.stubs(:thumbnail).returns(nil)
294 299 @request.session[:user_id] = 2
295 300
296 301 get :thumbnail, :id => 16
297 302 assert_response 404
298 303 end
299 304
300 305 def test_thumbnail_should_be_denied_without_permission
301 306 get :thumbnail, :id => 16
302 307 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fthumbnail%2F16'
303 308 end
304 309 else
305 310 puts '(ImageMagick convert not available)'
306 311 end
307 312
308 313 def test_destroy_issue_attachment
309 314 set_tmp_attachments_directory
310 315 issue = Issue.find(3)
311 316 @request.session[:user_id] = 2
312 317
313 318 assert_difference 'issue.attachments.count', -1 do
314 319 assert_difference 'Journal.count' do
315 320 delete :destroy, :id => 1
316 321 assert_redirected_to '/projects/ecookbook'
317 322 end
318 323 end
319 324 assert_nil Attachment.find_by_id(1)
320 325 j = Journal.first(:order => 'id DESC')
321 326 assert_equal issue, j.journalized
322 327 assert_equal 'attachment', j.details.first.property
323 328 assert_equal '1', j.details.first.prop_key
324 329 assert_equal 'error281.txt', j.details.first.old_value
325 330 assert_equal User.find(2), j.user
326 331 end
327 332
328 333 def test_destroy_wiki_page_attachment
329 334 set_tmp_attachments_directory
330 335 @request.session[:user_id] = 2
331 336 assert_difference 'Attachment.count', -1 do
332 337 delete :destroy, :id => 3
333 338 assert_response 302
334 339 end
335 340 end
336 341
337 342 def test_destroy_project_attachment
338 343 set_tmp_attachments_directory
339 344 @request.session[:user_id] = 2
340 345 assert_difference 'Attachment.count', -1 do
341 346 delete :destroy, :id => 8
342 347 assert_response 302
343 348 end
344 349 end
345 350
346 351 def test_destroy_version_attachment
347 352 set_tmp_attachments_directory
348 353 @request.session[:user_id] = 2
349 354 assert_difference 'Attachment.count', -1 do
350 355 delete :destroy, :id => 9
351 356 assert_response 302
352 357 end
353 358 end
354 359
355 360 def test_destroy_without_permission
356 361 set_tmp_attachments_directory
357 362 assert_no_difference 'Attachment.count' do
358 363 delete :destroy, :id => 3
359 364 end
360 365 assert_response 302
361 366 assert Attachment.find_by_id(3)
362 367 end
363 368 end
@@ -1,560 +1,565
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_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 391 user = User.find(1)
392 assert_nil user.pref[:diff_type]
393
394 @request.session[:user_id] = 1 # admin
390 395 get :diff,
391 396 :id => PRJ_ID,
392 397 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
393 398 assert_response :success
394 399 assert_template 'diff'
395 400 user.reload
396 401 assert_equal "inline", user.pref[:diff_type]
397 402 get :diff,
398 403 :id => PRJ_ID,
399 404 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
400 405 :type => 'sbs'
401 406 assert_response :success
402 407 assert_template 'diff'
403 408 user.reload
404 409 assert_equal "sbs", user.pref[:diff_type]
405 410 end
406 411
407 412 def test_annotate
408 413 get :annotate, :id => PRJ_ID,
409 414 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
410 415 assert_response :success
411 416 assert_template 'annotate'
412 417
413 418 # Line 23, changeset 2f9c0091
414 419 assert_select 'tr' do
415 420 assert_select 'th.line-num', :text => '23'
416 421 assert_select 'td.revision', :text => /2f9c0091/
417 422 assert_select 'td.author', :text => 'jsmith'
418 423 assert_select 'td', :text => /remove_watcher/
419 424 end
420 425 end
421 426
422 427 def test_annotate_at_given_revision
423 428 assert_equal 0, @repository.changesets.count
424 429 @repository.fetch_changesets
425 430 @project.reload
426 431 assert_equal NUM_REV, @repository.changesets.count
427 432 get :annotate, :id => PRJ_ID, :rev => 'deff7',
428 433 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
429 434 assert_response :success
430 435 assert_template 'annotate'
431 436 assert_tag :tag => 'h2', :content => /@ deff712f/
432 437 end
433 438
434 439 def test_annotate_binary_file
435 440 get :annotate, :id => PRJ_ID,
436 441 :path => repository_path_hash(['images', 'edit.png'])[:param]
437 442 assert_response 500
438 443 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
439 444 :content => /cannot be annotated/
440 445 end
441 446
442 447 def test_annotate_error_when_too_big
443 448 with_settings :file_max_size_displayed => 1 do
444 449 get :annotate, :id => PRJ_ID,
445 450 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
446 451 :rev => 'deff712f'
447 452 assert_response 500
448 453 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
449 454 :content => /exceeds the maximum text file size/
450 455
451 456 get :annotate, :id => PRJ_ID,
452 457 :path => repository_path_hash(['README'])[:param],
453 458 :rev => '7234cb2'
454 459 assert_response :success
455 460 assert_template 'annotate'
456 461 end
457 462 end
458 463
459 464 def test_annotate_latin_1
460 465 if @ruby19_non_utf8_pass
461 466 puts_ruby19_non_utf8_pass()
462 467 elsif WINDOWS_PASS
463 468 puts WINDOWS_SKIP_STR
464 469 elsif JRUBY_SKIP
465 470 puts JRUBY_SKIP_STR
466 471 else
467 472 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
468 473 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
469 474 get :annotate, :id => PRJ_ID,
470 475 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
471 476 :rev => r1
472 477 assert_tag :tag => 'th',
473 478 :content => '1',
474 479 :attributes => { :class => 'line-num' },
475 480 :sibling => { :tag => 'td',
476 481 :content => /test-#{@char_1}.txt/ }
477 482 end
478 483 end
479 484 end
480 485 end
481 486
482 487 def test_revision
483 488 assert_equal 0, @repository.changesets.count
484 489 @repository.fetch_changesets
485 490 @project.reload
486 491 assert_equal NUM_REV, @repository.changesets.count
487 492 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
488 493 get :revision, :id => PRJ_ID, :rev => r
489 494 assert_response :success
490 495 assert_template 'revision'
491 496 end
492 497 end
493 498
494 499 def test_empty_revision
495 500 assert_equal 0, @repository.changesets.count
496 501 @repository.fetch_changesets
497 502 @project.reload
498 503 assert_equal NUM_REV, @repository.changesets.count
499 504 ['', ' ', nil].each do |r|
500 505 get :revision, :id => PRJ_ID, :rev => r
501 506 assert_response 404
502 507 assert_error_tag :content => /was not found/
503 508 end
504 509 end
505 510
506 511 def test_destroy_valid_repository
507 512 @request.session[:user_id] = 1 # admin
508 513 assert_equal 0, @repository.changesets.count
509 514 @repository.fetch_changesets
510 515 @project.reload
511 516 assert_equal NUM_REV, @repository.changesets.count
512 517
513 518 assert_difference 'Repository.count', -1 do
514 519 delete :destroy, :id => @repository.id
515 520 end
516 521 assert_response 302
517 522 @project.reload
518 523 assert_nil @project.repository
519 524 end
520 525
521 526 def test_destroy_invalid_repository
522 527 @request.session[:user_id] = 1 # admin
523 528 @project.repository.destroy
524 529 @repository = Repository::Git.create!(
525 530 :project => @project,
526 531 :url => "/invalid",
527 532 :path_encoding => 'ISO-8859-1'
528 533 )
529 534 @repository.fetch_changesets
530 535 @repository.reload
531 536 assert_equal 0, @repository.changesets.count
532 537
533 538 assert_difference 'Repository.count', -1 do
534 539 delete :destroy, :id => @repository.id
535 540 end
536 541 assert_response 302
537 542 @project.reload
538 543 assert_nil @project.repository
539 544 end
540 545
541 546 private
542 547
543 548 def puts_ruby19_non_utf8_pass
544 549 puts "TODO: This test fails in Ruby 1.9 " +
545 550 "and Encoding.default_external is not UTF-8. " +
546 551 "Current value is '#{Encoding.default_external.to_s}'"
547 552 end
548 553 else
549 554 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
550 555 def test_fake; assert true end
551 556 end
552 557
553 558 private
554 559 def with_cache(&block)
555 560 before = ActionController::Base.perform_caching
556 561 ActionController::Base.perform_caching = true
557 562 block.call
558 563 ActionController::Base.perform_caching = before
559 564 end
560 565 end
General Comments 0
You need to be logged in to leave comments. Login now