@@ -1,534 +1,548 | |||
|
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 | ## Ruby uses ANSI api to fork a process on Windows. | |
|
33 | ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem | |
|
34 | ## and these are incompatible with ASCII. | |
|
35 | ## Git for Windows (msysGit) changed internal API from ANSI to Unicode in 1.7.10 | |
|
36 | ## http://code.google.com/p/msysgit/issues/detail?id=80 | |
|
37 | ## So, Latin-1 path tests fail on Japanese Windows | |
|
38 | WINDOWS_PASS = (Redmine::Platform.mswin? && | |
|
39 | Redmine::Scm::Adapters::GitAdapter.client_version_above?([1, 7, 10])) | |
|
40 | WINDOWS_SKIP_STR = "TODO: This test fails in Git for Windows above 1.7.10" | |
|
41 | ||
|
32 | 42 | ## Git, Mercurial and CVS path encodings are binary. |
|
33 | 43 | ## Subversion supports URL encoding for path. |
|
34 | 44 | ## Redmine Mercurial adapter and extension use URL encoding. |
|
35 | 45 | ## Git accepts only binary path in command line parameter. |
|
36 | 46 | ## So, there is no way to use binary command line parameter in JRuby. |
|
37 | 47 | JRUBY_SKIP = (RUBY_PLATFORM == 'java') |
|
38 | 48 | JRUBY_SKIP_STR = "TODO: This test fails in JRuby" |
|
39 | 49 | |
|
40 | 50 | def setup |
|
41 | 51 | @ruby19_non_utf8_pass = |
|
42 | 52 | (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8') |
|
43 | 53 | |
|
44 | 54 | User.current = nil |
|
45 | 55 | @project = Project.find(PRJ_ID) |
|
46 | 56 | @repository = Repository::Git.create( |
|
47 | 57 | :project => @project, |
|
48 | 58 | :url => REPOSITORY_PATH, |
|
49 | 59 | :path_encoding => 'ISO-8859-1' |
|
50 | 60 | ) |
|
51 | 61 | assert @repository |
|
52 | 62 | @char_1 = CHAR_1_HEX.dup |
|
53 | 63 | if @char_1.respond_to?(:force_encoding) |
|
54 | 64 | @char_1.force_encoding('UTF-8') |
|
55 | 65 | end |
|
56 | 66 | |
|
57 | 67 | Setting.default_language = 'en' |
|
58 | 68 | end |
|
59 | 69 | |
|
60 | 70 | def test_create_and_update |
|
61 | 71 | @request.session[:user_id] = 1 |
|
62 | 72 | assert_difference 'Repository.count' do |
|
63 | 73 | post :create, :project_id => 'subproject1', |
|
64 | 74 | :repository_scm => 'Git', |
|
65 | 75 | :repository => { |
|
66 | 76 | :url => '/test', |
|
67 | 77 | :is_default => '0', |
|
68 | 78 | :identifier => 'test-create', |
|
69 | 79 | :extra_report_last_commit => '1', |
|
70 | 80 | } |
|
71 | 81 | end |
|
72 | 82 | assert_response 302 |
|
73 | 83 | repository = Repository.first(:order => 'id DESC') |
|
74 | 84 | assert_kind_of Repository::Git, repository |
|
75 | 85 | assert_equal '/test', repository.url |
|
76 | 86 | assert_equal true, repository.extra_report_last_commit |
|
77 | 87 | |
|
78 | 88 | put :update, :id => repository.id, |
|
79 | 89 | :repository => { |
|
80 | 90 | :extra_report_last_commit => '0', |
|
81 | 91 | :identifier => 'test-update', |
|
82 | 92 | } |
|
83 | 93 | assert_response 302 |
|
84 | 94 | repo2 = Repository.find(repository.id) |
|
85 | 95 | assert_equal 'test-update', repo2.identifier |
|
86 | 96 | assert_equal false, repo2.extra_report_last_commit |
|
87 | 97 | end |
|
88 | 98 | |
|
89 | 99 | if File.directory?(REPOSITORY_PATH) |
|
90 | 100 | def test_get_new |
|
91 | 101 | @request.session[:user_id] = 1 |
|
92 | 102 | @project.repository.destroy |
|
93 | 103 | get :new, :project_id => 'subproject1', :repository_scm => 'Git' |
|
94 | 104 | assert_response :success |
|
95 | 105 | assert_template 'new' |
|
96 | 106 | assert_kind_of Repository::Git, assigns(:repository) |
|
97 | 107 | assert assigns(:repository).new_record? |
|
98 | 108 | end |
|
99 | 109 | |
|
100 | 110 | def test_browse_root |
|
101 | 111 | assert_equal 0, @repository.changesets.count |
|
102 | 112 | @repository.fetch_changesets |
|
103 | 113 | @project.reload |
|
104 | 114 | assert_equal NUM_REV, @repository.changesets.count |
|
105 | 115 | |
|
106 | 116 | get :show, :id => PRJ_ID |
|
107 | 117 | assert_response :success |
|
108 | 118 | assert_template 'show' |
|
109 | 119 | assert_not_nil assigns(:entries) |
|
110 | 120 | assert_equal 9, assigns(:entries).size |
|
111 | 121 | assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} |
|
112 | 122 | assert assigns(:entries).detect {|e| e.name == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir'} |
|
113 | 123 | assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} |
|
114 | 124 | assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} |
|
115 | 125 | assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'} |
|
116 | 126 | assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'} |
|
117 | 127 | assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'} |
|
118 | 128 | assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'} |
|
119 | 129 | assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'} |
|
120 | 130 | assert_not_nil assigns(:changesets) |
|
121 | 131 | assert assigns(:changesets).size > 0 |
|
122 | 132 | end |
|
123 | 133 | |
|
124 | 134 | def test_browse_branch |
|
125 | 135 | assert_equal 0, @repository.changesets.count |
|
126 | 136 | @repository.fetch_changesets |
|
127 | 137 | @project.reload |
|
128 | 138 | assert_equal NUM_REV, @repository.changesets.count |
|
129 | 139 | get :show, :id => PRJ_ID, :rev => 'test_branch' |
|
130 | 140 | assert_response :success |
|
131 | 141 | assert_template 'show' |
|
132 | 142 | assert_not_nil assigns(:entries) |
|
133 | 143 | assert_equal 4, assigns(:entries).size |
|
134 | 144 | assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} |
|
135 | 145 | assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} |
|
136 | 146 | assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} |
|
137 | 147 | assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'} |
|
138 | 148 | assert_not_nil assigns(:changesets) |
|
139 | 149 | assert assigns(:changesets).size > 0 |
|
140 | 150 | end |
|
141 | 151 | |
|
142 | 152 | def test_browse_tag |
|
143 | 153 | assert_equal 0, @repository.changesets.count |
|
144 | 154 | @repository.fetch_changesets |
|
145 | 155 | @project.reload |
|
146 | 156 | assert_equal NUM_REV, @repository.changesets.count |
|
147 | 157 | [ |
|
148 | 158 | "tag00.lightweight", |
|
149 | 159 | "tag01.annotated", |
|
150 | 160 | ].each do |t1| |
|
151 | 161 | get :show, :id => PRJ_ID, :rev => t1 |
|
152 | 162 | assert_response :success |
|
153 | 163 | assert_template 'show' |
|
154 | 164 | assert_not_nil assigns(:entries) |
|
155 | 165 | assert assigns(:entries).size > 0 |
|
156 | 166 | assert_not_nil assigns(:changesets) |
|
157 | 167 | assert assigns(:changesets).size > 0 |
|
158 | 168 | end |
|
159 | 169 | end |
|
160 | 170 | |
|
161 | 171 | def test_browse_directory |
|
162 | 172 | assert_equal 0, @repository.changesets.count |
|
163 | 173 | @repository.fetch_changesets |
|
164 | 174 | @project.reload |
|
165 | 175 | assert_equal NUM_REV, @repository.changesets.count |
|
166 | 176 | get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param] |
|
167 | 177 | assert_response :success |
|
168 | 178 | assert_template 'show' |
|
169 | 179 | assert_not_nil assigns(:entries) |
|
170 | 180 | assert_equal ['edit.png'], assigns(:entries).collect(&:name) |
|
171 | 181 | entry = assigns(:entries).detect {|e| e.name == 'edit.png'} |
|
172 | 182 | assert_not_nil entry |
|
173 | 183 | assert_equal 'file', entry.kind |
|
174 | 184 | assert_equal 'images/edit.png', entry.path |
|
175 | 185 | assert_not_nil assigns(:changesets) |
|
176 | 186 | assert assigns(:changesets).size > 0 |
|
177 | 187 | end |
|
178 | 188 | |
|
179 | 189 | def test_browse_at_given_revision |
|
180 | 190 | assert_equal 0, @repository.changesets.count |
|
181 | 191 | @repository.fetch_changesets |
|
182 | 192 | @project.reload |
|
183 | 193 | assert_equal NUM_REV, @repository.changesets.count |
|
184 | 194 | get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param], |
|
185 | 195 | :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518' |
|
186 | 196 | assert_response :success |
|
187 | 197 | assert_template 'show' |
|
188 | 198 | assert_not_nil assigns(:entries) |
|
189 | 199 | assert_equal ['delete.png'], assigns(:entries).collect(&:name) |
|
190 | 200 | assert_not_nil assigns(:changesets) |
|
191 | 201 | assert assigns(:changesets).size > 0 |
|
192 | 202 | end |
|
193 | 203 | |
|
194 | 204 | def test_changes |
|
195 | 205 | get :changes, :id => PRJ_ID, |
|
196 | 206 | :path => repository_path_hash(['images', 'edit.png'])[:param] |
|
197 | 207 | assert_response :success |
|
198 | 208 | assert_template 'changes' |
|
199 | 209 | assert_tag :tag => 'h2', :content => 'edit.png' |
|
200 | 210 | end |
|
201 | 211 | |
|
202 | 212 | def test_entry_show |
|
203 | 213 | get :entry, :id => PRJ_ID, |
|
204 | 214 | :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param] |
|
205 | 215 | assert_response :success |
|
206 | 216 | assert_template 'entry' |
|
207 | 217 | # Line 19 |
|
208 | 218 | assert_tag :tag => 'th', |
|
209 | 219 | :content => '11', |
|
210 | 220 | :attributes => { :class => 'line-num' }, |
|
211 | 221 | :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ } |
|
212 | 222 | end |
|
213 | 223 | |
|
214 | 224 | def test_entry_show_latin_1 |
|
215 | 225 | if @ruby19_non_utf8_pass |
|
216 | 226 | puts_ruby19_non_utf8_pass() |
|
227 | elsif WINDOWS_PASS | |
|
228 | puts WINDOWS_SKIP_STR | |
|
217 | 229 | elsif JRUBY_SKIP |
|
218 | 230 | puts JRUBY_SKIP_STR |
|
219 | 231 | else |
|
220 | 232 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do |
|
221 | 233 | ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1| |
|
222 | 234 | get :entry, :id => PRJ_ID, |
|
223 | 235 | :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param], |
|
224 | 236 | :rev => r1 |
|
225 | 237 | assert_response :success |
|
226 | 238 | assert_template 'entry' |
|
227 | 239 | assert_tag :tag => 'th', |
|
228 | 240 | :content => '1', |
|
229 | 241 | :attributes => { :class => 'line-num' }, |
|
230 | 242 | :sibling => { :tag => 'td', |
|
231 | 243 | :content => /test-#{@char_1}.txt/ } |
|
232 | 244 | end |
|
233 | 245 | end |
|
234 | 246 | end |
|
235 | 247 | end |
|
236 | 248 | |
|
237 | 249 | def test_entry_download |
|
238 | 250 | get :entry, :id => PRJ_ID, |
|
239 | 251 | :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param], |
|
240 | 252 | :format => 'raw' |
|
241 | 253 | assert_response :success |
|
242 | 254 | # File content |
|
243 | 255 | assert @response.body.include?('WITHOUT ANY WARRANTY') |
|
244 | 256 | end |
|
245 | 257 | |
|
246 | 258 | def test_directory_entry |
|
247 | 259 | get :entry, :id => PRJ_ID, |
|
248 | 260 | :path => repository_path_hash(['sources'])[:param] |
|
249 | 261 | assert_response :success |
|
250 | 262 | assert_template 'show' |
|
251 | 263 | assert_not_nil assigns(:entry) |
|
252 | 264 | assert_equal 'sources', assigns(:entry).name |
|
253 | 265 | end |
|
254 | 266 | |
|
255 | 267 | def test_diff |
|
256 | 268 | assert_equal 0, @repository.changesets.count |
|
257 | 269 | @repository.fetch_changesets |
|
258 | 270 | @project.reload |
|
259 | 271 | assert_equal NUM_REV, @repository.changesets.count |
|
260 | 272 | # Full diff of changeset 2f9c0091 |
|
261 | 273 | ['inline', 'sbs'].each do |dt| |
|
262 | 274 | get :diff, |
|
263 | 275 | :id => PRJ_ID, |
|
264 | 276 | :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7', |
|
265 | 277 | :type => dt |
|
266 | 278 | assert_response :success |
|
267 | 279 | assert_template 'diff' |
|
268 | 280 | # Line 22 removed |
|
269 | 281 | assert_tag :tag => 'th', |
|
270 | 282 | :content => /22/, |
|
271 | 283 | :sibling => { :tag => 'td', |
|
272 | 284 | :attributes => { :class => /diff_out/ }, |
|
273 | 285 | :content => /def remove/ } |
|
274 | 286 | assert_tag :tag => 'h2', :content => /2f9c0091/ |
|
275 | 287 | end |
|
276 | 288 | end |
|
277 | 289 | |
|
278 | 290 | def test_diff_truncated |
|
279 | 291 | assert_equal 0, @repository.changesets.count |
|
280 | 292 | @repository.fetch_changesets |
|
281 | 293 | @project.reload |
|
282 | 294 | assert_equal NUM_REV, @repository.changesets.count |
|
283 | 295 | Setting.diff_max_lines_displayed = 5 |
|
284 | 296 | |
|
285 | 297 | # Truncated diff of changeset 2f9c0091 |
|
286 | 298 | with_cache do |
|
287 | 299 | get :diff, :id => PRJ_ID, :type => 'inline', |
|
288 | 300 | :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7' |
|
289 | 301 | assert_response :success |
|
290 | 302 | assert @response.body.include?("... This diff was truncated") |
|
291 | 303 | |
|
292 | 304 | Setting.default_language = 'fr' |
|
293 | 305 | get :diff, :id => PRJ_ID, :type => 'inline', |
|
294 | 306 | :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7' |
|
295 | 307 | assert_response :success |
|
296 | 308 | assert ! @response.body.include?("... This diff was truncated") |
|
297 | 309 | assert @response.body.include?("... Ce diff") |
|
298 | 310 | end |
|
299 | 311 | end |
|
300 | 312 | |
|
301 | 313 | def test_diff_two_revs |
|
302 | 314 | assert_equal 0, @repository.changesets.count |
|
303 | 315 | @repository.fetch_changesets |
|
304 | 316 | @project.reload |
|
305 | 317 | assert_equal NUM_REV, @repository.changesets.count |
|
306 | 318 | ['inline', 'sbs'].each do |dt| |
|
307 | 319 | get :diff, |
|
308 | 320 | :id => PRJ_ID, |
|
309 | 321 | :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1', |
|
310 | 322 | :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7', |
|
311 | 323 | :type => dt |
|
312 | 324 | assert_response :success |
|
313 | 325 | assert_template 'diff' |
|
314 | 326 | diff = assigns(:diff) |
|
315 | 327 | assert_not_nil diff |
|
316 | 328 | assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/ |
|
317 | 329 | end |
|
318 | 330 | end |
|
319 | 331 | |
|
320 | 332 | def test_diff_latin_1 |
|
321 | 333 | if @ruby19_non_utf8_pass |
|
322 | 334 | puts_ruby19_non_utf8_pass() |
|
323 | 335 | else |
|
324 | 336 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do |
|
325 | 337 | ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1| |
|
326 | 338 | ['inline', 'sbs'].each do |dt| |
|
327 | 339 | get :diff, :id => PRJ_ID, :rev => r1, :type => dt |
|
328 | 340 | assert_response :success |
|
329 | 341 | assert_template 'diff' |
|
330 | 342 | assert_tag :tag => 'thead', |
|
331 | 343 | :descendant => { |
|
332 | 344 | :tag => 'th', |
|
333 | 345 | :attributes => { :class => 'filename' } , |
|
334 | 346 | :content => /latin-1-dir\/test-#{@char_1}.txt/ , |
|
335 | 347 | }, |
|
336 | 348 | :sibling => { |
|
337 | 349 | :tag => 'tbody', |
|
338 | 350 | :descendant => { |
|
339 | 351 | :tag => 'td', |
|
340 | 352 | :attributes => { :class => /diff_in/ }, |
|
341 | 353 | :content => /test-#{@char_1}.txt/ |
|
342 | 354 | } |
|
343 | 355 | } |
|
344 | 356 | end |
|
345 | 357 | end |
|
346 | 358 | end |
|
347 | 359 | end |
|
348 | 360 | end |
|
349 | 361 | |
|
350 | 362 | def test_save_diff_type |
|
351 | 363 | @request.session[:user_id] = 1 # admin |
|
352 | 364 | user = User.find(1) |
|
353 | 365 | get :diff, |
|
354 | 366 | :id => PRJ_ID, |
|
355 | 367 | :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7' |
|
356 | 368 | assert_response :success |
|
357 | 369 | assert_template 'diff' |
|
358 | 370 | user.reload |
|
359 | 371 | assert_equal "inline", user.pref[:diff_type] |
|
360 | 372 | get :diff, |
|
361 | 373 | :id => PRJ_ID, |
|
362 | 374 | :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7', |
|
363 | 375 | :type => 'sbs' |
|
364 | 376 | assert_response :success |
|
365 | 377 | assert_template 'diff' |
|
366 | 378 | user.reload |
|
367 | 379 | assert_equal "sbs", user.pref[:diff_type] |
|
368 | 380 | end |
|
369 | 381 | |
|
370 | 382 | def test_annotate |
|
371 | 383 | get :annotate, :id => PRJ_ID, |
|
372 | 384 | :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param] |
|
373 | 385 | assert_response :success |
|
374 | 386 | assert_template 'annotate' |
|
375 | 387 | # Line 24, changeset 2f9c0091 |
|
376 | 388 | assert_tag :tag => 'th', :content => '24', |
|
377 | 389 | :sibling => { |
|
378 | 390 | :tag => 'td', |
|
379 | 391 | :child => { |
|
380 | 392 | :tag => 'a', |
|
381 | 393 | :content => /2f9c0091/ |
|
382 | 394 | } |
|
383 | 395 | } |
|
384 | 396 | assert_tag :tag => 'th', :content => '24', |
|
385 | 397 | :sibling => { :tag => 'td', :content => /jsmith/ } |
|
386 | 398 | assert_tag :tag => 'th', :content => '24', |
|
387 | 399 | :sibling => { |
|
388 | 400 | :tag => 'td', |
|
389 | 401 | :child => { |
|
390 | 402 | :tag => 'a', |
|
391 | 403 | :content => /2f9c0091/ |
|
392 | 404 | } |
|
393 | 405 | } |
|
394 | 406 | assert_tag :tag => 'th', :content => '24', |
|
395 | 407 | :sibling => { :tag => 'td', :content => /watcher =/ } |
|
396 | 408 | end |
|
397 | 409 | |
|
398 | 410 | def test_annotate_at_given_revision |
|
399 | 411 | assert_equal 0, @repository.changesets.count |
|
400 | 412 | @repository.fetch_changesets |
|
401 | 413 | @project.reload |
|
402 | 414 | assert_equal NUM_REV, @repository.changesets.count |
|
403 | 415 | get :annotate, :id => PRJ_ID, :rev => 'deff7', |
|
404 | 416 | :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param] |
|
405 | 417 | assert_response :success |
|
406 | 418 | assert_template 'annotate' |
|
407 | 419 | assert_tag :tag => 'h2', :content => /@ deff712f/ |
|
408 | 420 | end |
|
409 | 421 | |
|
410 | 422 | def test_annotate_binary_file |
|
411 | 423 | get :annotate, :id => PRJ_ID, |
|
412 | 424 | :path => repository_path_hash(['images', 'edit.png'])[:param] |
|
413 | 425 | assert_response 500 |
|
414 | 426 | assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ }, |
|
415 | 427 | :content => /cannot be annotated/ |
|
416 | 428 | end |
|
417 | 429 | |
|
418 | 430 | def test_annotate_error_when_too_big |
|
419 | 431 | with_settings :file_max_size_displayed => 1 do |
|
420 | 432 | get :annotate, :id => PRJ_ID, |
|
421 | 433 | :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param], |
|
422 | 434 | :rev => 'deff712f' |
|
423 | 435 | assert_response 500 |
|
424 | 436 | assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ }, |
|
425 | 437 | :content => /exceeds the maximum text file size/ |
|
426 | 438 | |
|
427 | 439 | get :annotate, :id => PRJ_ID, |
|
428 | 440 | :path => repository_path_hash(['README'])[:param], |
|
429 | 441 | :rev => '7234cb2' |
|
430 | 442 | assert_response :success |
|
431 | 443 | assert_template 'annotate' |
|
432 | 444 | end |
|
433 | 445 | end |
|
434 | 446 | |
|
435 | 447 | def test_annotate_latin_1 |
|
436 | 448 | if @ruby19_non_utf8_pass |
|
437 | 449 | puts_ruby19_non_utf8_pass() |
|
450 | elsif WINDOWS_PASS | |
|
451 | puts WINDOWS_SKIP_STR | |
|
438 | 452 | elsif JRUBY_SKIP |
|
439 | 453 | puts JRUBY_SKIP_STR |
|
440 | 454 | else |
|
441 | 455 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do |
|
442 | 456 | ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1| |
|
443 | 457 | get :annotate, :id => PRJ_ID, |
|
444 | 458 | :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param], |
|
445 | 459 | :rev => r1 |
|
446 | 460 | assert_tag :tag => 'th', |
|
447 | 461 | :content => '1', |
|
448 | 462 | :attributes => { :class => 'line-num' }, |
|
449 | 463 | :sibling => { :tag => 'td', |
|
450 | 464 | :content => /test-#{@char_1}.txt/ } |
|
451 | 465 | end |
|
452 | 466 | end |
|
453 | 467 | end |
|
454 | 468 | end |
|
455 | 469 | |
|
456 | 470 | def test_revision |
|
457 | 471 | assert_equal 0, @repository.changesets.count |
|
458 | 472 | @repository.fetch_changesets |
|
459 | 473 | @project.reload |
|
460 | 474 | assert_equal NUM_REV, @repository.changesets.count |
|
461 | 475 | ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r| |
|
462 | 476 | get :revision, :id => PRJ_ID, :rev => r |
|
463 | 477 | assert_response :success |
|
464 | 478 | assert_template 'revision' |
|
465 | 479 | end |
|
466 | 480 | end |
|
467 | 481 | |
|
468 | 482 | def test_empty_revision |
|
469 | 483 | assert_equal 0, @repository.changesets.count |
|
470 | 484 | @repository.fetch_changesets |
|
471 | 485 | @project.reload |
|
472 | 486 | assert_equal NUM_REV, @repository.changesets.count |
|
473 | 487 | ['', ' ', nil].each do |r| |
|
474 | 488 | get :revision, :id => PRJ_ID, :rev => r |
|
475 | 489 | assert_response 404 |
|
476 | 490 | assert_error_tag :content => /was not found/ |
|
477 | 491 | end |
|
478 | 492 | end |
|
479 | 493 | |
|
480 | 494 | def test_destroy_valid_repository |
|
481 | 495 | @request.session[:user_id] = 1 # admin |
|
482 | 496 | assert_equal 0, @repository.changesets.count |
|
483 | 497 | @repository.fetch_changesets |
|
484 | 498 | @project.reload |
|
485 | 499 | assert_equal NUM_REV, @repository.changesets.count |
|
486 | 500 | |
|
487 | 501 | assert_difference 'Repository.count', -1 do |
|
488 | 502 | delete :destroy, :id => @repository.id |
|
489 | 503 | end |
|
490 | 504 | assert_response 302 |
|
491 | 505 | @project.reload |
|
492 | 506 | assert_nil @project.repository |
|
493 | 507 | end |
|
494 | 508 | |
|
495 | 509 | def test_destroy_invalid_repository |
|
496 | 510 | @request.session[:user_id] = 1 # admin |
|
497 | 511 | @project.repository.destroy |
|
498 | 512 | @repository = Repository::Git.create!( |
|
499 | 513 | :project => @project, |
|
500 | 514 | :url => "/invalid", |
|
501 | 515 | :path_encoding => 'ISO-8859-1' |
|
502 | 516 | ) |
|
503 | 517 | @repository.fetch_changesets |
|
504 | 518 | @repository.reload |
|
505 | 519 | assert_equal 0, @repository.changesets.count |
|
506 | 520 | |
|
507 | 521 | assert_difference 'Repository.count', -1 do |
|
508 | 522 | delete :destroy, :id => @repository.id |
|
509 | 523 | end |
|
510 | 524 | assert_response 302 |
|
511 | 525 | @project.reload |
|
512 | 526 | assert_nil @project.repository |
|
513 | 527 | end |
|
514 | 528 | |
|
515 | 529 | private |
|
516 | 530 | |
|
517 | 531 | def puts_ruby19_non_utf8_pass |
|
518 | 532 | puts "TODO: This test fails in Ruby 1.9 " + |
|
519 | 533 | "and Encoding.default_external is not UTF-8. " + |
|
520 | 534 | "Current value is '#{Encoding.default_external.to_s}'" |
|
521 | 535 | end |
|
522 | 536 | else |
|
523 | 537 | puts "Git test repository NOT FOUND. Skipping functional tests !!!" |
|
524 | 538 | def test_fake; assert true end |
|
525 | 539 | end |
|
526 | 540 | |
|
527 | 541 | private |
|
528 | 542 | def with_cache(&block) |
|
529 | 543 | before = ActionController::Base.perform_caching |
|
530 | 544 | ActionController::Base.perform_caching = true |
|
531 | 545 | block.call |
|
532 | 546 | ActionController::Base.perform_caching = before |
|
533 | 547 | end |
|
534 | 548 | end |
@@ -1,531 +1,535 | |||
|
1 | 1 | # encoding: utf-8 |
|
2 | 2 | |
|
3 | 3 | require File.expand_path('../../../../../../test_helper', __FILE__) |
|
4 | 4 | begin |
|
5 | 5 | require 'mocha' |
|
6 | 6 | |
|
7 | 7 | class GitAdapterTest < ActiveSupport::TestCase |
|
8 | 8 | REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s |
|
9 | 9 | |
|
10 | 10 | FELIX_HEX = "Felix Sch\xC3\xA4fer" |
|
11 | 11 | CHAR_1_HEX = "\xc3\x9c" |
|
12 | 12 | |
|
13 | 13 | ## Ruby uses ANSI api to fork a process on Windows. |
|
14 | 14 | ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem |
|
15 | 15 | ## and these are incompatible with ASCII. |
|
16 | # WINDOWS_PASS = Redmine::Platform.mswin? | |
|
17 | WINDOWS_PASS = false | |
|
16 | ## Git for Windows (msysGit) changed internal API from ANSI to Unicode in 1.7.10 | |
|
17 | ## http://code.google.com/p/msysgit/issues/detail?id=80 | |
|
18 | ## So, Latin-1 path tests fail on Japanese Windows | |
|
19 | WINDOWS_PASS = (Redmine::Platform.mswin? && | |
|
20 | Redmine::Scm::Adapters::GitAdapter.client_version_above?([1, 7, 10])) | |
|
21 | WINDOWS_SKIP_STR = "TODO: This test fails in Git for Windows above 1.7.10" | |
|
18 | 22 | |
|
19 | 23 | ## Git, Mercurial and CVS path encodings are binary. |
|
20 | 24 | ## Subversion supports URL encoding for path. |
|
21 | 25 | ## Redmine Mercurial adapter and extension use URL encoding. |
|
22 | 26 | ## Git accepts only binary path in command line parameter. |
|
23 | 27 | ## So, there is no way to use binary command line parameter in JRuby. |
|
24 | 28 | JRUBY_SKIP = (RUBY_PLATFORM == 'java') |
|
25 | 29 | JRUBY_SKIP_STR = "TODO: This test fails in JRuby" |
|
26 | 30 | |
|
27 | 31 | if File.directory?(REPOSITORY_PATH) |
|
28 | 32 | def setup |
|
29 | 33 | adapter_class = Redmine::Scm::Adapters::GitAdapter |
|
30 | 34 | assert adapter_class |
|
31 | 35 | assert adapter_class.client_command |
|
32 | 36 | assert_equal true, adapter_class.client_available |
|
33 | 37 | assert_equal true, adapter_class.client_version_above?([1]) |
|
34 | 38 | assert_equal true, adapter_class.client_version_above?([1, 0]) |
|
35 | 39 | |
|
36 | 40 | @adapter = Redmine::Scm::Adapters::GitAdapter.new( |
|
37 | 41 | REPOSITORY_PATH, |
|
38 | 42 | nil, |
|
39 | 43 | nil, |
|
40 | 44 | nil, |
|
41 | 45 | 'ISO-8859-1' |
|
42 | 46 | ) |
|
43 | 47 | assert @adapter |
|
44 | 48 | @char_1 = CHAR_1_HEX.dup |
|
45 | 49 | if @char_1.respond_to?(:force_encoding) |
|
46 | 50 | @char_1.force_encoding('UTF-8') |
|
47 | 51 | end |
|
48 | 52 | end |
|
49 | 53 | |
|
50 | 54 | def test_scm_version |
|
51 | 55 | to_test = { "git version 1.7.3.4\n" => [1,7,3,4], |
|
52 | 56 | "1.6.1\n1.7\n1.8" => [1,6,1], |
|
53 | 57 | "1.6.2\r\n1.8.1\r\n1.9.1" => [1,6,2]} |
|
54 | 58 | to_test.each do |s, v| |
|
55 | 59 | test_scm_version_for(s, v) |
|
56 | 60 | end |
|
57 | 61 | end |
|
58 | 62 | |
|
59 | 63 | def test_branches |
|
60 | 64 | brs = [] |
|
61 | 65 | @adapter.branches.each do |b| |
|
62 | 66 | brs << b |
|
63 | 67 | end |
|
64 | 68 | assert_equal 6, brs.length |
|
65 | 69 | br_issue_8857 = brs[0] |
|
66 | 70 | assert_equal 'issue-8857', br_issue_8857.to_s |
|
67 | 71 | assert_equal '2a682156a3b6e77a8bf9cd4590e8db757f3c6c78', br_issue_8857.revision |
|
68 | 72 | assert_equal br_issue_8857.scmid, br_issue_8857.revision |
|
69 | 73 | assert_equal false, br_issue_8857.is_default |
|
70 | 74 | br_latin_1_path = brs[1] |
|
71 | 75 | assert_equal 'latin-1-path-encoding', br_latin_1_path.to_s |
|
72 | 76 | assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', br_latin_1_path.revision |
|
73 | 77 | assert_equal br_latin_1_path.scmid, br_latin_1_path.revision |
|
74 | 78 | assert_equal false, br_latin_1_path.is_default |
|
75 | 79 | br_master = brs[2] |
|
76 | 80 | assert_equal 'master', br_master.to_s |
|
77 | 81 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', br_master.revision |
|
78 | 82 | assert_equal br_master.scmid, br_master.revision |
|
79 | 83 | assert_equal false, br_master.is_default |
|
80 | 84 | br_master_20120212 = brs[3] |
|
81 | 85 | assert_equal 'master-20120212', br_master_20120212.to_s |
|
82 | 86 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', br_master_20120212.revision |
|
83 | 87 | assert_equal br_master_20120212.scmid, br_master_20120212.revision |
|
84 | 88 | assert_equal true, br_master_20120212.is_default |
|
85 | 89 | br_latin_1 = brs[-2] |
|
86 | 90 | assert_equal 'test-latin-1', br_latin_1.to_s |
|
87 | 91 | assert_equal '67e7792ce20ccae2e4bb73eed09bb397819c8834', br_latin_1.revision |
|
88 | 92 | assert_equal br_latin_1.scmid, br_latin_1.revision |
|
89 | 93 | assert_equal false, br_latin_1.is_default |
|
90 | 94 | br_test = brs[-1] |
|
91 | 95 | assert_equal 'test_branch', br_test.to_s |
|
92 | 96 | assert_equal 'fba357b886984ee71185ad2065e65fc0417d9b92', br_test.revision |
|
93 | 97 | assert_equal br_test.scmid, br_test.revision |
|
94 | 98 | assert_equal false, br_test.is_default |
|
95 | 99 | end |
|
96 | 100 | |
|
97 | 101 | def test_default_branch |
|
98 | 102 | assert_equal 'master-20120212', @adapter.default_branch |
|
99 | 103 | end |
|
100 | 104 | |
|
101 | 105 | def test_tags |
|
102 | 106 | assert_equal [ |
|
103 | 107 | "tag00.lightweight", |
|
104 | 108 | "tag01.annotated", |
|
105 | 109 | ], @adapter.tags |
|
106 | 110 | end |
|
107 | 111 | |
|
108 | 112 | def test_revisions_master_all |
|
109 | 113 | revs1 = [] |
|
110 | 114 | @adapter.revisions('', nil, "master",{}) do |rev| |
|
111 | 115 | revs1 << rev |
|
112 | 116 | end |
|
113 | 117 | assert_equal 15, revs1.length |
|
114 | 118 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[ 0].identifier |
|
115 | 119 | assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs1[-1].identifier |
|
116 | 120 | |
|
117 | 121 | revs2 = [] |
|
118 | 122 | @adapter.revisions('', nil, "master", |
|
119 | 123 | {:reverse => true}) do |rev| |
|
120 | 124 | revs2 << rev |
|
121 | 125 | end |
|
122 | 126 | assert_equal 15, revs2.length |
|
123 | 127 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs2[-1].identifier |
|
124 | 128 | assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs2[ 0].identifier |
|
125 | 129 | end |
|
126 | 130 | |
|
127 | 131 | def test_revisions_master_merged_rev |
|
128 | 132 | revs1 = [] |
|
129 | 133 | @adapter.revisions('', |
|
130 | 134 | "713f4944648826f558cf548222f813dabe7cbb04", |
|
131 | 135 | "master", |
|
132 | 136 | {:reverse => true}) do |rev| |
|
133 | 137 | revs1 << rev |
|
134 | 138 | end |
|
135 | 139 | assert_equal 8, revs1.length |
|
136 | 140 | assert_equal 'fba357b886984ee71185ad2065e65fc0417d9b92', revs1[ 0].identifier |
|
137 | 141 | assert_equal '7e61ac704deecde634b51e59daa8110435dcb3da', revs1[ 1].identifier |
|
138 | 142 | # 4a07fe31b is not a child of 713f49446 |
|
139 | 143 | assert_equal '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8', revs1[ 2].identifier |
|
140 | 144 | # Merged revision |
|
141 | 145 | assert_equal '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf', revs1[ 3].identifier |
|
142 | 146 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[-1].identifier |
|
143 | 147 | |
|
144 | 148 | revs2 = [] |
|
145 | 149 | @adapter.revisions('', |
|
146 | 150 | "fba357b886984ee71185ad2065e65fc0417d9b92", |
|
147 | 151 | "master", |
|
148 | 152 | {:reverse => true}) do |rev| |
|
149 | 153 | revs2 << rev |
|
150 | 154 | end |
|
151 | 155 | assert_equal 7, revs2.length |
|
152 | 156 | assert_equal '7e61ac704deecde634b51e59daa8110435dcb3da', revs2[ 0].identifier |
|
153 | 157 | # 4a07fe31b is not a child of fba357b8869 |
|
154 | 158 | assert_equal '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8', revs2[ 1].identifier |
|
155 | 159 | # Merged revision |
|
156 | 160 | assert_equal '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf', revs2[ 2].identifier |
|
157 | 161 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs2[-1].identifier |
|
158 | 162 | end |
|
159 | 163 | |
|
160 | 164 | def test_revisions_branch_latin_1_path_encoding_all |
|
161 | 165 | revs1 = [] |
|
162 | 166 | @adapter.revisions('', nil, "latin-1-path-encoding",{}) do |rev| |
|
163 | 167 | revs1 << rev |
|
164 | 168 | end |
|
165 | 169 | assert_equal 8, revs1.length |
|
166 | 170 | assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs1[ 0].identifier |
|
167 | 171 | assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs1[-1].identifier |
|
168 | 172 | |
|
169 | 173 | revs2 = [] |
|
170 | 174 | @adapter.revisions('', nil, "latin-1-path-encoding", |
|
171 | 175 | {:reverse => true}) do |rev| |
|
172 | 176 | revs2 << rev |
|
173 | 177 | end |
|
174 | 178 | assert_equal 8, revs2.length |
|
175 | 179 | assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs2[-1].identifier |
|
176 | 180 | assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs2[ 0].identifier |
|
177 | 181 | end |
|
178 | 182 | |
|
179 | 183 | def test_revisions_branch_latin_1_path_encoding_with_rev |
|
180 | 184 | revs1 = [] |
|
181 | 185 | @adapter.revisions('', |
|
182 | 186 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
183 | 187 | "latin-1-path-encoding", |
|
184 | 188 | {:reverse => true}) do |rev| |
|
185 | 189 | revs1 << rev |
|
186 | 190 | end |
|
187 | 191 | assert_equal 7, revs1.length |
|
188 | 192 | assert_equal '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', revs1[ 0].identifier |
|
189 | 193 | assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs1[-1].identifier |
|
190 | 194 | |
|
191 | 195 | revs2 = [] |
|
192 | 196 | @adapter.revisions('', |
|
193 | 197 | '57ca437c0acbbcb749821fdf3726a1367056d364', |
|
194 | 198 | "latin-1-path-encoding", |
|
195 | 199 | {:reverse => true}) do |rev| |
|
196 | 200 | revs2 << rev |
|
197 | 201 | end |
|
198 | 202 | assert_equal 3, revs2.length |
|
199 | 203 | assert_equal '4fc55c43bf3d3dc2efb66145365ddc17639ce81e', revs2[ 0].identifier |
|
200 | 204 | assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs2[-1].identifier |
|
201 | 205 | end |
|
202 | 206 | |
|
203 | 207 | def test_revisions_invalid_rev |
|
204 | 208 | assert_equal [], @adapter.revisions('', '1234abcd', "master") |
|
205 | 209 | assert_raise Redmine::Scm::Adapters::CommandFailed do |
|
206 | 210 | revs1 = [] |
|
207 | 211 | @adapter.revisions('', |
|
208 | 212 | '1234abcd', |
|
209 | 213 | "master", |
|
210 | 214 | {:reverse => true}) do |rev| |
|
211 | 215 | revs1 << rev |
|
212 | 216 | end |
|
213 | 217 | end |
|
214 | 218 | end |
|
215 | 219 | |
|
216 | 220 | def test_revisions_includes_master_two_revs |
|
217 | 221 | revs1 = [] |
|
218 | 222 | @adapter.revisions('', nil, nil, |
|
219 | 223 | {:reverse => true, |
|
220 | 224 | :includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c'], |
|
221 | 225 | :excludes => ['4f26664364207fa8b1af9f8722647ab2d4ac5d43']}) do |rev| |
|
222 | 226 | revs1 << rev |
|
223 | 227 | end |
|
224 | 228 | assert_equal 2, revs1.length |
|
225 | 229 | assert_equal 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b', revs1[ 0].identifier |
|
226 | 230 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[-1].identifier |
|
227 | 231 | end |
|
228 | 232 | |
|
229 | 233 | def test_revisions_includes_master_two_revs_from_origin |
|
230 | 234 | revs1 = [] |
|
231 | 235 | @adapter.revisions('', nil, nil, |
|
232 | 236 | {:reverse => true, |
|
233 | 237 | :includes => ['899a15dba03a3b350b89c3f537e4bbe02a03cdc9'], |
|
234 | 238 | :excludes => []}) do |rev| |
|
235 | 239 | revs1 << rev |
|
236 | 240 | end |
|
237 | 241 | assert_equal 2, revs1.length |
|
238 | 242 | assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs1[ 0].identifier |
|
239 | 243 | assert_equal '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', revs1[ 1].identifier |
|
240 | 244 | end |
|
241 | 245 | |
|
242 | 246 | def test_revisions_includes_merged_revs |
|
243 | 247 | revs1 = [] |
|
244 | 248 | @adapter.revisions('', nil, nil, |
|
245 | 249 | {:reverse => true, |
|
246 | 250 | :includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c'], |
|
247 | 251 | :excludes => ['fba357b886984ee71185ad2065e65fc0417d9b92']}) do |rev| |
|
248 | 252 | revs1 << rev |
|
249 | 253 | end |
|
250 | 254 | assert_equal 7, revs1.length |
|
251 | 255 | assert_equal '7e61ac704deecde634b51e59daa8110435dcb3da', revs1[ 0].identifier |
|
252 | 256 | assert_equal '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8', revs1[ 1].identifier |
|
253 | 257 | assert_equal '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf', revs1[ 2].identifier |
|
254 | 258 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[-1].identifier |
|
255 | 259 | end |
|
256 | 260 | |
|
257 | 261 | def test_revisions_includes_two_heads |
|
258 | 262 | revs1 = [] |
|
259 | 263 | @adapter.revisions('', nil, nil, |
|
260 | 264 | {:reverse => true, |
|
261 | 265 | :includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', |
|
262 | 266 | '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127'], |
|
263 | 267 | :excludes => ['4f26664364207fa8b1af9f8722647ab2d4ac5d43', |
|
264 | 268 | '4fc55c43bf3d3dc2efb66145365ddc17639ce81e']}) do |rev| |
|
265 | 269 | revs1 << rev |
|
266 | 270 | end |
|
267 | 271 | assert_equal 4, revs1.length |
|
268 | 272 | assert_equal 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b', revs1[ 0].identifier |
|
269 | 273 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[ 1].identifier |
|
270 | 274 | assert_equal '64f1f3e89ad1cb57976ff0ad99a107012ba3481d', revs1[-2].identifier |
|
271 | 275 | assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs1[-1].identifier |
|
272 | 276 | end |
|
273 | 277 | |
|
274 | 278 | def test_revisions_disjointed_histories_revisions |
|
275 | 279 | revs1 = [] |
|
276 | 280 | @adapter.revisions('', nil, nil, |
|
277 | 281 | {:reverse => true, |
|
278 | 282 | :includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', |
|
279 | 283 | '92397af84d22f27389c822848ecd5b463c181583'], |
|
280 | 284 | :excludes => ['95488a44bc25f7d1f97d775a31359539ff333a63', |
|
281 | 285 | '4f26664364207fa8b1af9f8722647ab2d4ac5d43'] }) do |rev| |
|
282 | 286 | revs1 << rev |
|
283 | 287 | end |
|
284 | 288 | assert_equal 4, revs1.length |
|
285 | 289 | assert_equal 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b', revs1[ 0].identifier |
|
286 | 290 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[ 1].identifier |
|
287 | 291 | assert_equal 'bc201c95999c4f10d018b0aa03b541cd6a2ff0ee', revs1[-2].identifier |
|
288 | 292 | assert_equal '92397af84d22f27389c822848ecd5b463c181583', revs1[-1].identifier |
|
289 | 293 | end |
|
290 | 294 | |
|
291 | 295 | def test_revisions_invalid_rev_excludes |
|
292 | 296 | assert_equal [], |
|
293 | 297 | @adapter.revisions('', nil, nil, |
|
294 | 298 | {:reverse => true, |
|
295 | 299 | :includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c'], |
|
296 | 300 | :excludes => ['0123abcd4567']}) |
|
297 | 301 | assert_raise Redmine::Scm::Adapters::CommandFailed do |
|
298 | 302 | revs1 = [] |
|
299 | 303 | @adapter.revisions('', nil, nil, |
|
300 | 304 | {:reverse => true, |
|
301 | 305 | :includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c'], |
|
302 | 306 | :excludes => ['0123abcd4567']}) do |rev| |
|
303 | 307 | revs1 << rev |
|
304 | 308 | end |
|
305 | 309 | end |
|
306 | 310 | end |
|
307 | 311 | |
|
308 | 312 | def test_getting_revisions_with_spaces_in_filename |
|
309 | 313 | assert_equal 1, @adapter.revisions("filemane with spaces.txt", |
|
310 | 314 | nil, "master").length |
|
311 | 315 | end |
|
312 | 316 | |
|
313 | 317 | def test_parents |
|
314 | 318 | revs1 = [] |
|
315 | 319 | @adapter.revisions('', |
|
316 | 320 | nil, |
|
317 | 321 | "master", |
|
318 | 322 | {:reverse => true}) do |rev| |
|
319 | 323 | revs1 << rev |
|
320 | 324 | end |
|
321 | 325 | assert_equal 15, revs1.length |
|
322 | 326 | assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", |
|
323 | 327 | revs1[0].identifier |
|
324 | 328 | assert_equal nil, revs1[0].parents |
|
325 | 329 | assert_equal "899a15dba03a3b350b89c3f537e4bbe02a03cdc9", |
|
326 | 330 | revs1[1].identifier |
|
327 | 331 | assert_equal 1, revs1[1].parents.length |
|
328 | 332 | assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", |
|
329 | 333 | revs1[1].parents[0] |
|
330 | 334 | assert_equal "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf", |
|
331 | 335 | revs1[10].identifier |
|
332 | 336 | assert_equal 2, revs1[10].parents.length |
|
333 | 337 | assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", |
|
334 | 338 | revs1[10].parents[0] |
|
335 | 339 | assert_equal "7e61ac704deecde634b51e59daa8110435dcb3da", |
|
336 | 340 | revs1[10].parents[1] |
|
337 | 341 | end |
|
338 | 342 | |
|
339 | 343 | def test_getting_revisions_with_leading_and_trailing_spaces_in_filename |
|
340 | 344 | assert_equal " filename with a leading space.txt ", |
|
341 | 345 | @adapter.revisions(" filename with a leading space.txt ", |
|
342 | 346 | nil, "master")[0].paths[0][:path] |
|
343 | 347 | end |
|
344 | 348 | |
|
345 | 349 | def test_getting_entries_with_leading_and_trailing_spaces_in_filename |
|
346 | 350 | assert_equal " filename with a leading space.txt ", |
|
347 | 351 | @adapter.entries('', |
|
348 | 352 | '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c')[3].name |
|
349 | 353 | end |
|
350 | 354 | |
|
351 | 355 | def test_annotate |
|
352 | 356 | annotate = @adapter.annotate('sources/watchers_controller.rb') |
|
353 | 357 | assert_kind_of Redmine::Scm::Adapters::Annotate, annotate |
|
354 | 358 | assert_equal 41, annotate.lines.size |
|
355 | 359 | assert_equal "# This program is free software; you can redistribute it and/or", |
|
356 | 360 | annotate.lines[4].strip |
|
357 | 361 | assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", |
|
358 | 362 | annotate.revisions[4].identifier |
|
359 | 363 | assert_equal "jsmith", annotate.revisions[4].author |
|
360 | 364 | end |
|
361 | 365 | |
|
362 | 366 | def test_annotate_moved_file |
|
363 | 367 | annotate = @adapter.annotate('renamed_test.txt') |
|
364 | 368 | assert_kind_of Redmine::Scm::Adapters::Annotate, annotate |
|
365 | 369 | assert_equal 2, annotate.lines.size |
|
366 | 370 | end |
|
367 | 371 | |
|
368 | 372 | def test_last_rev |
|
369 | 373 | last_rev = @adapter.lastrev("README", |
|
370 | 374 | "4f26664364207fa8b1af9f8722647ab2d4ac5d43") |
|
371 | 375 | assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", last_rev.scmid |
|
372 | 376 | assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", last_rev.identifier |
|
373 | 377 | assert_equal "Adam Soltys <asoltys@gmail.com>", last_rev.author |
|
374 | 378 | assert_equal "2009-06-24 05:27:38".to_time, last_rev.time |
|
375 | 379 | end |
|
376 | 380 | |
|
377 | 381 | def test_last_rev_with_spaces_in_filename |
|
378 | 382 | last_rev = @adapter.lastrev("filemane with spaces.txt", |
|
379 | 383 | "ed5bb786bbda2dee66a2d50faf51429dbc043a7b") |
|
380 | 384 | str_felix_hex = FELIX_HEX.dup |
|
381 | 385 | last_rev_author = last_rev.author |
|
382 | 386 | if last_rev_author.respond_to?(:force_encoding) |
|
383 | 387 | last_rev_author.force_encoding('UTF-8') |
|
384 | 388 | end |
|
385 | 389 | assert_equal "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", last_rev.scmid |
|
386 | 390 | assert_equal "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", last_rev.identifier |
|
387 | 391 | assert_equal "#{str_felix_hex} <felix@fachschaften.org>", |
|
388 | 392 | last_rev.author |
|
389 | 393 | assert_equal "2010-09-18 19:59:46".to_time, last_rev.time |
|
390 | 394 | end |
|
391 | 395 | |
|
392 | 396 | def test_latin_1_path |
|
393 | 397 | if WINDOWS_PASS |
|
394 | # | |
|
398 | puts WINDOWS_SKIP_STR | |
|
395 | 399 | elsif JRUBY_SKIP |
|
396 | 400 | puts JRUBY_SKIP_STR |
|
397 | 401 | else |
|
398 | 402 | p2 = "latin-1-dir/test-#{@char_1}-2.txt" |
|
399 | 403 | ['4fc55c43bf3d3dc2efb66145365ddc17639ce81e', '4fc55c43bf3'].each do |r1| |
|
400 | 404 | assert @adapter.diff(p2, r1) |
|
401 | 405 | assert @adapter.cat(p2, r1) |
|
402 | 406 | assert_equal 1, @adapter.annotate(p2, r1).lines.length |
|
403 | 407 | ['64f1f3e89ad1cb57976ff0ad99a107012ba3481d', '64f1f3e89ad1cb5797'].each do |r2| |
|
404 | 408 | assert @adapter.diff(p2, r1, r2) |
|
405 | 409 | end |
|
406 | 410 | end |
|
407 | 411 | end |
|
408 | 412 | end |
|
409 | 413 | |
|
410 | 414 | def test_entries_tag |
|
411 | 415 | entries1 = @adapter.entries(nil, 'tag01.annotated', |
|
412 | 416 | options = {:report_last_commit => true}) |
|
413 | 417 | assert entries1 |
|
414 | 418 | assert_equal 3, entries1.size |
|
415 | 419 | assert_equal 'sources', entries1[1].name |
|
416 | 420 | assert_equal 'sources', entries1[1].path |
|
417 | 421 | assert_equal 'dir', entries1[1].kind |
|
418 | 422 | readme = entries1[2] |
|
419 | 423 | assert_equal 'README', readme.name |
|
420 | 424 | assert_equal 'README', readme.path |
|
421 | 425 | assert_equal 'file', readme.kind |
|
422 | 426 | assert_equal 27, readme.size |
|
423 | 427 | assert_equal '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', readme.lastrev.identifier |
|
424 | 428 | assert_equal Time.gm(2007, 12, 14, 9, 24, 1), readme.lastrev.time |
|
425 | 429 | end |
|
426 | 430 | |
|
427 | 431 | def test_entries_branch |
|
428 | 432 | entries1 = @adapter.entries(nil, 'test_branch', |
|
429 | 433 | options = {:report_last_commit => true}) |
|
430 | 434 | assert entries1 |
|
431 | 435 | assert_equal 4, entries1.size |
|
432 | 436 | assert_equal 'sources', entries1[1].name |
|
433 | 437 | assert_equal 'sources', entries1[1].path |
|
434 | 438 | assert_equal 'dir', entries1[1].kind |
|
435 | 439 | readme = entries1[2] |
|
436 | 440 | assert_equal 'README', readme.name |
|
437 | 441 | assert_equal 'README', readme.path |
|
438 | 442 | assert_equal 'file', readme.kind |
|
439 | 443 | assert_equal 159, readme.size |
|
440 | 444 | assert_equal '713f4944648826f558cf548222f813dabe7cbb04', readme.lastrev.identifier |
|
441 | 445 | assert_equal Time.gm(2009, 6, 19, 4, 37, 23), readme.lastrev.time |
|
442 | 446 | end |
|
443 | 447 | |
|
444 | 448 | def test_entries_latin_1_files |
|
445 | 449 | entries1 = @adapter.entries('latin-1-dir', '64f1f3e8') |
|
446 | 450 | assert entries1 |
|
447 | 451 | assert_equal 3, entries1.size |
|
448 | 452 | f1 = entries1[1] |
|
449 | 453 | assert_equal "test-#{@char_1}-2.txt", f1.name |
|
450 | 454 | assert_equal "latin-1-dir/test-#{@char_1}-2.txt", f1.path |
|
451 | 455 | assert_equal 'file', f1.kind |
|
452 | 456 | end |
|
453 | 457 | |
|
454 | 458 | def test_entries_latin_1_dir |
|
455 | 459 | if WINDOWS_PASS |
|
456 | # | |
|
460 | puts WINDOWS_SKIP_STR | |
|
457 | 461 | elsif JRUBY_SKIP |
|
458 | 462 | puts JRUBY_SKIP_STR |
|
459 | 463 | else |
|
460 | 464 | entries1 = @adapter.entries("latin-1-dir/test-#{@char_1}-subdir", |
|
461 | 465 | '1ca7f5ed') |
|
462 | 466 | assert entries1 |
|
463 | 467 | assert_equal 3, entries1.size |
|
464 | 468 | f1 = entries1[1] |
|
465 | 469 | assert_equal "test-#{@char_1}-2.txt", f1.name |
|
466 | 470 | assert_equal "latin-1-dir/test-#{@char_1}-subdir/test-#{@char_1}-2.txt", f1.path |
|
467 | 471 | assert_equal 'file', f1.kind |
|
468 | 472 | end |
|
469 | 473 | end |
|
470 | 474 | |
|
471 | 475 | def test_path_encoding_default_utf8 |
|
472 | 476 | adpt1 = Redmine::Scm::Adapters::GitAdapter.new( |
|
473 | 477 | REPOSITORY_PATH |
|
474 | 478 | ) |
|
475 | 479 | assert_equal "UTF-8", adpt1.path_encoding |
|
476 | 480 | adpt2 = Redmine::Scm::Adapters::GitAdapter.new( |
|
477 | 481 | REPOSITORY_PATH, |
|
478 | 482 | nil, |
|
479 | 483 | nil, |
|
480 | 484 | nil, |
|
481 | 485 | "" |
|
482 | 486 | ) |
|
483 | 487 | assert_equal "UTF-8", adpt2.path_encoding |
|
484 | 488 | end |
|
485 | 489 | |
|
486 | 490 | def test_cat_path_invalid |
|
487 | 491 | assert_nil @adapter.cat('invalid') |
|
488 | 492 | end |
|
489 | 493 | |
|
490 | 494 | def test_cat_revision_invalid |
|
491 | 495 | assert @adapter.cat('README') |
|
492 | 496 | assert_nil @adapter.cat('README', '1234abcd5678') |
|
493 | 497 | end |
|
494 | 498 | |
|
495 | 499 | def test_diff_path_invalid |
|
496 | 500 | assert_equal [], @adapter.diff('invalid', '713f4944648826f5') |
|
497 | 501 | end |
|
498 | 502 | |
|
499 | 503 | def test_diff_revision_invalid |
|
500 | 504 | assert_nil @adapter.diff(nil, '1234abcd5678') |
|
501 | 505 | assert_nil @adapter.diff(nil, '713f4944648826f5', '1234abcd5678') |
|
502 | 506 | assert_nil @adapter.diff(nil, '1234abcd5678', '713f4944648826f5') |
|
503 | 507 | end |
|
504 | 508 | |
|
505 | 509 | def test_annotate_path_invalid |
|
506 | 510 | assert_nil @adapter.annotate('invalid') |
|
507 | 511 | end |
|
508 | 512 | |
|
509 | 513 | def test_annotate_revision_invalid |
|
510 | 514 | assert @adapter.annotate('README') |
|
511 | 515 | assert_nil @adapter.annotate('README', '1234abcd5678') |
|
512 | 516 | end |
|
513 | 517 | |
|
514 | 518 | private |
|
515 | 519 | |
|
516 | 520 | def test_scm_version_for(scm_command_version, version) |
|
517 | 521 | @adapter.class.expects(:scm_version_from_command_line).returns(scm_command_version) |
|
518 | 522 | assert_equal version, @adapter.class.scm_command_version |
|
519 | 523 | end |
|
520 | 524 | |
|
521 | 525 | else |
|
522 | 526 | puts "Git test repository NOT FOUND. Skipping unit tests !!!" |
|
523 | 527 | def test_fake; assert true end |
|
524 | 528 | end |
|
525 | 529 | end |
|
526 | 530 | |
|
527 | 531 | rescue LoadError |
|
528 | 532 | class GitMochaFake < ActiveSupport::TestCase |
|
529 | 533 | def test_fake; assert(false, "Requires mocha to run those tests") end |
|
530 | 534 | end |
|
531 | 535 | end |
@@ -1,556 +1,562 | |||
|
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 RepositoryGitTest < ActiveSupport::TestCase |
|
21 | 21 | fixtures :projects, :repositories, :enabled_modules, :users, :roles |
|
22 | 22 | |
|
23 | 23 | include Redmine::I18n |
|
24 | 24 | |
|
25 | 25 | REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s |
|
26 | 26 | REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin? |
|
27 | 27 | |
|
28 | 28 | NUM_REV = 28 |
|
29 | 29 | NUM_HEAD = 6 |
|
30 | 30 | |
|
31 | 31 | FELIX_HEX = "Felix Sch\xC3\xA4fer" |
|
32 | 32 | CHAR_1_HEX = "\xc3\x9c" |
|
33 | 33 | |
|
34 | 34 | ## Ruby uses ANSI api to fork a process on Windows. |
|
35 | 35 | ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem |
|
36 | 36 | ## and these are incompatible with ASCII. |
|
37 | # WINDOWS_PASS = Redmine::Platform.mswin? | |
|
38 | WINDOWS_PASS = false | |
|
37 | ## Git for Windows (msysGit) changed internal API from ANSI to Unicode in 1.7.10 | |
|
38 | ## http://code.google.com/p/msysgit/issues/detail?id=80 | |
|
39 | ## So, Latin-1 path tests fail on Japanese Windows | |
|
40 | WINDOWS_PASS = (Redmine::Platform.mswin? && | |
|
41 | Redmine::Scm::Adapters::GitAdapter.client_version_above?([1, 7, 10])) | |
|
42 | WINDOWS_SKIP_STR = "TODO: This test fails in Git for Windows above 1.7.10" | |
|
39 | 43 | |
|
40 | 44 | ## Git, Mercurial and CVS path encodings are binary. |
|
41 | 45 | ## Subversion supports URL encoding for path. |
|
42 | 46 | ## Redmine Mercurial adapter and extension use URL encoding. |
|
43 | 47 | ## Git accepts only binary path in command line parameter. |
|
44 | 48 | ## So, there is no way to use binary command line parameter in JRuby. |
|
45 | 49 | JRUBY_SKIP = (RUBY_PLATFORM == 'java') |
|
46 | 50 | JRUBY_SKIP_STR = "TODO: This test fails in JRuby" |
|
47 | 51 | |
|
48 | 52 | def setup |
|
49 | 53 | @project = Project.find(3) |
|
50 | 54 | @repository = Repository::Git.create( |
|
51 | 55 | :project => @project, |
|
52 | 56 | :url => REPOSITORY_PATH, |
|
53 | 57 | :path_encoding => 'ISO-8859-1' |
|
54 | 58 | ) |
|
55 | 59 | assert @repository |
|
56 | 60 | @char_1 = CHAR_1_HEX.dup |
|
57 | 61 | if @char_1.respond_to?(:force_encoding) |
|
58 | 62 | @char_1.force_encoding('UTF-8') |
|
59 | 63 | end |
|
60 | 64 | end |
|
61 | 65 | |
|
62 | 66 | def test_blank_path_to_repository_error_message |
|
63 | 67 | set_language_if_valid 'en' |
|
64 | 68 | repo = Repository::Git.new( |
|
65 | 69 | :project => @project, |
|
66 | 70 | :identifier => 'test' |
|
67 | 71 | ) |
|
68 | 72 | assert !repo.save |
|
69 | 73 | assert_include "Path to repository can't be blank", |
|
70 | 74 | repo.errors.full_messages |
|
71 | 75 | end |
|
72 | 76 | |
|
73 | 77 | def test_blank_path_to_repository_error_message_fr |
|
74 | 78 | set_language_if_valid 'fr' |
|
75 | 79 | str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)" |
|
76 | 80 | str.force_encoding('UTF-8') if str.respond_to?(:force_encoding) |
|
77 | 81 | repo = Repository::Git.new( |
|
78 | 82 | :project => @project, |
|
79 | 83 | :url => "", |
|
80 | 84 | :identifier => 'test', |
|
81 | 85 | :path_encoding => '' |
|
82 | 86 | ) |
|
83 | 87 | assert !repo.save |
|
84 | 88 | assert_include str, repo.errors.full_messages |
|
85 | 89 | end |
|
86 | 90 | |
|
87 | 91 | if File.directory?(REPOSITORY_PATH) |
|
88 | 92 | def test_scm_available |
|
89 | 93 | klass = Repository::Git |
|
90 | 94 | assert_equal "Git", klass.scm_name |
|
91 | 95 | assert klass.scm_adapter_class |
|
92 | 96 | assert_not_equal "", klass.scm_command |
|
93 | 97 | assert_equal true, klass.scm_available |
|
94 | 98 | end |
|
95 | 99 | |
|
96 | 100 | def test_fetch_changesets_from_scratch |
|
97 | 101 | assert_nil @repository.extra_info |
|
98 | 102 | |
|
99 | 103 | assert_equal 0, @repository.changesets.count |
|
100 | 104 | @repository.fetch_changesets |
|
101 | 105 | @project.reload |
|
102 | 106 | |
|
103 | 107 | assert_equal NUM_REV, @repository.changesets.count |
|
104 | 108 | assert_equal 39, @repository.filechanges.count |
|
105 | 109 | |
|
106 | 110 | commit = @repository.changesets.find_by_revision("7234cb2750b63f47bff735edc50a1c0a433c2518") |
|
107 | 111 | assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.scmid |
|
108 | 112 | assert_equal "Initial import.\nThe repository contains 3 files.", commit.comments |
|
109 | 113 | assert_equal "jsmith <jsmith@foo.bar>", commit.committer |
|
110 | 114 | assert_equal User.find_by_login('jsmith'), commit.user |
|
111 | 115 | # TODO: add a commit with commit time <> author time to the test repository |
|
112 | 116 | assert_equal "2007-12-14 09:22:52".to_time, commit.committed_on |
|
113 | 117 | assert_equal "2007-12-14".to_date, commit.commit_date |
|
114 | 118 | assert_equal 3, commit.filechanges.count |
|
115 | 119 | change = commit.filechanges.sort_by(&:path).first |
|
116 | 120 | assert_equal "README", change.path |
|
117 | 121 | assert_equal nil, change.from_path |
|
118 | 122 | assert_equal "A", change.action |
|
119 | 123 | |
|
120 | 124 | assert_equal NUM_HEAD, @repository.extra_info["heads"].size |
|
121 | 125 | end |
|
122 | 126 | |
|
123 | 127 | def test_fetch_changesets_incremental |
|
124 | 128 | assert_equal 0, @repository.changesets.count |
|
125 | 129 | @repository.fetch_changesets |
|
126 | 130 | @project.reload |
|
127 | 131 | assert_equal NUM_REV, @repository.changesets.count |
|
128 | 132 | extra_info_heads = @repository.extra_info["heads"].dup |
|
129 | 133 | assert_equal NUM_HEAD, extra_info_heads.size |
|
130 | 134 | extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" } |
|
131 | 135 | assert_equal 4, extra_info_heads.size |
|
132 | 136 | |
|
133 | 137 | del_revs = [ |
|
134 | 138 | "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c", |
|
135 | 139 | "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", |
|
136 | 140 | "4f26664364207fa8b1af9f8722647ab2d4ac5d43", |
|
137 | 141 | "deff712f05a90d96edbd70facc47d944be5897e3", |
|
138 | 142 | "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf", |
|
139 | 143 | "7e61ac704deecde634b51e59daa8110435dcb3da", |
|
140 | 144 | ] |
|
141 | 145 | @repository.changesets.each do |rev| |
|
142 | 146 | rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s } |
|
143 | 147 | end |
|
144 | 148 | @project.reload |
|
145 | 149 | cs1 = @repository.changesets |
|
146 | 150 | assert_equal NUM_REV - 6, cs1.count |
|
147 | 151 | extra_info_heads << "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8" |
|
148 | 152 | h = {} |
|
149 | 153 | h["heads"] = extra_info_heads |
|
150 | 154 | @repository.merge_extra_info(h) |
|
151 | 155 | @repository.save |
|
152 | 156 | @project.reload |
|
153 | 157 | assert @repository.extra_info["heads"].index("4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8") |
|
154 | 158 | @repository.fetch_changesets |
|
155 | 159 | @project.reload |
|
156 | 160 | assert_equal NUM_REV, @repository.changesets.count |
|
157 | 161 | assert_equal NUM_HEAD, @repository.extra_info["heads"].size |
|
158 | 162 | assert @repository.extra_info["heads"].index("83ca5fd546063a3c7dc2e568ba3355661a9e2b2c") |
|
159 | 163 | end |
|
160 | 164 | |
|
161 | 165 | def test_fetch_changesets_history_editing |
|
162 | 166 | assert_equal 0, @repository.changesets.count |
|
163 | 167 | @repository.fetch_changesets |
|
164 | 168 | @project.reload |
|
165 | 169 | assert_equal NUM_REV, @repository.changesets.count |
|
166 | 170 | extra_info_heads = @repository.extra_info["heads"].dup |
|
167 | 171 | assert_equal NUM_HEAD, extra_info_heads.size |
|
168 | 172 | extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" } |
|
169 | 173 | assert_equal 4, extra_info_heads.size |
|
170 | 174 | |
|
171 | 175 | del_revs = [ |
|
172 | 176 | "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c", |
|
173 | 177 | "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", |
|
174 | 178 | "4f26664364207fa8b1af9f8722647ab2d4ac5d43", |
|
175 | 179 | "deff712f05a90d96edbd70facc47d944be5897e3", |
|
176 | 180 | "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf", |
|
177 | 181 | "7e61ac704deecde634b51e59daa8110435dcb3da", |
|
178 | 182 | ] |
|
179 | 183 | @repository.changesets.each do |rev| |
|
180 | 184 | rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s } |
|
181 | 185 | end |
|
182 | 186 | @project.reload |
|
183 | 187 | assert_equal NUM_REV - 6, @repository.changesets.count |
|
184 | 188 | |
|
185 | 189 | c = Changeset.new(:repository => @repository, |
|
186 | 190 | :committed_on => Time.now, |
|
187 | 191 | :revision => "abcd1234efgh", |
|
188 | 192 | :scmid => "abcd1234efgh", |
|
189 | 193 | :comments => 'test') |
|
190 | 194 | assert c.save |
|
191 | 195 | @project.reload |
|
192 | 196 | assert_equal NUM_REV - 5, @repository.changesets.count |
|
193 | 197 | |
|
194 | 198 | extra_info_heads << "1234abcd5678" |
|
195 | 199 | h = {} |
|
196 | 200 | h["heads"] = extra_info_heads |
|
197 | 201 | @repository.merge_extra_info(h) |
|
198 | 202 | @repository.save |
|
199 | 203 | @project.reload |
|
200 | 204 | h1 = @repository.extra_info["heads"].dup |
|
201 | 205 | assert h1.index("1234abcd5678") |
|
202 | 206 | assert_equal 5, h1.size |
|
203 | 207 | |
|
204 | 208 | @repository.fetch_changesets |
|
205 | 209 | @project.reload |
|
206 | 210 | assert_equal NUM_REV - 5, @repository.changesets.count |
|
207 | 211 | h2 = @repository.extra_info["heads"].dup |
|
208 | 212 | assert_equal h1, h2 |
|
209 | 213 | end |
|
210 | 214 | |
|
211 | 215 | def test_parents |
|
212 | 216 | assert_equal 0, @repository.changesets.count |
|
213 | 217 | @repository.fetch_changesets |
|
214 | 218 | @project.reload |
|
215 | 219 | assert_equal NUM_REV, @repository.changesets.count |
|
216 | 220 | r1 = @repository.find_changeset_by_name("7234cb2750b63") |
|
217 | 221 | assert_equal [], r1.parents |
|
218 | 222 | r2 = @repository.find_changeset_by_name("899a15dba03a3") |
|
219 | 223 | assert_equal 1, r2.parents.length |
|
220 | 224 | assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", |
|
221 | 225 | r2.parents[0].identifier |
|
222 | 226 | r3 = @repository.find_changeset_by_name("32ae898b720c2") |
|
223 | 227 | assert_equal 2, r3.parents.length |
|
224 | 228 | r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort |
|
225 | 229 | assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", r4[0] |
|
226 | 230 | assert_equal "7e61ac704deecde634b51e59daa8110435dcb3da", r4[1] |
|
227 | 231 | end |
|
228 | 232 | |
|
229 | 233 | def test_db_consistent_ordering_init |
|
230 | 234 | assert_nil @repository.extra_info |
|
231 | 235 | assert_equal 0, @repository.changesets.count |
|
232 | 236 | @repository.fetch_changesets |
|
233 | 237 | @project.reload |
|
234 | 238 | assert_equal 1, @repository.extra_info["db_consistent"]["ordering"] |
|
235 | 239 | end |
|
236 | 240 | |
|
237 | 241 | def test_db_consistent_ordering_before_1_2 |
|
238 | 242 | assert_nil @repository.extra_info |
|
239 | 243 | assert_equal 0, @repository.changesets.count |
|
240 | 244 | @repository.fetch_changesets |
|
241 | 245 | @project.reload |
|
242 | 246 | assert_equal NUM_REV, @repository.changesets.count |
|
243 | 247 | assert_not_nil @repository.extra_info |
|
244 | 248 | h = {} |
|
245 | 249 | h["heads"] = [] |
|
246 | 250 | h["branches"] = {} |
|
247 | 251 | h["db_consistent"] = {} |
|
248 | 252 | @repository.merge_extra_info(h) |
|
249 | 253 | @repository.save |
|
250 | 254 | assert_equal NUM_REV, @repository.changesets.count |
|
251 | 255 | @repository.fetch_changesets |
|
252 | 256 | @project.reload |
|
253 | 257 | assert_equal 0, @repository.extra_info["db_consistent"]["ordering"] |
|
254 | 258 | |
|
255 | 259 | extra_info_heads = @repository.extra_info["heads"].dup |
|
256 | 260 | extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" } |
|
257 | 261 | del_revs = [ |
|
258 | 262 | "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c", |
|
259 | 263 | "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", |
|
260 | 264 | "4f26664364207fa8b1af9f8722647ab2d4ac5d43", |
|
261 | 265 | "deff712f05a90d96edbd70facc47d944be5897e3", |
|
262 | 266 | "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf", |
|
263 | 267 | "7e61ac704deecde634b51e59daa8110435dcb3da", |
|
264 | 268 | ] |
|
265 | 269 | @repository.changesets.each do |rev| |
|
266 | 270 | rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s } |
|
267 | 271 | end |
|
268 | 272 | @project.reload |
|
269 | 273 | cs1 = @repository.changesets |
|
270 | 274 | assert_equal NUM_REV - 6, cs1.count |
|
271 | 275 | assert_equal 0, @repository.extra_info["db_consistent"]["ordering"] |
|
272 | 276 | |
|
273 | 277 | extra_info_heads << "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8" |
|
274 | 278 | h = {} |
|
275 | 279 | h["heads"] = extra_info_heads |
|
276 | 280 | @repository.merge_extra_info(h) |
|
277 | 281 | @repository.save |
|
278 | 282 | @project.reload |
|
279 | 283 | assert @repository.extra_info["heads"].index("4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8") |
|
280 | 284 | @repository.fetch_changesets |
|
281 | 285 | @project.reload |
|
282 | 286 | assert_equal NUM_REV, @repository.changesets.count |
|
283 | 287 | assert_equal NUM_HEAD, @repository.extra_info["heads"].size |
|
284 | 288 | |
|
285 | 289 | assert_equal 0, @repository.extra_info["db_consistent"]["ordering"] |
|
286 | 290 | end |
|
287 | 291 | |
|
288 | 292 | def test_heads_from_branches_hash |
|
289 | 293 | assert_nil @repository.extra_info |
|
290 | 294 | assert_equal 0, @repository.changesets.count |
|
291 | 295 | assert_equal [], @repository.heads_from_branches_hash |
|
292 | 296 | h = {} |
|
293 | 297 | h["branches"] = {} |
|
294 | 298 | h["branches"]["test1"] = {} |
|
295 | 299 | h["branches"]["test1"]["last_scmid"] = "1234abcd" |
|
296 | 300 | h["branches"]["test2"] = {} |
|
297 | 301 | h["branches"]["test2"]["last_scmid"] = "abcd1234" |
|
298 | 302 | @repository.merge_extra_info(h) |
|
299 | 303 | @repository.save |
|
300 | 304 | @project.reload |
|
301 | 305 | assert_equal ["1234abcd", "abcd1234"], @repository.heads_from_branches_hash.sort |
|
302 | 306 | end |
|
303 | 307 | |
|
304 | 308 | def test_latest_changesets |
|
305 | 309 | assert_equal 0, @repository.changesets.count |
|
306 | 310 | @repository.fetch_changesets |
|
307 | 311 | @project.reload |
|
308 | 312 | assert_equal NUM_REV, @repository.changesets.count |
|
309 | 313 | # with limit |
|
310 | 314 | changesets = @repository.latest_changesets('', 'master', 2) |
|
311 | 315 | assert_equal 2, changesets.size |
|
312 | 316 | |
|
313 | 317 | # with path |
|
314 | 318 | changesets = @repository.latest_changesets('images', 'master') |
|
315 | 319 | assert_equal [ |
|
316 | 320 | 'deff712f05a90d96edbd70facc47d944be5897e3', |
|
317 | 321 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
318 | 322 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
319 | 323 | ], changesets.collect(&:revision) |
|
320 | 324 | |
|
321 | 325 | changesets = @repository.latest_changesets('README', nil) |
|
322 | 326 | assert_equal [ |
|
323 | 327 | '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf', |
|
324 | 328 | '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8', |
|
325 | 329 | '713f4944648826f558cf548222f813dabe7cbb04', |
|
326 | 330 | '61b685fbe55ab05b5ac68402d5720c1a6ac973d1', |
|
327 | 331 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
328 | 332 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
329 | 333 | ], changesets.collect(&:revision) |
|
330 | 334 | |
|
331 | 335 | # with path, revision and limit |
|
332 | 336 | changesets = @repository.latest_changesets('images', '899a15dba') |
|
333 | 337 | assert_equal [ |
|
334 | 338 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
335 | 339 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
336 | 340 | ], changesets.collect(&:revision) |
|
337 | 341 | |
|
338 | 342 | changesets = @repository.latest_changesets('images', '899a15dba', 1) |
|
339 | 343 | assert_equal [ |
|
340 | 344 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
341 | 345 | ], changesets.collect(&:revision) |
|
342 | 346 | |
|
343 | 347 | changesets = @repository.latest_changesets('README', '899a15dba') |
|
344 | 348 | assert_equal [ |
|
345 | 349 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
346 | 350 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
347 | 351 | ], changesets.collect(&:revision) |
|
348 | 352 | |
|
349 | 353 | changesets = @repository.latest_changesets('README', '899a15dba', 1) |
|
350 | 354 | assert_equal [ |
|
351 | 355 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
352 | 356 | ], changesets.collect(&:revision) |
|
353 | 357 | |
|
354 | 358 | # with path, tag and limit |
|
355 | 359 | changesets = @repository.latest_changesets('images', 'tag01.annotated') |
|
356 | 360 | assert_equal [ |
|
357 | 361 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
358 | 362 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
359 | 363 | ], changesets.collect(&:revision) |
|
360 | 364 | |
|
361 | 365 | changesets = @repository.latest_changesets('images', 'tag01.annotated', 1) |
|
362 | 366 | assert_equal [ |
|
363 | 367 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
364 | 368 | ], changesets.collect(&:revision) |
|
365 | 369 | |
|
366 | 370 | changesets = @repository.latest_changesets('README', 'tag01.annotated') |
|
367 | 371 | assert_equal [ |
|
368 | 372 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
369 | 373 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
370 | 374 | ], changesets.collect(&:revision) |
|
371 | 375 | |
|
372 | 376 | changesets = @repository.latest_changesets('README', 'tag01.annotated', 1) |
|
373 | 377 | assert_equal [ |
|
374 | 378 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
375 | 379 | ], changesets.collect(&:revision) |
|
376 | 380 | |
|
377 | 381 | # with path, branch and limit |
|
378 | 382 | changesets = @repository.latest_changesets('images', 'test_branch') |
|
379 | 383 | assert_equal [ |
|
380 | 384 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
381 | 385 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
382 | 386 | ], changesets.collect(&:revision) |
|
383 | 387 | |
|
384 | 388 | changesets = @repository.latest_changesets('images', 'test_branch', 1) |
|
385 | 389 | assert_equal [ |
|
386 | 390 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
387 | 391 | ], changesets.collect(&:revision) |
|
388 | 392 | |
|
389 | 393 | changesets = @repository.latest_changesets('README', 'test_branch') |
|
390 | 394 | assert_equal [ |
|
391 | 395 | '713f4944648826f558cf548222f813dabe7cbb04', |
|
392 | 396 | '61b685fbe55ab05b5ac68402d5720c1a6ac973d1', |
|
393 | 397 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
394 | 398 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
395 | 399 | ], changesets.collect(&:revision) |
|
396 | 400 | |
|
397 | 401 | changesets = @repository.latest_changesets('README', 'test_branch', 2) |
|
398 | 402 | assert_equal [ |
|
399 | 403 | '713f4944648826f558cf548222f813dabe7cbb04', |
|
400 | 404 | '61b685fbe55ab05b5ac68402d5720c1a6ac973d1', |
|
401 | 405 | ], changesets.collect(&:revision) |
|
402 | 406 | |
|
403 | if JRUBY_SKIP | |
|
407 | if WINDOWS_PASS | |
|
408 | puts WINDOWS_SKIP_STR | |
|
409 | elsif JRUBY_SKIP | |
|
404 | 410 | puts JRUBY_SKIP_STR |
|
405 | 411 | else |
|
406 | 412 | # latin-1 encoding path |
|
407 | 413 | changesets = @repository.latest_changesets( |
|
408 | 414 | "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89') |
|
409 | 415 | assert_equal [ |
|
410 | 416 | '64f1f3e89ad1cb57976ff0ad99a107012ba3481d', |
|
411 | 417 | '4fc55c43bf3d3dc2efb66145365ddc17639ce81e', |
|
412 | 418 | ], changesets.collect(&:revision) |
|
413 | 419 | |
|
414 | 420 | changesets = @repository.latest_changesets( |
|
415 | 421 | "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89', 1) |
|
416 | 422 | assert_equal [ |
|
417 | 423 | '64f1f3e89ad1cb57976ff0ad99a107012ba3481d', |
|
418 | 424 | ], changesets.collect(&:revision) |
|
419 | 425 | end |
|
420 | 426 | end |
|
421 | 427 | |
|
422 | 428 | def test_latest_changesets_latin_1_dir |
|
423 | 429 | if WINDOWS_PASS |
|
424 | # | |
|
430 | puts WINDOWS_SKIP_STR | |
|
425 | 431 | elsif JRUBY_SKIP |
|
426 | 432 | puts JRUBY_SKIP_STR |
|
427 | 433 | else |
|
428 | 434 | assert_equal 0, @repository.changesets.count |
|
429 | 435 | @repository.fetch_changesets |
|
430 | 436 | @project.reload |
|
431 | 437 | assert_equal NUM_REV, @repository.changesets.count |
|
432 | 438 | changesets = @repository.latest_changesets( |
|
433 | 439 | "latin-1-dir/test-#{@char_1}-subdir", '1ca7f5ed') |
|
434 | 440 | assert_equal [ |
|
435 | 441 | '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', |
|
436 | 442 | ], changesets.collect(&:revision) |
|
437 | 443 | end |
|
438 | 444 | end |
|
439 | 445 | |
|
440 | 446 | def test_find_changeset_by_name |
|
441 | 447 | assert_equal 0, @repository.changesets.count |
|
442 | 448 | @repository.fetch_changesets |
|
443 | 449 | @project.reload |
|
444 | 450 | assert_equal NUM_REV, @repository.changesets.count |
|
445 | 451 | ['7234cb2750b63f47bff735edc50a1c0a433c2518', '7234cb2750b'].each do |r| |
|
446 | 452 | assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
447 | 453 | @repository.find_changeset_by_name(r).revision |
|
448 | 454 | end |
|
449 | 455 | end |
|
450 | 456 | |
|
451 | 457 | def test_find_changeset_by_empty_name |
|
452 | 458 | assert_equal 0, @repository.changesets.count |
|
453 | 459 | @repository.fetch_changesets |
|
454 | 460 | @project.reload |
|
455 | 461 | assert_equal NUM_REV, @repository.changesets.count |
|
456 | 462 | ['', ' ', nil].each do |r| |
|
457 | 463 | assert_nil @repository.find_changeset_by_name(r) |
|
458 | 464 | end |
|
459 | 465 | end |
|
460 | 466 | |
|
461 | 467 | def test_identifier |
|
462 | 468 | assert_equal 0, @repository.changesets.count |
|
463 | 469 | @repository.fetch_changesets |
|
464 | 470 | @project.reload |
|
465 | 471 | assert_equal NUM_REV, @repository.changesets.count |
|
466 | 472 | c = @repository.changesets.find_by_revision( |
|
467 | 473 | '7234cb2750b63f47bff735edc50a1c0a433c2518') |
|
468 | 474 | assert_equal c.scmid, c.identifier |
|
469 | 475 | end |
|
470 | 476 | |
|
471 | 477 | def test_format_identifier |
|
472 | 478 | assert_equal 0, @repository.changesets.count |
|
473 | 479 | @repository.fetch_changesets |
|
474 | 480 | @project.reload |
|
475 | 481 | assert_equal NUM_REV, @repository.changesets.count |
|
476 | 482 | c = @repository.changesets.find_by_revision( |
|
477 | 483 | '7234cb2750b63f47bff735edc50a1c0a433c2518') |
|
478 | 484 | assert_equal '7234cb27', c.format_identifier |
|
479 | 485 | end |
|
480 | 486 | |
|
481 | 487 | def test_activities |
|
482 | 488 | c = Changeset.new(:repository => @repository, |
|
483 | 489 | :committed_on => Time.now, |
|
484 | 490 | :revision => 'abc7234cb2750b63f47bff735edc50a1c0a433c2', |
|
485 | 491 | :scmid => 'abc7234cb2750b63f47bff735edc50a1c0a433c2', |
|
486 | 492 | :comments => 'test') |
|
487 | 493 | assert c.event_title.include?('abc7234c:') |
|
488 | 494 | assert_equal 'abc7234cb2750b63f47bff735edc50a1c0a433c2', c.event_url[:rev] |
|
489 | 495 | end |
|
490 | 496 | |
|
491 | 497 | def test_log_utf8 |
|
492 | 498 | assert_equal 0, @repository.changesets.count |
|
493 | 499 | @repository.fetch_changesets |
|
494 | 500 | @project.reload |
|
495 | 501 | assert_equal NUM_REV, @repository.changesets.count |
|
496 | 502 | str_felix_hex = FELIX_HEX.dup |
|
497 | 503 | if str_felix_hex.respond_to?(:force_encoding) |
|
498 | 504 | str_felix_hex.force_encoding('UTF-8') |
|
499 | 505 | end |
|
500 | 506 | c = @repository.changesets.find_by_revision( |
|
501 | 507 | 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b') |
|
502 | 508 | assert_equal "#{str_felix_hex} <felix@fachschaften.org>", c.committer |
|
503 | 509 | end |
|
504 | 510 | |
|
505 | 511 | def test_previous |
|
506 | 512 | assert_equal 0, @repository.changesets.count |
|
507 | 513 | @repository.fetch_changesets |
|
508 | 514 | @project.reload |
|
509 | 515 | assert_equal NUM_REV, @repository.changesets.count |
|
510 | 516 | %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1| |
|
511 | 517 | changeset = @repository.find_changeset_by_name(r1) |
|
512 | 518 | %w|64f1f3e89ad1cb57976ff0ad99a107012ba3481d 64f1f3e89ad1|.each do |r2| |
|
513 | 519 | assert_equal @repository.find_changeset_by_name(r2), changeset.previous |
|
514 | 520 | end |
|
515 | 521 | end |
|
516 | 522 | end |
|
517 | 523 | |
|
518 | 524 | def test_previous_nil |
|
519 | 525 | assert_equal 0, @repository.changesets.count |
|
520 | 526 | @repository.fetch_changesets |
|
521 | 527 | @project.reload |
|
522 | 528 | assert_equal NUM_REV, @repository.changesets.count |
|
523 | 529 | %w|7234cb2750b63f47bff735edc50a1c0a433c2518 7234cb275|.each do |r1| |
|
524 | 530 | changeset = @repository.find_changeset_by_name(r1) |
|
525 | 531 | assert_nil changeset.previous |
|
526 | 532 | end |
|
527 | 533 | end |
|
528 | 534 | |
|
529 | 535 | def test_next |
|
530 | 536 | assert_equal 0, @repository.changesets.count |
|
531 | 537 | @repository.fetch_changesets |
|
532 | 538 | @project.reload |
|
533 | 539 | assert_equal NUM_REV, @repository.changesets.count |
|
534 | 540 | %w|64f1f3e89ad1cb57976ff0ad99a107012ba3481d 64f1f3e89ad1|.each do |r2| |
|
535 | 541 | changeset = @repository.find_changeset_by_name(r2) |
|
536 | 542 | %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1| |
|
537 | 543 | assert_equal @repository.find_changeset_by_name(r1), changeset.next |
|
538 | 544 | end |
|
539 | 545 | end |
|
540 | 546 | end |
|
541 | 547 | |
|
542 | 548 | def test_next_nil |
|
543 | 549 | assert_equal 0, @repository.changesets.count |
|
544 | 550 | @repository.fetch_changesets |
|
545 | 551 | @project.reload |
|
546 | 552 | assert_equal NUM_REV, @repository.changesets.count |
|
547 | 553 | %w|2a682156a3b6e77a8bf9cd4590e8db757f3c6c78 2a682156a3b6e77a|.each do |r1| |
|
548 | 554 | changeset = @repository.find_changeset_by_name(r1) |
|
549 | 555 | assert_nil changeset.next |
|
550 | 556 | end |
|
551 | 557 | end |
|
552 | 558 | else |
|
553 | 559 | puts "Git test repository NOT FOUND. Skipping unit tests !!!" |
|
554 | 560 | def test_fake; assert true end |
|
555 | 561 | end |
|
556 | 562 | end |
General Comments 0
You need to be logged in to leave comments.
Login now