##// END OF EJS Templates
Merged r12944 (#16143)....
Jean-Philippe Lang -
r12672:dbe03f544355
parent child
Show More
@@ -0,0 +1,12
1 class ChangeChangesetsCommentsLimit < ActiveRecord::Migration
2 def up
3 if ActiveRecord::Base.connection.adapter_name =~ /mysql/i
4 max_size = 16.megabytes
5 change_column :changesets, :comments, :text, :limit => max_size
6 end
7 end
8
9 def down
10 # no-op
11 end
12 end
@@ -1,543 +1,554
1 1 # encoding: utf-8
2 2 #
3 3 # Redmine - project management software
4 4 # Copyright (C) 2006-2014 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.order('id desc').first
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',
115 115 'status_id' => IssueStatus.where(:is_closed => true).first.id.to_s}]
116 116 Setting.commit_logtime_enabled = '1'
117 117
118 118 c = Changeset.new(:repository => Project.find(1).repository,
119 119 :committed_on => Time.now,
120 120 :comments => 'This is a comment. Fixes #1 @4.5, #2 @1',
121 121 :user => User.find(2))
122 122 assert_difference 'TimeEntry.count', 2 do
123 123 c.scan_comment_for_issue_ids
124 124 end
125 125
126 126 assert_equal [1, 2], c.issue_ids.sort
127 127 assert Issue.find(1).closed?
128 128 assert Issue.find(2).closed?
129 129
130 130 times = TimeEntry.order('id desc').limit(2)
131 131 assert_equal [1, 2], times.collect(&:issue_id).sort
132 132 end
133 133
134 134 def test_ref_keywords_any_line_start
135 135 Setting.commit_ref_keywords = '*'
136 136 c = Changeset.new(:repository => Project.find(1).repository,
137 137 :committed_on => Time.now,
138 138 :comments => '#1 is the reason of this commit',
139 139 :revision => '12345')
140 140 assert c.save
141 141 assert_equal [1], c.issue_ids.sort
142 142 end
143 143
144 144 def test_ref_keywords_allow_brackets_around_a_issue_number
145 145 Setting.commit_ref_keywords = '*'
146 146 c = Changeset.new(:repository => Project.find(1).repository,
147 147 :committed_on => Time.now,
148 148 :comments => '[#1] Worked on this issue',
149 149 :revision => '12345')
150 150 assert c.save
151 151 assert_equal [1], c.issue_ids.sort
152 152 end
153 153
154 154 def test_ref_keywords_allow_brackets_around_multiple_issue_numbers
155 155 Setting.commit_ref_keywords = '*'
156 156 c = Changeset.new(:repository => Project.find(1).repository,
157 157 :committed_on => Time.now,
158 158 :comments => '[#1 #2, #3] Worked on these',
159 159 :revision => '12345')
160 160 assert c.save
161 161 assert_equal [1,2,3], c.issue_ids.sort
162 162 end
163 163
164 164 def test_update_keywords_with_multiple_rules
165 165 with_settings :commit_update_keywords => [
166 166 {'keywords' => 'fixes, closes', 'status_id' => '5'},
167 167 {'keywords' => 'resolves', 'status_id' => '3'}
168 168 ] do
169 169
170 170 issue1 = Issue.generate!
171 171 issue2 = Issue.generate!
172 172 Changeset.generate!(:comments => "Closes ##{issue1.id}\nResolves ##{issue2.id}")
173 173 assert_equal 5, issue1.reload.status_id
174 174 assert_equal 3, issue2.reload.status_id
175 175 end
176 176 end
177 177
178 178 def test_update_keywords_with_multiple_rules_should_match_tracker
179 179 with_settings :commit_update_keywords => [
180 180 {'keywords' => 'fixes', 'status_id' => '5', 'if_tracker_id' => '2'},
181 181 {'keywords' => 'fixes', 'status_id' => '3', 'if_tracker_id' => ''}
182 182 ] do
183 183
184 184 issue1 = Issue.generate!(:tracker_id => 2)
185 185 issue2 = Issue.generate!
186 186 Changeset.generate!(:comments => "Fixes ##{issue1.id}, ##{issue2.id}")
187 187 assert_equal 5, issue1.reload.status_id
188 188 assert_equal 3, issue2.reload.status_id
189 189 end
190 190 end
191 191
192 192 def test_update_keywords_with_multiple_rules_and_no_match
193 193 with_settings :commit_update_keywords => [
194 194 {'keywords' => 'fixes', 'status_id' => '5', 'if_tracker_id' => '2'},
195 195 {'keywords' => 'fixes', 'status_id' => '3', 'if_tracker_id' => '3'}
196 196 ] do
197 197
198 198 issue1 = Issue.generate!(:tracker_id => 2)
199 199 issue2 = Issue.generate!
200 200 Changeset.generate!(:comments => "Fixes ##{issue1.id}, ##{issue2.id}")
201 201 assert_equal 5, issue1.reload.status_id
202 202 assert_equal 1, issue2.reload.status_id # no updates
203 203 end
204 204 end
205 205
206 206 def test_commit_referencing_a_subproject_issue
207 207 c = Changeset.new(:repository => Project.find(1).repository,
208 208 :committed_on => Time.now,
209 209 :comments => 'refs #5, a subproject issue',
210 210 :revision => '12345')
211 211 assert c.save
212 212 assert_equal [5], c.issue_ids.sort
213 213 assert c.issues.first.project != c.project
214 214 end
215 215
216 216 def test_commit_closing_a_subproject_issue
217 217 with_settings :commit_update_keywords => [{'keywords' => 'closes', 'status_id' => '5'}],
218 218 :default_language => 'en' do
219 219 issue = Issue.find(5)
220 220 assert !issue.closed?
221 221 assert_difference 'Journal.count' do
222 222 c = Changeset.new(:repository => Project.find(1).repository,
223 223 :committed_on => Time.now,
224 224 :comments => 'closes #5, a subproject issue',
225 225 :revision => '12345')
226 226 assert c.save
227 227 end
228 228 assert issue.reload.closed?
229 229 journal = Journal.order('id DESC').first
230 230 assert_equal issue, journal.issue
231 231 assert_include "Applied in changeset ecookbook:r12345.", journal.notes
232 232 end
233 233 end
234 234
235 235 def test_commit_referencing_a_parent_project_issue
236 236 # repository of child project
237 237 r = Repository::Subversion.create!(
238 238 :project => Project.find(3),
239 239 :url => 'svn://localhost/test')
240 240 c = Changeset.new(:repository => r,
241 241 :committed_on => Time.now,
242 242 :comments => 'refs #2, an issue of a parent project',
243 243 :revision => '12345')
244 244 assert c.save
245 245 assert_equal [2], c.issue_ids.sort
246 246 assert c.issues.first.project != c.project
247 247 end
248 248
249 249 def test_commit_referencing_a_project_with_commit_cross_project_ref_disabled
250 250 r = Repository::Subversion.create!(
251 251 :project => Project.find(3),
252 252 :url => 'svn://localhost/test')
253 253 with_settings :commit_cross_project_ref => '0' do
254 254 c = Changeset.new(:repository => r,
255 255 :committed_on => Time.now,
256 256 :comments => 'refs #4, an issue of a different project',
257 257 :revision => '12345')
258 258 assert c.save
259 259 assert_equal [], c.issue_ids
260 260 end
261 261 end
262 262
263 263 def test_commit_referencing_a_project_with_commit_cross_project_ref_enabled
264 264 r = Repository::Subversion.create!(
265 265 :project => Project.find(3),
266 266 :url => 'svn://localhost/test')
267 267 with_settings :commit_cross_project_ref => '1' do
268 268 c = Changeset.new(:repository => r,
269 269 :committed_on => Time.now,
270 270 :comments => 'refs #4, an issue of a different project',
271 271 :revision => '12345')
272 272 assert c.save
273 273 assert_equal [4], c.issue_ids
274 274 end
275 275 end
276 276
277 277 def test_old_commits_should_not_update_issues_nor_log_time
278 278 Setting.commit_ref_keywords = '*'
279 279 Setting.commit_update_keywords = {'fixes , closes' => {'status_id' => '5', 'done_ratio' => '90'}}
280 280 Setting.commit_logtime_enabled = '1'
281 281
282 282 repository = Project.find(1).repository
283 283 repository.created_on = Time.now
284 284 repository.save!
285 285
286 286 c = Changeset.new(:repository => repository,
287 287 :committed_on => 1.month.ago,
288 288 :comments => 'New commit (#2). Fixes #1 @1h',
289 289 :revision => '12345')
290 290 assert_no_difference 'TimeEntry.count' do
291 291 assert c.save
292 292 end
293 293 assert_equal [1, 2], c.issue_ids.sort
294 294 issue = Issue.find(1)
295 295 assert_equal 1, issue.status_id
296 296 assert_equal 0, issue.done_ratio
297 297 end
298 298
299 299 def test_text_tag_revision
300 300 c = Changeset.new(:revision => '520')
301 301 assert_equal 'r520', c.text_tag
302 302 end
303 303
304 304 def test_text_tag_revision_with_same_project
305 305 c = Changeset.new(:revision => '520', :repository => Project.find(1).repository)
306 306 assert_equal 'r520', c.text_tag(Project.find(1))
307 307 end
308 308
309 309 def test_text_tag_revision_with_different_project
310 310 c = Changeset.new(:revision => '520', :repository => Project.find(1).repository)
311 311 assert_equal 'ecookbook:r520', c.text_tag(Project.find(2))
312 312 end
313 313
314 314 def test_text_tag_revision_with_repository_identifier
315 315 r = Repository::Subversion.create!(
316 316 :project_id => 1,
317 317 :url => 'svn://localhost/test',
318 318 :identifier => 'documents')
319 319 c = Changeset.new(:revision => '520', :repository => r)
320 320 assert_equal 'documents|r520', c.text_tag
321 321 assert_equal 'ecookbook:documents|r520', c.text_tag(Project.find(2))
322 322 end
323 323
324 324 def test_text_tag_hash
325 325 c = Changeset.new(
326 326 :scmid => '7234cb2750b63f47bff735edc50a1c0a433c2518',
327 327 :revision => '7234cb2750b63f47bff735edc50a1c0a433c2518')
328 328 assert_equal 'commit:7234cb2750b63f47bff735edc50a1c0a433c2518', c.text_tag
329 329 end
330 330
331 331 def test_text_tag_hash_with_same_project
332 332 c = Changeset.new(:revision => '7234cb27', :scmid => '7234cb27', :repository => Project.find(1).repository)
333 333 assert_equal 'commit:7234cb27', c.text_tag(Project.find(1))
334 334 end
335 335
336 336 def test_text_tag_hash_with_different_project
337 337 c = Changeset.new(:revision => '7234cb27', :scmid => '7234cb27', :repository => Project.find(1).repository)
338 338 assert_equal 'ecookbook:commit:7234cb27', c.text_tag(Project.find(2))
339 339 end
340 340
341 341 def test_text_tag_hash_all_number
342 342 c = Changeset.new(:scmid => '0123456789', :revision => '0123456789')
343 343 assert_equal 'commit:0123456789', c.text_tag
344 344 end
345 345
346 346 def test_text_tag_hash_with_repository_identifier
347 347 r = Repository::Subversion.new(
348 348 :project_id => 1,
349 349 :url => 'svn://localhost/test',
350 350 :identifier => 'documents')
351 351 c = Changeset.new(:revision => '7234cb27', :scmid => '7234cb27', :repository => r)
352 352 assert_equal 'commit:documents|7234cb27', c.text_tag
353 353 assert_equal 'ecookbook:commit:documents|7234cb27', c.text_tag(Project.find(2))
354 354 end
355 355
356 356 def test_previous
357 357 changeset = Changeset.find_by_revision('3')
358 358 assert_equal Changeset.find_by_revision('2'), changeset.previous
359 359 end
360 360
361 361 def test_previous_nil
362 362 changeset = Changeset.find_by_revision('1')
363 363 assert_nil changeset.previous
364 364 end
365 365
366 366 def test_next
367 367 changeset = Changeset.find_by_revision('2')
368 368 assert_equal Changeset.find_by_revision('3'), changeset.next
369 369 end
370 370
371 371 def test_next_nil
372 372 changeset = Changeset.find_by_revision('10')
373 373 assert_nil changeset.next
374 374 end
375 375
376 376 def test_comments_should_be_converted_to_utf8
377 377 proj = Project.find(3)
378 378 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
379 379 str = "Texte encod\xe9 en ISO-8859-1."
380 380 str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding)
381 381 r = Repository::Bazaar.create!(
382 382 :project => proj,
383 383 :url => '/tmp/test/bazaar',
384 384 :log_encoding => 'ISO-8859-1' )
385 385 assert r
386 386 c = Changeset.new(:repository => r,
387 387 :committed_on => Time.now,
388 388 :revision => '123',
389 389 :scmid => '12345',
390 390 :comments => str)
391 391 assert( c.save )
392 392 str_utf8 = "Texte encod\xc3\xa9 en ISO-8859-1."
393 393 str_utf8.force_encoding("UTF-8") if str_utf8.respond_to?(:force_encoding)
394 394 assert_equal str_utf8, c.comments
395 395 end
396 396
397 397 def test_invalid_utf8_sequences_in_comments_should_be_replaced_latin1
398 398 proj = Project.find(3)
399 399 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
400 400 str1 = "Texte encod\xe9 en ISO-8859-1."
401 401 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
402 402 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
403 403 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
404 404 r = Repository::Bazaar.create!(
405 405 :project => proj,
406 406 :url => '/tmp/test/bazaar',
407 407 :log_encoding => 'UTF-8' )
408 408 assert r
409 409 c = Changeset.new(:repository => r,
410 410 :committed_on => Time.now,
411 411 :revision => '123',
412 412 :scmid => '12345',
413 413 :comments => str1,
414 414 :committer => str2)
415 415 assert( c.save )
416 416 assert_equal "Texte encod? en ISO-8859-1.", c.comments
417 417 assert_equal "?a?b?c?d?e test", c.committer
418 418 end
419 419
420 420 def test_invalid_utf8_sequences_in_comments_should_be_replaced_ja_jis
421 421 proj = Project.find(3)
422 422 str = "test\xb5\xfetest\xb5\xfe"
423 423 if str.respond_to?(:force_encoding)
424 424 str.force_encoding('ASCII-8BIT')
425 425 end
426 426 r = Repository::Bazaar.create!(
427 427 :project => proj,
428 428 :url => '/tmp/test/bazaar',
429 429 :log_encoding => 'ISO-2022-JP' )
430 430 assert r
431 431 c = Changeset.new(:repository => r,
432 432 :committed_on => Time.now,
433 433 :revision => '123',
434 434 :scmid => '12345',
435 435 :comments => str)
436 436 assert( c.save )
437 437 assert_equal "test??test??", c.comments
438 438 end
439 439
440 440 def test_comments_should_be_converted_all_latin1_to_utf8
441 441 s1 = "\xC2\x80"
442 442 s2 = "\xc3\x82\xc2\x80"
443 443 s4 = s2.dup
444 444 if s1.respond_to?(:force_encoding)
445 445 s3 = s1.dup
446 446 s1.force_encoding('ASCII-8BIT')
447 447 s2.force_encoding('ASCII-8BIT')
448 448 s3.force_encoding('ISO-8859-1')
449 449 s4.force_encoding('UTF-8')
450 450 assert_equal s3.encode('UTF-8'), s4
451 451 end
452 452 proj = Project.find(3)
453 453 r = Repository::Bazaar.create!(
454 454 :project => proj,
455 455 :url => '/tmp/test/bazaar',
456 456 :log_encoding => 'ISO-8859-1' )
457 457 assert r
458 458 c = Changeset.new(:repository => r,
459 459 :committed_on => Time.now,
460 460 :revision => '123',
461 461 :scmid => '12345',
462 462 :comments => s1)
463 463 assert( c.save )
464 464 assert_equal s4, c.comments
465 465 end
466 466
467 467 def test_invalid_utf8_sequences_in_paths_should_be_replaced
468 468 proj = Project.find(3)
469 469 str1 = "Texte encod\xe9 en ISO-8859-1"
470 470 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
471 471 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
472 472 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
473 473 r = Repository::Bazaar.create!(
474 474 :project => proj,
475 475 :url => '/tmp/test/bazaar',
476 476 :log_encoding => 'UTF-8' )
477 477 assert r
478 478 cs = Changeset.new(
479 479 :repository => r,
480 480 :committed_on => Time.now,
481 481 :revision => '123',
482 482 :scmid => '12345',
483 483 :comments => "test")
484 484 assert(cs.save)
485 485 ch = Change.new(
486 486 :changeset => cs,
487 487 :action => "A",
488 488 :path => str1,
489 489 :from_path => str2,
490 490 :from_revision => "345")
491 491 assert(ch.save)
492 492 assert_equal "Texte encod? en ISO-8859-1", ch.path
493 493 assert_equal "?a?b?c?d?e test", ch.from_path
494 494 end
495 495
496 496 def test_comments_nil
497 497 proj = Project.find(3)
498 498 r = Repository::Bazaar.create!(
499 499 :project => proj,
500 500 :url => '/tmp/test/bazaar',
501 501 :log_encoding => 'ISO-8859-1' )
502 502 assert r
503 503 c = Changeset.new(:repository => r,
504 504 :committed_on => Time.now,
505 505 :revision => '123',
506 506 :scmid => '12345',
507 507 :comments => nil,
508 508 :committer => nil)
509 509 assert( c.save )
510 510 assert_equal "", c.comments
511 511 assert_equal nil, c.committer
512 512 if c.comments.respond_to?(:force_encoding)
513 513 assert_equal "UTF-8", c.comments.encoding.to_s
514 514 end
515 515 end
516 516
517 517 def test_comments_empty
518 518 proj = Project.find(3)
519 519 r = Repository::Bazaar.create!(
520 520 :project => proj,
521 521 :url => '/tmp/test/bazaar',
522 522 :log_encoding => 'ISO-8859-1' )
523 523 assert r
524 524 c = Changeset.new(:repository => r,
525 525 :committed_on => Time.now,
526 526 :revision => '123',
527 527 :scmid => '12345',
528 528 :comments => "",
529 529 :committer => "")
530 530 assert( c.save )
531 531 assert_equal "", c.comments
532 532 assert_equal "", c.committer
533 533 if c.comments.respond_to?(:force_encoding)
534 534 assert_equal "UTF-8", c.comments.encoding.to_s
535 535 assert_equal "UTF-8", c.committer.encoding.to_s
536 536 end
537 537 end
538 538
539 def test_comments_should_accept_more_than_64k
540 c = Changeset.new(:repository => Repository.first,
541 :committed_on => Time.now,
542 :revision => '123',
543 :scmid => '12345',
544 :comments => "a" * 500.kilobyte)
545 assert c.save
546 c.reload
547 assert_equal 500.kilobyte, c.comments.size
548 end
549
539 550 def test_identifier
540 551 c = Changeset.find_by_revision('1')
541 552 assert_equal c.revision, c.identifier
542 553 end
543 554 end
General Comments 0
You need to be logged in to leave comments. Login now