##// END OF EJS Templates
remove empty setup method from test/unit/changeset_test.rb...
Toshi MARUYAMA -
r10273:7690aff8bd16
parent child
Show More
@@ -1,479 +1,476
1 1 # encoding: utf-8
2 2 #
3 3 # Redmine - project management software
4 4 # Copyright (C) 2006-2012 Jean-Philippe Lang
5 5 #
6 6 # This program is free software; you can redistribute it and/or
7 7 # modify it under the terms of the GNU General Public License
8 8 # as published by the Free Software Foundation; either version 2
9 9 # of the License, or (at your option) any later version.
10 10 #
11 11 # This program is distributed in the hope that it will be useful,
12 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 14 # GNU General Public License for more details.
15 15 #
16 16 # You should have received a copy of the GNU General Public License
17 17 # along with this program; if not, write to the Free Software
18 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 19
20 20 require File.expand_path('../../test_helper', __FILE__)
21 21
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 def setup
32 end
33
34 31 def test_ref_keywords_any
35 32 ActionMailer::Base.deliveries.clear
36 33 Setting.commit_fix_status_id = IssueStatus.find(
37 34 :first, :conditions => ["is_closed = ?", true]).id
38 35 Setting.commit_fix_done_ratio = '90'
39 36 Setting.commit_ref_keywords = '*'
40 37 Setting.commit_fix_keywords = 'fixes , closes'
41 38
42 39 c = Changeset.new(:repository => Project.find(1).repository,
43 40 :committed_on => Time.now,
44 41 :comments => 'New commit (#2). Fixes #1',
45 42 :revision => '12345')
46 43 assert c.save
47 44 assert_equal [1, 2], c.issue_ids.sort
48 45 fixed = Issue.find(1)
49 46 assert fixed.closed?
50 47 assert_equal 90, fixed.done_ratio
51 48 assert_equal 1, ActionMailer::Base.deliveries.size
52 49 end
53 50
54 51 def test_ref_keywords
55 52 Setting.commit_ref_keywords = 'refs'
56 53 Setting.commit_fix_keywords = ''
57 54 c = Changeset.new(:repository => Project.find(1).repository,
58 55 :committed_on => Time.now,
59 56 :comments => 'Ignores #2. Refs #1',
60 57 :revision => '12345')
61 58 assert c.save
62 59 assert_equal [1], c.issue_ids.sort
63 60 end
64 61
65 62 def test_ref_keywords_any_only
66 63 Setting.commit_ref_keywords = '*'
67 64 Setting.commit_fix_keywords = ''
68 65 c = Changeset.new(:repository => Project.find(1).repository,
69 66 :committed_on => Time.now,
70 67 :comments => 'Ignores #2. Refs #1',
71 68 :revision => '12345')
72 69 assert c.save
73 70 assert_equal [1, 2], c.issue_ids.sort
74 71 end
75 72
76 73 def test_ref_keywords_any_with_timelog
77 74 Setting.commit_ref_keywords = '*'
78 75 Setting.commit_logtime_enabled = '1'
79 76
80 77 {
81 78 '2' => 2.0,
82 79 '2h' => 2.0,
83 80 '2hours' => 2.0,
84 81 '15m' => 0.25,
85 82 '15min' => 0.25,
86 83 '3h15' => 3.25,
87 84 '3h15m' => 3.25,
88 85 '3h15min' => 3.25,
89 86 '3:15' => 3.25,
90 87 '3.25' => 3.25,
91 88 '3.25h' => 3.25,
92 89 '3,25' => 3.25,
93 90 '3,25h' => 3.25,
94 91 }.each do |syntax, expected_hours|
95 92 c = Changeset.new(:repository => Project.find(1).repository,
96 93 :committed_on => 24.hours.ago,
97 94 :comments => "Worked on this issue #1 @#{syntax}",
98 95 :revision => '520',
99 96 :user => User.find(2))
100 97 assert_difference 'TimeEntry.count' do
101 98 c.scan_comment_for_issue_ids
102 99 end
103 100 assert_equal [1], c.issue_ids.sort
104 101
105 102 time = TimeEntry.first(:order => 'id desc')
106 103 assert_equal 1, time.issue_id
107 104 assert_equal 1, time.project_id
108 105 assert_equal 2, time.user_id
109 106 assert_equal expected_hours, time.hours,
110 107 "@#{syntax} should be logged as #{expected_hours} hours but was #{time.hours}"
111 108 assert_equal Date.yesterday, time.spent_on
112 109 assert time.activity.is_default?
113 110 assert time.comments.include?('r520'),
114 111 "r520 was expected in time_entry comments: #{time.comments}"
115 112 end
116 113 end
117 114
118 115 def test_ref_keywords_closing_with_timelog
119 116 Setting.commit_fix_status_id = IssueStatus.find(
120 117 :first, :conditions => ["is_closed = ?", true]).id
121 118 Setting.commit_ref_keywords = '*'
122 119 Setting.commit_fix_keywords = 'fixes , closes'
123 120 Setting.commit_logtime_enabled = '1'
124 121
125 122 c = Changeset.new(:repository => Project.find(1).repository,
126 123 :committed_on => Time.now,
127 124 :comments => 'This is a comment. Fixes #1 @4.5, #2 @1',
128 125 :user => User.find(2))
129 126 assert_difference 'TimeEntry.count', 2 do
130 127 c.scan_comment_for_issue_ids
131 128 end
132 129
133 130 assert_equal [1, 2], c.issue_ids.sort
134 131 assert Issue.find(1).closed?
135 132 assert Issue.find(2).closed?
136 133
137 134 times = TimeEntry.all(:order => 'id desc', :limit => 2)
138 135 assert_equal [1, 2], times.collect(&:issue_id).sort
139 136 end
140 137
141 138 def test_ref_keywords_any_line_start
142 139 Setting.commit_ref_keywords = '*'
143 140 c = Changeset.new(:repository => Project.find(1).repository,
144 141 :committed_on => Time.now,
145 142 :comments => '#1 is the reason of this commit',
146 143 :revision => '12345')
147 144 assert c.save
148 145 assert_equal [1], c.issue_ids.sort
149 146 end
150 147
151 148 def test_ref_keywords_allow_brackets_around_a_issue_number
152 149 Setting.commit_ref_keywords = '*'
153 150 c = Changeset.new(:repository => Project.find(1).repository,
154 151 :committed_on => Time.now,
155 152 :comments => '[#1] Worked on this issue',
156 153 :revision => '12345')
157 154 assert c.save
158 155 assert_equal [1], c.issue_ids.sort
159 156 end
160 157
161 158 def test_ref_keywords_allow_brackets_around_multiple_issue_numbers
162 159 Setting.commit_ref_keywords = '*'
163 160 c = Changeset.new(:repository => Project.find(1).repository,
164 161 :committed_on => Time.now,
165 162 :comments => '[#1 #2, #3] Worked on these',
166 163 :revision => '12345')
167 164 assert c.save
168 165 assert_equal [1,2,3], c.issue_ids.sort
169 166 end
170 167
171 168 def test_commit_referencing_a_subproject_issue
172 169 c = Changeset.new(:repository => Project.find(1).repository,
173 170 :committed_on => Time.now,
174 171 :comments => 'refs #5, a subproject issue',
175 172 :revision => '12345')
176 173 assert c.save
177 174 assert_equal [5], c.issue_ids.sort
178 175 assert c.issues.first.project != c.project
179 176 end
180 177
181 178 def test_commit_closing_a_subproject_issue
182 179 with_settings :commit_fix_status_id => 5, :commit_fix_keywords => 'closes',
183 180 :default_language => 'en' do
184 181 issue = Issue.find(5)
185 182 assert !issue.closed?
186 183 assert_difference 'Journal.count' do
187 184 c = Changeset.new(:repository => Project.find(1).repository,
188 185 :committed_on => Time.now,
189 186 :comments => 'closes #5, a subproject issue',
190 187 :revision => '12345')
191 188 assert c.save
192 189 end
193 190 assert issue.reload.closed?
194 191 journal = Journal.first(:order => 'id DESC')
195 192 assert_equal issue, journal.issue
196 193 assert_include "Applied in changeset ecookbook:r12345.", journal.notes
197 194 end
198 195 end
199 196
200 197 def test_commit_referencing_a_parent_project_issue
201 198 # repository of child project
202 199 r = Repository::Subversion.create!(
203 200 :project => Project.find(3),
204 201 :url => 'svn://localhost/test')
205 202 c = Changeset.new(:repository => r,
206 203 :committed_on => Time.now,
207 204 :comments => 'refs #2, an issue of a parent project',
208 205 :revision => '12345')
209 206 assert c.save
210 207 assert_equal [2], c.issue_ids.sort
211 208 assert c.issues.first.project != c.project
212 209 end
213 210
214 211 def test_commit_referencing_a_project_with_commit_cross_project_ref_disabled
215 212 r = Repository::Subversion.create!(
216 213 :project => Project.find(3),
217 214 :url => 'svn://localhost/test')
218 215
219 216 with_settings :commit_cross_project_ref => '0' do
220 217 c = Changeset.new(:repository => r,
221 218 :committed_on => Time.now,
222 219 :comments => 'refs #4, an issue of a different project',
223 220 :revision => '12345')
224 221 assert c.save
225 222 assert_equal [], c.issue_ids
226 223 end
227 224 end
228 225
229 226 def test_commit_referencing_a_project_with_commit_cross_project_ref_enabled
230 227 r = Repository::Subversion.create!(
231 228 :project => Project.find(3),
232 229 :url => 'svn://localhost/test')
233 230
234 231 with_settings :commit_cross_project_ref => '1' do
235 232 c = Changeset.new(:repository => r,
236 233 :committed_on => Time.now,
237 234 :comments => 'refs #4, an issue of a different project',
238 235 :revision => '12345')
239 236 assert c.save
240 237 assert_equal [4], c.issue_ids
241 238 end
242 239 end
243 240
244 241 def test_text_tag_revision
245 242 c = Changeset.new(:revision => '520')
246 243 assert_equal 'r520', c.text_tag
247 244 end
248 245
249 246 def test_text_tag_revision_with_same_project
250 247 c = Changeset.new(:revision => '520', :repository => Project.find(1).repository)
251 248 assert_equal 'r520', c.text_tag(Project.find(1))
252 249 end
253 250
254 251 def test_text_tag_revision_with_different_project
255 252 c = Changeset.new(:revision => '520', :repository => Project.find(1).repository)
256 253 assert_equal 'ecookbook:r520', c.text_tag(Project.find(2))
257 254 end
258 255
259 256 def test_text_tag_revision_with_repository_identifier
260 257 r = Repository::Subversion.create!(
261 258 :project_id => 1,
262 259 :url => 'svn://localhost/test',
263 260 :identifier => 'documents')
264 261
265 262 c = Changeset.new(:revision => '520', :repository => r)
266 263 assert_equal 'documents|r520', c.text_tag
267 264 assert_equal 'ecookbook:documents|r520', c.text_tag(Project.find(2))
268 265 end
269 266
270 267 def test_text_tag_hash
271 268 c = Changeset.new(
272 269 :scmid => '7234cb2750b63f47bff735edc50a1c0a433c2518',
273 270 :revision => '7234cb2750b63f47bff735edc50a1c0a433c2518')
274 271 assert_equal 'commit:7234cb2750b63f47bff735edc50a1c0a433c2518', c.text_tag
275 272 end
276 273
277 274 def test_text_tag_hash_with_same_project
278 275 c = Changeset.new(:revision => '7234cb27', :scmid => '7234cb27', :repository => Project.find(1).repository)
279 276 assert_equal 'commit:7234cb27', c.text_tag(Project.find(1))
280 277 end
281 278
282 279 def test_text_tag_hash_with_different_project
283 280 c = Changeset.new(:revision => '7234cb27', :scmid => '7234cb27', :repository => Project.find(1).repository)
284 281 assert_equal 'ecookbook:commit:7234cb27', c.text_tag(Project.find(2))
285 282 end
286 283
287 284 def test_text_tag_hash_all_number
288 285 c = Changeset.new(:scmid => '0123456789', :revision => '0123456789')
289 286 assert_equal 'commit:0123456789', c.text_tag
290 287 end
291 288
292 289 def test_previous
293 290 changeset = Changeset.find_by_revision('3')
294 291 assert_equal Changeset.find_by_revision('2'), changeset.previous
295 292 end
296 293
297 294 def test_previous_nil
298 295 changeset = Changeset.find_by_revision('1')
299 296 assert_nil changeset.previous
300 297 end
301 298
302 299 def test_next
303 300 changeset = Changeset.find_by_revision('2')
304 301 assert_equal Changeset.find_by_revision('3'), changeset.next
305 302 end
306 303
307 304 def test_next_nil
308 305 changeset = Changeset.find_by_revision('10')
309 306 assert_nil changeset.next
310 307 end
311 308
312 309 def test_comments_should_be_converted_to_utf8
313 310 proj = Project.find(3)
314 311 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
315 312 str = "Texte encod\xe9 en ISO-8859-1."
316 313 str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding)
317 314 r = Repository::Bazaar.create!(
318 315 :project => proj,
319 316 :url => '/tmp/test/bazaar',
320 317 :log_encoding => 'ISO-8859-1' )
321 318 assert r
322 319 c = Changeset.new(:repository => r,
323 320 :committed_on => Time.now,
324 321 :revision => '123',
325 322 :scmid => '12345',
326 323 :comments => str)
327 324 assert( c.save )
328 325 str_utf8 = "Texte encod\xc3\xa9 en ISO-8859-1."
329 326 str_utf8.force_encoding("UTF-8") if str_utf8.respond_to?(:force_encoding)
330 327 assert_equal str_utf8, c.comments
331 328 end
332 329
333 330 def test_invalid_utf8_sequences_in_comments_should_be_replaced_latin1
334 331 proj = Project.find(3)
335 332 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
336 333 str1 = "Texte encod\xe9 en ISO-8859-1."
337 334 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
338 335 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
339 336 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
340 337 r = Repository::Bazaar.create!(
341 338 :project => proj,
342 339 :url => '/tmp/test/bazaar',
343 340 :log_encoding => 'UTF-8' )
344 341 assert r
345 342 c = Changeset.new(:repository => r,
346 343 :committed_on => Time.now,
347 344 :revision => '123',
348 345 :scmid => '12345',
349 346 :comments => str1,
350 347 :committer => str2)
351 348 assert( c.save )
352 349 assert_equal "Texte encod? en ISO-8859-1.", c.comments
353 350 assert_equal "?a?b?c?d?e test", c.committer
354 351 end
355 352
356 353 def test_invalid_utf8_sequences_in_comments_should_be_replaced_ja_jis
357 354 proj = Project.find(3)
358 355 str = "test\xb5\xfetest\xb5\xfe"
359 356 if str.respond_to?(:force_encoding)
360 357 str.force_encoding('ASCII-8BIT')
361 358 end
362 359 r = Repository::Bazaar.create!(
363 360 :project => proj,
364 361 :url => '/tmp/test/bazaar',
365 362 :log_encoding => 'ISO-2022-JP' )
366 363 assert r
367 364 c = Changeset.new(:repository => r,
368 365 :committed_on => Time.now,
369 366 :revision => '123',
370 367 :scmid => '12345',
371 368 :comments => str)
372 369 assert( c.save )
373 370 assert_equal "test??test??", c.comments
374 371 end
375 372
376 373 def test_comments_should_be_converted_all_latin1_to_utf8
377 374 s1 = "\xC2\x80"
378 375 s2 = "\xc3\x82\xc2\x80"
379 376 s4 = s2.dup
380 377 if s1.respond_to?(:force_encoding)
381 378 s3 = s1.dup
382 379 s1.force_encoding('ASCII-8BIT')
383 380 s2.force_encoding('ASCII-8BIT')
384 381 s3.force_encoding('ISO-8859-1')
385 382 s4.force_encoding('UTF-8')
386 383 assert_equal s3.encode('UTF-8'), s4
387 384 end
388 385 proj = Project.find(3)
389 386 r = Repository::Bazaar.create!(
390 387 :project => proj,
391 388 :url => '/tmp/test/bazaar',
392 389 :log_encoding => 'ISO-8859-1' )
393 390 assert r
394 391 c = Changeset.new(:repository => r,
395 392 :committed_on => Time.now,
396 393 :revision => '123',
397 394 :scmid => '12345',
398 395 :comments => s1)
399 396 assert( c.save )
400 397 assert_equal s4, c.comments
401 398 end
402 399
403 400 def test_invalid_utf8_sequences_in_paths_should_be_replaced
404 401 proj = Project.find(3)
405 402 str1 = "Texte encod\xe9 en ISO-8859-1"
406 403 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
407 404 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
408 405 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
409 406 r = Repository::Bazaar.create!(
410 407 :project => proj,
411 408 :url => '/tmp/test/bazaar',
412 409 :log_encoding => 'UTF-8' )
413 410 assert r
414 411 cs = Changeset.new(
415 412 :repository => r,
416 413 :committed_on => Time.now,
417 414 :revision => '123',
418 415 :scmid => '12345',
419 416 :comments => "test")
420 417 assert(cs.save)
421 418 ch = Change.new(
422 419 :changeset => cs,
423 420 :action => "A",
424 421 :path => str1,
425 422 :from_path => str2,
426 423 :from_revision => "345")
427 424 assert(ch.save)
428 425 assert_equal "Texte encod? en ISO-8859-1", ch.path
429 426 assert_equal "?a?b?c?d?e test", ch.from_path
430 427 end
431 428
432 429 def test_comments_nil
433 430 proj = Project.find(3)
434 431 r = Repository::Bazaar.create!(
435 432 :project => proj,
436 433 :url => '/tmp/test/bazaar',
437 434 :log_encoding => 'ISO-8859-1' )
438 435 assert r
439 436 c = Changeset.new(:repository => r,
440 437 :committed_on => Time.now,
441 438 :revision => '123',
442 439 :scmid => '12345',
443 440 :comments => nil,
444 441 :committer => nil)
445 442 assert( c.save )
446 443 assert_equal "", c.comments
447 444 assert_equal nil, c.committer
448 445 if c.comments.respond_to?(:force_encoding)
449 446 assert_equal "UTF-8", c.comments.encoding.to_s
450 447 end
451 448 end
452 449
453 450 def test_comments_empty
454 451 proj = Project.find(3)
455 452 r = Repository::Bazaar.create!(
456 453 :project => proj,
457 454 :url => '/tmp/test/bazaar',
458 455 :log_encoding => 'ISO-8859-1' )
459 456 assert r
460 457 c = Changeset.new(:repository => r,
461 458 :committed_on => Time.now,
462 459 :revision => '123',
463 460 :scmid => '12345',
464 461 :comments => "",
465 462 :committer => "")
466 463 assert( c.save )
467 464 assert_equal "", c.comments
468 465 assert_equal "", c.committer
469 466 if c.comments.respond_to?(:force_encoding)
470 467 assert_equal "UTF-8", c.comments.encoding.to_s
471 468 assert_equal "UTF-8", c.committer.encoding.to_s
472 469 end
473 470 end
474 471
475 472 def test_identifier
476 473 c = Changeset.find_by_revision('1')
477 474 assert_equal c.revision, c.identifier
478 475 end
479 476 end
General Comments 0
You need to be logged in to leave comments. Login now