##// END OF EJS Templates
remove extra empty lines from test/unit/changeset_test.rb...
Toshi MARUYAMA -
r12109:a624204f1b40
parent child
Show More
@@ -1,535 +1,532
1 1 # encoding: utf-8
2 2 #
3 3 # Redmine - project management software
4 4 # Copyright (C) 2006-2013 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
22 22 class ChangesetTest < ActiveSupport::TestCase
23 23 fixtures :projects, :repositories,
24 24 :issues, :issue_statuses, :issue_categories,
25 25 :changesets, :changes,
26 26 :enumerations,
27 27 :custom_fields, :custom_values,
28 28 :users, :members, :member_roles, :trackers,
29 29 :enabled_modules, :roles
30 30
31 31 def test_ref_keywords_any
32 32 ActionMailer::Base.deliveries.clear
33 33 Setting.commit_ref_keywords = '*'
34 34 Setting.commit_update_keywords = [{'keywords' => 'fixes , closes', 'status_id' => '5', 'done_ratio' => '90'}]
35 35
36 36 c = Changeset.new(:repository => Project.find(1).repository,
37 37 :committed_on => Time.now,
38 38 :comments => 'New commit (#2). Fixes #1',
39 39 :revision => '12345')
40 40 assert c.save
41 41 assert_equal [1, 2], c.issue_ids.sort
42 42 fixed = Issue.find(1)
43 43 assert fixed.closed?
44 44 assert_equal 90, fixed.done_ratio
45 45 assert_equal 1, ActionMailer::Base.deliveries.size
46 46 end
47 47
48 48 def test_ref_keywords
49 49 Setting.commit_ref_keywords = 'refs'
50 50 Setting.commit_update_keywords = ''
51 51 c = Changeset.new(:repository => Project.find(1).repository,
52 52 :committed_on => Time.now,
53 53 :comments => 'Ignores #2. Refs #1',
54 54 :revision => '12345')
55 55 assert c.save
56 56 assert_equal [1], c.issue_ids.sort
57 57 end
58 58
59 59 def test_ref_keywords_any_only
60 60 Setting.commit_ref_keywords = '*'
61 61 Setting.commit_update_keywords = ''
62 62 c = Changeset.new(:repository => Project.find(1).repository,
63 63 :committed_on => Time.now,
64 64 :comments => 'Ignores #2. Refs #1',
65 65 :revision => '12345')
66 66 assert c.save
67 67 assert_equal [1, 2], c.issue_ids.sort
68 68 end
69 69
70 70 def test_ref_keywords_any_with_timelog
71 71 Setting.commit_ref_keywords = '*'
72 72 Setting.commit_logtime_enabled = '1'
73 73
74 74 {
75 75 '2' => 2.0,
76 76 '2h' => 2.0,
77 77 '2hours' => 2.0,
78 78 '15m' => 0.25,
79 79 '15min' => 0.25,
80 80 '3h15' => 3.25,
81 81 '3h15m' => 3.25,
82 82 '3h15min' => 3.25,
83 83 '3:15' => 3.25,
84 84 '3.25' => 3.25,
85 85 '3.25h' => 3.25,
86 86 '3,25' => 3.25,
87 87 '3,25h' => 3.25,
88 88 }.each do |syntax, expected_hours|
89 89 c = Changeset.new(:repository => Project.find(1).repository,
90 90 :committed_on => 24.hours.ago,
91 91 :comments => "Worked on this issue #1 @#{syntax}",
92 92 :revision => '520',
93 93 :user => User.find(2))
94 94 assert_difference 'TimeEntry.count' do
95 95 c.scan_comment_for_issue_ids
96 96 end
97 97 assert_equal [1], c.issue_ids.sort
98 98
99 99 time = TimeEntry.first(:order => 'id desc')
100 100 assert_equal 1, time.issue_id
101 101 assert_equal 1, time.project_id
102 102 assert_equal 2, time.user_id
103 103 assert_equal expected_hours, time.hours,
104 104 "@#{syntax} should be logged as #{expected_hours} hours but was #{time.hours}"
105 105 assert_equal Date.yesterday, time.spent_on
106 106 assert time.activity.is_default?
107 107 assert time.comments.include?('r520'),
108 108 "r520 was expected in time_entry comments: #{time.comments}"
109 109 end
110 110 end
111 111
112 112 def test_ref_keywords_closing_with_timelog
113 113 Setting.commit_ref_keywords = '*'
114 114 Setting.commit_update_keywords = [{'keywords' => 'fixes , closes', 'status_id' => IssueStatus.where(:is_closed => true).first.id.to_s}]
115 115 Setting.commit_logtime_enabled = '1'
116 116
117 117 c = Changeset.new(:repository => Project.find(1).repository,
118 118 :committed_on => Time.now,
119 119 :comments => 'This is a comment. Fixes #1 @4.5, #2 @1',
120 120 :user => User.find(2))
121 121 assert_difference 'TimeEntry.count', 2 do
122 122 c.scan_comment_for_issue_ids
123 123 end
124 124
125 125 assert_equal [1, 2], c.issue_ids.sort
126 126 assert Issue.find(1).closed?
127 127 assert Issue.find(2).closed?
128 128
129 129 times = TimeEntry.all(:order => 'id desc', :limit => 2)
130 130 assert_equal [1, 2], times.collect(&:issue_id).sort
131 131 end
132 132
133 133 def test_ref_keywords_any_line_start
134 134 Setting.commit_ref_keywords = '*'
135 135 c = Changeset.new(:repository => Project.find(1).repository,
136 136 :committed_on => Time.now,
137 137 :comments => '#1 is the reason of this commit',
138 138 :revision => '12345')
139 139 assert c.save
140 140 assert_equal [1], c.issue_ids.sort
141 141 end
142 142
143 143 def test_ref_keywords_allow_brackets_around_a_issue_number
144 144 Setting.commit_ref_keywords = '*'
145 145 c = Changeset.new(:repository => Project.find(1).repository,
146 146 :committed_on => Time.now,
147 147 :comments => '[#1] Worked on this issue',
148 148 :revision => '12345')
149 149 assert c.save
150 150 assert_equal [1], c.issue_ids.sort
151 151 end
152 152
153 153 def test_ref_keywords_allow_brackets_around_multiple_issue_numbers
154 154 Setting.commit_ref_keywords = '*'
155 155 c = Changeset.new(:repository => Project.find(1).repository,
156 156 :committed_on => Time.now,
157 157 :comments => '[#1 #2, #3] Worked on these',
158 158 :revision => '12345')
159 159 assert c.save
160 160 assert_equal [1,2,3], c.issue_ids.sort
161 161 end
162 162
163 163 def test_update_keywords_with_multiple_rules
164 164 with_settings :commit_update_keywords => [
165 165 {'keywords' => 'fixes, closes', 'status_id' => '5'},
166 166 {'keywords' => 'resolves', 'status_id' => '3'}
167 167 ] do
168 168
169 169 issue1 = Issue.generate!
170 170 issue2 = Issue.generate!
171 171 Changeset.generate!(:comments => "Closes ##{issue1.id}\nResolves ##{issue2.id}")
172 172 assert_equal 5, issue1.reload.status_id
173 173 assert_equal 3, issue2.reload.status_id
174 174 end
175 175 end
176 176
177 177 def test_update_keywords_with_multiple_rules_should_match_tracker
178 178 with_settings :commit_update_keywords => [
179 179 {'keywords' => 'fixes', 'status_id' => '5', 'if_tracker_id' => '2'},
180 180 {'keywords' => 'fixes', 'status_id' => '3', 'if_tracker_id' => ''}
181 181 ] do
182 182
183 183 issue1 = Issue.generate!(:tracker_id => 2)
184 184 issue2 = Issue.generate!
185 185 Changeset.generate!(:comments => "Fixes ##{issue1.id}, ##{issue2.id}")
186 186 assert_equal 5, issue1.reload.status_id
187 187 assert_equal 3, issue2.reload.status_id
188 188 end
189 189 end
190 190
191 191 def test_update_keywords_with_multiple_rules_and_no_match
192 192 with_settings :commit_update_keywords => [
193 193 {'keywords' => 'fixes', 'status_id' => '5', 'if_tracker_id' => '2'},
194 194 {'keywords' => 'fixes', 'status_id' => '3', 'if_tracker_id' => '3'}
195 195 ] do
196 196
197 197 issue1 = Issue.generate!(:tracker_id => 2)
198 198 issue2 = Issue.generate!
199 199 Changeset.generate!(:comments => "Fixes ##{issue1.id}, ##{issue2.id}")
200 200 assert_equal 5, issue1.reload.status_id
201 201 assert_equal 1, issue2.reload.status_id # no updates
202 202 end
203 203 end
204 204
205 205 def test_commit_referencing_a_subproject_issue
206 206 c = Changeset.new(:repository => Project.find(1).repository,
207 207 :committed_on => Time.now,
208 208 :comments => 'refs #5, a subproject issue',
209 209 :revision => '12345')
210 210 assert c.save
211 211 assert_equal [5], c.issue_ids.sort
212 212 assert c.issues.first.project != c.project
213 213 end
214 214
215 215 def test_commit_closing_a_subproject_issue
216 216 with_settings :commit_update_keywords => [{'keywords' => 'closes', 'status_id' => '5'}],
217 217 :default_language => 'en' do
218 218 issue = Issue.find(5)
219 219 assert !issue.closed?
220 220 assert_difference 'Journal.count' do
221 221 c = Changeset.new(:repository => Project.find(1).repository,
222 222 :committed_on => Time.now,
223 223 :comments => 'closes #5, a subproject issue',
224 224 :revision => '12345')
225 225 assert c.save
226 226 end
227 227 assert issue.reload.closed?
228 228 journal = Journal.first(:order => 'id DESC')
229 229 assert_equal issue, journal.issue
230 230 assert_include "Applied in changeset ecookbook:r12345.", journal.notes
231 231 end
232 232 end
233 233
234 234 def test_commit_referencing_a_parent_project_issue
235 235 # repository of child project
236 236 r = Repository::Subversion.create!(
237 237 :project => Project.find(3),
238 238 :url => 'svn://localhost/test')
239 239 c = Changeset.new(:repository => r,
240 240 :committed_on => Time.now,
241 241 :comments => 'refs #2, an issue of a parent project',
242 242 :revision => '12345')
243 243 assert c.save
244 244 assert_equal [2], c.issue_ids.sort
245 245 assert c.issues.first.project != c.project
246 246 end
247 247
248 248 def test_commit_referencing_a_project_with_commit_cross_project_ref_disabled
249 249 r = Repository::Subversion.create!(
250 250 :project => Project.find(3),
251 251 :url => 'svn://localhost/test')
252
253 252 with_settings :commit_cross_project_ref => '0' do
254 253 c = Changeset.new(:repository => r,
255 254 :committed_on => Time.now,
256 255 :comments => 'refs #4, an issue of a different project',
257 256 :revision => '12345')
258 257 assert c.save
259 258 assert_equal [], c.issue_ids
260 259 end
261 260 end
262 261
263 262 def test_commit_referencing_a_project_with_commit_cross_project_ref_enabled
264 263 r = Repository::Subversion.create!(
265 264 :project => Project.find(3),
266 265 :url => 'svn://localhost/test')
267
268 266 with_settings :commit_cross_project_ref => '1' do
269 267 c = Changeset.new(:repository => r,
270 268 :committed_on => Time.now,
271 269 :comments => 'refs #4, an issue of a different project',
272 270 :revision => '12345')
273 271 assert c.save
274 272 assert_equal [4], c.issue_ids
275 273 end
276 274 end
277 275
278 276 def test_old_commits_should_not_update_issues_nor_log_time
279 277 Setting.commit_ref_keywords = '*'
280 278 Setting.commit_update_keywords = {'fixes , closes' => {'status_id' => '5', 'done_ratio' => '90'}}
281 279 Setting.commit_logtime_enabled = '1'
282 280
283 281 repository = Project.find(1).repository
284 282 repository.created_on = Time.now
285 283 repository.save!
286 284
287 285 c = Changeset.new(:repository => repository,
288 286 :committed_on => 1.month.ago,
289 287 :comments => 'New commit (#2). Fixes #1 @1h',
290 288 :revision => '12345')
291 289 assert_no_difference 'TimeEntry.count' do
292 290 assert c.save
293 291 end
294 292 assert_equal [1, 2], c.issue_ids.sort
295 293 issue = Issue.find(1)
296 294 assert_equal 1, issue.status_id
297 295 assert_equal 0, issue.done_ratio
298 296 end
299 297
300 298 def test_text_tag_revision
301 299 c = Changeset.new(:revision => '520')
302 300 assert_equal 'r520', c.text_tag
303 301 end
304 302
305 303 def test_text_tag_revision_with_same_project
306 304 c = Changeset.new(:revision => '520', :repository => Project.find(1).repository)
307 305 assert_equal 'r520', c.text_tag(Project.find(1))
308 306 end
309 307
310 308 def test_text_tag_revision_with_different_project
311 309 c = Changeset.new(:revision => '520', :repository => Project.find(1).repository)
312 310 assert_equal 'ecookbook:r520', c.text_tag(Project.find(2))
313 311 end
314 312
315 313 def test_text_tag_revision_with_repository_identifier
316 314 r = Repository::Subversion.create!(
317 315 :project_id => 1,
318 316 :url => 'svn://localhost/test',
319 317 :identifier => 'documents')
320
321 318 c = Changeset.new(:revision => '520', :repository => r)
322 319 assert_equal 'documents|r520', c.text_tag
323 320 assert_equal 'ecookbook:documents|r520', c.text_tag(Project.find(2))
324 321 end
325 322
326 323 def test_text_tag_hash
327 324 c = Changeset.new(
328 325 :scmid => '7234cb2750b63f47bff735edc50a1c0a433c2518',
329 326 :revision => '7234cb2750b63f47bff735edc50a1c0a433c2518')
330 327 assert_equal 'commit:7234cb2750b63f47bff735edc50a1c0a433c2518', c.text_tag
331 328 end
332 329
333 330 def test_text_tag_hash_with_same_project
334 331 c = Changeset.new(:revision => '7234cb27', :scmid => '7234cb27', :repository => Project.find(1).repository)
335 332 assert_equal 'commit:7234cb27', c.text_tag(Project.find(1))
336 333 end
337 334
338 335 def test_text_tag_hash_with_different_project
339 336 c = Changeset.new(:revision => '7234cb27', :scmid => '7234cb27', :repository => Project.find(1).repository)
340 337 assert_equal 'ecookbook:commit:7234cb27', c.text_tag(Project.find(2))
341 338 end
342 339
343 340 def test_text_tag_hash_all_number
344 341 c = Changeset.new(:scmid => '0123456789', :revision => '0123456789')
345 342 assert_equal 'commit:0123456789', c.text_tag
346 343 end
347 344
348 345 def test_previous
349 346 changeset = Changeset.find_by_revision('3')
350 347 assert_equal Changeset.find_by_revision('2'), changeset.previous
351 348 end
352 349
353 350 def test_previous_nil
354 351 changeset = Changeset.find_by_revision('1')
355 352 assert_nil changeset.previous
356 353 end
357 354
358 355 def test_next
359 356 changeset = Changeset.find_by_revision('2')
360 357 assert_equal Changeset.find_by_revision('3'), changeset.next
361 358 end
362 359
363 360 def test_next_nil
364 361 changeset = Changeset.find_by_revision('10')
365 362 assert_nil changeset.next
366 363 end
367 364
368 365 def test_comments_should_be_converted_to_utf8
369 366 proj = Project.find(3)
370 367 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
371 368 str = "Texte encod\xe9 en ISO-8859-1."
372 369 str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding)
373 370 r = Repository::Bazaar.create!(
374 371 :project => proj,
375 372 :url => '/tmp/test/bazaar',
376 373 :log_encoding => 'ISO-8859-1' )
377 374 assert r
378 375 c = Changeset.new(:repository => r,
379 376 :committed_on => Time.now,
380 377 :revision => '123',
381 378 :scmid => '12345',
382 379 :comments => str)
383 380 assert( c.save )
384 381 str_utf8 = "Texte encod\xc3\xa9 en ISO-8859-1."
385 382 str_utf8.force_encoding("UTF-8") if str_utf8.respond_to?(:force_encoding)
386 383 assert_equal str_utf8, c.comments
387 384 end
388 385
389 386 def test_invalid_utf8_sequences_in_comments_should_be_replaced_latin1
390 387 proj = Project.find(3)
391 388 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
392 389 str1 = "Texte encod\xe9 en ISO-8859-1."
393 390 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
394 391 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
395 392 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
396 393 r = Repository::Bazaar.create!(
397 394 :project => proj,
398 395 :url => '/tmp/test/bazaar',
399 396 :log_encoding => 'UTF-8' )
400 397 assert r
401 398 c = Changeset.new(:repository => r,
402 399 :committed_on => Time.now,
403 400 :revision => '123',
404 401 :scmid => '12345',
405 402 :comments => str1,
406 403 :committer => str2)
407 404 assert( c.save )
408 405 assert_equal "Texte encod? en ISO-8859-1.", c.comments
409 406 assert_equal "?a?b?c?d?e test", c.committer
410 407 end
411 408
412 409 def test_invalid_utf8_sequences_in_comments_should_be_replaced_ja_jis
413 410 proj = Project.find(3)
414 411 str = "test\xb5\xfetest\xb5\xfe"
415 412 if str.respond_to?(:force_encoding)
416 413 str.force_encoding('ASCII-8BIT')
417 414 end
418 415 r = Repository::Bazaar.create!(
419 416 :project => proj,
420 417 :url => '/tmp/test/bazaar',
421 418 :log_encoding => 'ISO-2022-JP' )
422 419 assert r
423 420 c = Changeset.new(:repository => r,
424 421 :committed_on => Time.now,
425 422 :revision => '123',
426 423 :scmid => '12345',
427 424 :comments => str)
428 425 assert( c.save )
429 426 assert_equal "test??test??", c.comments
430 427 end
431 428
432 429 def test_comments_should_be_converted_all_latin1_to_utf8
433 430 s1 = "\xC2\x80"
434 431 s2 = "\xc3\x82\xc2\x80"
435 432 s4 = s2.dup
436 433 if s1.respond_to?(:force_encoding)
437 434 s3 = s1.dup
438 435 s1.force_encoding('ASCII-8BIT')
439 436 s2.force_encoding('ASCII-8BIT')
440 437 s3.force_encoding('ISO-8859-1')
441 438 s4.force_encoding('UTF-8')
442 439 assert_equal s3.encode('UTF-8'), s4
443 440 end
444 441 proj = Project.find(3)
445 442 r = Repository::Bazaar.create!(
446 443 :project => proj,
447 444 :url => '/tmp/test/bazaar',
448 445 :log_encoding => 'ISO-8859-1' )
449 446 assert r
450 447 c = Changeset.new(:repository => r,
451 448 :committed_on => Time.now,
452 449 :revision => '123',
453 450 :scmid => '12345',
454 451 :comments => s1)
455 452 assert( c.save )
456 453 assert_equal s4, c.comments
457 454 end
458 455
459 456 def test_invalid_utf8_sequences_in_paths_should_be_replaced
460 457 proj = Project.find(3)
461 458 str1 = "Texte encod\xe9 en ISO-8859-1"
462 459 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
463 460 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
464 461 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
465 462 r = Repository::Bazaar.create!(
466 463 :project => proj,
467 464 :url => '/tmp/test/bazaar',
468 465 :log_encoding => 'UTF-8' )
469 466 assert r
470 467 cs = Changeset.new(
471 468 :repository => r,
472 469 :committed_on => Time.now,
473 470 :revision => '123',
474 471 :scmid => '12345',
475 472 :comments => "test")
476 473 assert(cs.save)
477 474 ch = Change.new(
478 475 :changeset => cs,
479 476 :action => "A",
480 477 :path => str1,
481 478 :from_path => str2,
482 479 :from_revision => "345")
483 480 assert(ch.save)
484 481 assert_equal "Texte encod? en ISO-8859-1", ch.path
485 482 assert_equal "?a?b?c?d?e test", ch.from_path
486 483 end
487 484
488 485 def test_comments_nil
489 486 proj = Project.find(3)
490 487 r = Repository::Bazaar.create!(
491 488 :project => proj,
492 489 :url => '/tmp/test/bazaar',
493 490 :log_encoding => 'ISO-8859-1' )
494 491 assert r
495 492 c = Changeset.new(:repository => r,
496 493 :committed_on => Time.now,
497 494 :revision => '123',
498 495 :scmid => '12345',
499 496 :comments => nil,
500 497 :committer => nil)
501 498 assert( c.save )
502 499 assert_equal "", c.comments
503 500 assert_equal nil, c.committer
504 501 if c.comments.respond_to?(:force_encoding)
505 502 assert_equal "UTF-8", c.comments.encoding.to_s
506 503 end
507 504 end
508 505
509 506 def test_comments_empty
510 507 proj = Project.find(3)
511 508 r = Repository::Bazaar.create!(
512 509 :project => proj,
513 510 :url => '/tmp/test/bazaar',
514 511 :log_encoding => 'ISO-8859-1' )
515 512 assert r
516 513 c = Changeset.new(:repository => r,
517 514 :committed_on => Time.now,
518 515 :revision => '123',
519 516 :scmid => '12345',
520 517 :comments => "",
521 518 :committer => "")
522 519 assert( c.save )
523 520 assert_equal "", c.comments
524 521 assert_equal "", c.committer
525 522 if c.comments.respond_to?(:force_encoding)
526 523 assert_equal "UTF-8", c.comments.encoding.to_s
527 524 assert_equal "UTF-8", c.committer.encoding.to_s
528 525 end
529 526 end
530 527
531 528 def test_identifier
532 529 c = Changeset.find_by_revision('1')
533 530 assert_equal c.revision, c.identifier
534 531 end
535 532 end
General Comments 0
You need to be logged in to leave comments. Login now