##// END OF EJS Templates
scm: add dummy revision at test_ref_keywords_any of unit changeset test....
Toshi MARUYAMA -
r6598:21dd3e39ec6c
parent child
Show More
@@ -1,405 +1,406
1 1 # encoding: utf-8
2 2 #
3 3 # Redmine - project management software
4 4 # Copyright (C) 2006-2011 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 setup
32 32 end
33 33
34 34 def test_ref_keywords_any
35 35 ActionMailer::Base.deliveries.clear
36 36 Setting.commit_fix_status_id = IssueStatus.find(
37 37 :first, :conditions => ["is_closed = ?", true]).id
38 38 Setting.commit_fix_done_ratio = '90'
39 39 Setting.commit_ref_keywords = '*'
40 40 Setting.commit_fix_keywords = 'fixes , closes'
41 41
42 42 c = Changeset.new(:repository => Project.find(1).repository,
43 43 :committed_on => Time.now,
44 :comments => 'New commit (#2). Fixes #1')
44 :comments => 'New commit (#2). Fixes #1',
45 :revision => '12345')
45 46 c.scan_comment_for_issue_ids
46 47
47 48 assert_equal [1, 2], c.issue_ids.sort
48 49 fixed = Issue.find(1)
49 50 assert fixed.closed?
50 51 assert_equal 90, fixed.done_ratio
51 52 assert_equal 1, ActionMailer::Base.deliveries.size
52 53 end
53 54
54 55 def test_ref_keywords
55 56 Setting.commit_ref_keywords = 'refs'
56 57 Setting.commit_fix_keywords = ''
57 58
58 59 c = Changeset.new(:repository => Project.find(1).repository,
59 60 :committed_on => Time.now,
60 61 :comments => 'Ignores #2. Refs #1')
61 62 c.scan_comment_for_issue_ids
62 63
63 64 assert_equal [1], c.issue_ids.sort
64 65 end
65 66
66 67 def test_ref_keywords_any_only
67 68 Setting.commit_ref_keywords = '*'
68 69 Setting.commit_fix_keywords = ''
69 70
70 71 c = Changeset.new(:repository => Project.find(1).repository,
71 72 :committed_on => Time.now,
72 73 :comments => 'Ignores #2. Refs #1')
73 74 c.scan_comment_for_issue_ids
74 75
75 76 assert_equal [1, 2], c.issue_ids.sort
76 77 end
77 78
78 79 def test_ref_keywords_any_with_timelog
79 80 Setting.commit_ref_keywords = '*'
80 81 Setting.commit_logtime_enabled = '1'
81 82
82 83 {
83 84 '2' => 2.0,
84 85 '2h' => 2.0,
85 86 '2hours' => 2.0,
86 87 '15m' => 0.25,
87 88 '15min' => 0.25,
88 89 '3h15' => 3.25,
89 90 '3h15m' => 3.25,
90 91 '3h15min' => 3.25,
91 92 '3:15' => 3.25,
92 93 '3.25' => 3.25,
93 94 '3.25h' => 3.25,
94 95 '3,25' => 3.25,
95 96 '3,25h' => 3.25,
96 97 }.each do |syntax, expected_hours|
97 98 c = Changeset.new(:repository => Project.find(1).repository,
98 99 :committed_on => 24.hours.ago,
99 100 :comments => "Worked on this issue #1 @#{syntax}",
100 101 :revision => '520',
101 102 :user => User.find(2))
102 103 assert_difference 'TimeEntry.count' do
103 104 c.scan_comment_for_issue_ids
104 105 end
105 106 assert_equal [1], c.issue_ids.sort
106 107
107 108 time = TimeEntry.first(:order => 'id desc')
108 109 assert_equal 1, time.issue_id
109 110 assert_equal 1, time.project_id
110 111 assert_equal 2, time.user_id
111 112 assert_equal expected_hours, time.hours,
112 113 "@#{syntax} should be logged as #{expected_hours} hours but was #{time.hours}"
113 114 assert_equal Date.yesterday, time.spent_on
114 115 assert time.activity.is_default?
115 116 assert time.comments.include?('r520'),
116 117 "r520 was expected in time_entry comments: #{time.comments}"
117 118 end
118 119 end
119 120
120 121 def test_ref_keywords_closing_with_timelog
121 122 Setting.commit_fix_status_id = IssueStatus.find(
122 123 :first, :conditions => ["is_closed = ?", true]).id
123 124 Setting.commit_ref_keywords = '*'
124 125 Setting.commit_fix_keywords = 'fixes , closes'
125 126 Setting.commit_logtime_enabled = '1'
126 127
127 128 c = Changeset.new(:repository => Project.find(1).repository,
128 129 :committed_on => Time.now,
129 130 :comments => 'This is a comment. Fixes #1 @4.5, #2 @1',
130 131 :user => User.find(2))
131 132 assert_difference 'TimeEntry.count', 2 do
132 133 c.scan_comment_for_issue_ids
133 134 end
134 135
135 136 assert_equal [1, 2], c.issue_ids.sort
136 137 assert Issue.find(1).closed?
137 138 assert Issue.find(2).closed?
138 139
139 140 times = TimeEntry.all(:order => 'id desc', :limit => 2)
140 141 assert_equal [1, 2], times.collect(&:issue_id).sort
141 142 end
142 143
143 144 def test_ref_keywords_any_line_start
144 145 Setting.commit_ref_keywords = '*'
145 146
146 147 c = Changeset.new(:repository => Project.find(1).repository,
147 148 :committed_on => Time.now,
148 149 :comments => '#1 is the reason of this commit')
149 150 c.scan_comment_for_issue_ids
150 151
151 152 assert_equal [1], c.issue_ids.sort
152 153 end
153 154
154 155 def test_ref_keywords_allow_brackets_around_a_issue_number
155 156 Setting.commit_ref_keywords = '*'
156 157
157 158 c = Changeset.new(:repository => Project.find(1).repository,
158 159 :committed_on => Time.now,
159 160 :comments => '[#1] Worked on this issue')
160 161 c.scan_comment_for_issue_ids
161 162
162 163 assert_equal [1], c.issue_ids.sort
163 164 end
164 165
165 166 def test_ref_keywords_allow_brackets_around_multiple_issue_numbers
166 167 Setting.commit_ref_keywords = '*'
167 168
168 169 c = Changeset.new(:repository => Project.find(1).repository,
169 170 :committed_on => Time.now,
170 171 :comments => '[#1 #2, #3] Worked on these')
171 172 c.scan_comment_for_issue_ids
172 173
173 174 assert_equal [1,2,3], c.issue_ids.sort
174 175 end
175 176
176 177 def test_commit_referencing_a_subproject_issue
177 178 c = Changeset.new(:repository => Project.find(1).repository,
178 179 :committed_on => Time.now,
179 180 :comments => 'refs #5, a subproject issue')
180 181 c.scan_comment_for_issue_ids
181 182
182 183 assert_equal [5], c.issue_ids.sort
183 184 assert c.issues.first.project != c.project
184 185 end
185 186
186 187 def test_commit_referencing_a_parent_project_issue
187 188 # repository of child project
188 189 r = Repository::Subversion.create!(
189 190 :project => Project.find(3),
190 191 :url => 'svn://localhost/test')
191 192
192 193 c = Changeset.new(:repository => r,
193 194 :committed_on => Time.now,
194 195 :comments => 'refs #2, an issue of a parent project')
195 196 c.scan_comment_for_issue_ids
196 197
197 198 assert_equal [2], c.issue_ids.sort
198 199 assert c.issues.first.project != c.project
199 200 end
200 201
201 202 def test_text_tag_revision
202 203 c = Changeset.new(:revision => '520')
203 204 assert_equal 'r520', c.text_tag
204 205 end
205 206
206 207 def test_text_tag_hash
207 208 c = Changeset.new(
208 209 :scmid => '7234cb2750b63f47bff735edc50a1c0a433c2518',
209 210 :revision => '7234cb2750b63f47bff735edc50a1c0a433c2518')
210 211 assert_equal 'commit:7234cb2750b63f47bff735edc50a1c0a433c2518', c.text_tag
211 212 end
212 213
213 214 def test_text_tag_hash_all_number
214 215 c = Changeset.new(:scmid => '0123456789', :revision => '0123456789')
215 216 assert_equal 'commit:0123456789', c.text_tag
216 217 end
217 218
218 219 def test_previous
219 220 changeset = Changeset.find_by_revision('3')
220 221 assert_equal Changeset.find_by_revision('2'), changeset.previous
221 222 end
222 223
223 224 def test_previous_nil
224 225 changeset = Changeset.find_by_revision('1')
225 226 assert_nil changeset.previous
226 227 end
227 228
228 229 def test_next
229 230 changeset = Changeset.find_by_revision('2')
230 231 assert_equal Changeset.find_by_revision('3'), changeset.next
231 232 end
232 233
233 234 def test_next_nil
234 235 changeset = Changeset.find_by_revision('10')
235 236 assert_nil changeset.next
236 237 end
237 238
238 239 def test_comments_should_be_converted_to_utf8
239 240 proj = Project.find(3)
240 241 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
241 242 str = "Texte encod\xe9 en ISO-8859-1."
242 243 str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding)
243 244 r = Repository::Bazaar.create!(
244 245 :project => proj,
245 246 :url => '/tmp/test/bazaar',
246 247 :log_encoding => 'ISO-8859-1' )
247 248 assert r
248 249 c = Changeset.new(:repository => r,
249 250 :committed_on => Time.now,
250 251 :revision => '123',
251 252 :scmid => '12345',
252 253 :comments => str)
253 254 assert( c.save )
254 255 str_utf8 = "Texte encod\xc3\xa9 en ISO-8859-1."
255 256 str_utf8.force_encoding("UTF-8") if str_utf8.respond_to?(:force_encoding)
256 257 assert_equal str_utf8, c.comments
257 258 end
258 259
259 260 def test_invalid_utf8_sequences_in_comments_should_be_replaced_latin1
260 261 proj = Project.find(3)
261 262 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
262 263 str1 = "Texte encod\xe9 en ISO-8859-1."
263 264 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
264 265 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
265 266 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
266 267 r = Repository::Bazaar.create!(
267 268 :project => proj,
268 269 :url => '/tmp/test/bazaar',
269 270 :log_encoding => 'UTF-8' )
270 271 assert r
271 272 c = Changeset.new(:repository => r,
272 273 :committed_on => Time.now,
273 274 :revision => '123',
274 275 :scmid => '12345',
275 276 :comments => str1,
276 277 :committer => str2)
277 278 assert( c.save )
278 279 assert_equal "Texte encod? en ISO-8859-1.", c.comments
279 280 assert_equal "?a?b?c?d?e test", c.committer
280 281 end
281 282
282 283 def test_invalid_utf8_sequences_in_comments_should_be_replaced_ja_jis
283 284 proj = Project.find(3)
284 285 str = "test\xb5\xfetest\xb5\xfe"
285 286 if str.respond_to?(:force_encoding)
286 287 str.force_encoding('ASCII-8BIT')
287 288 end
288 289 r = Repository::Bazaar.create!(
289 290 :project => proj,
290 291 :url => '/tmp/test/bazaar',
291 292 :log_encoding => 'ISO-2022-JP' )
292 293 assert r
293 294 c = Changeset.new(:repository => r,
294 295 :committed_on => Time.now,
295 296 :revision => '123',
296 297 :scmid => '12345',
297 298 :comments => str)
298 299 assert( c.save )
299 300 assert_equal "test??test??", c.comments
300 301 end
301 302
302 303 def test_comments_should_be_converted_all_latin1_to_utf8
303 304 s1 = "\xC2\x80"
304 305 s2 = "\xc3\x82\xc2\x80"
305 306 s4 = s2.dup
306 307 if s1.respond_to?(:force_encoding)
307 308 s3 = s1.dup
308 309 s1.force_encoding('ASCII-8BIT')
309 310 s2.force_encoding('ASCII-8BIT')
310 311 s3.force_encoding('ISO-8859-1')
311 312 s4.force_encoding('UTF-8')
312 313 assert_equal s3.encode('UTF-8'), s4
313 314 end
314 315 proj = Project.find(3)
315 316 r = Repository::Bazaar.create!(
316 317 :project => proj,
317 318 :url => '/tmp/test/bazaar',
318 319 :log_encoding => 'ISO-8859-1' )
319 320 assert r
320 321 c = Changeset.new(:repository => r,
321 322 :committed_on => Time.now,
322 323 :revision => '123',
323 324 :scmid => '12345',
324 325 :comments => s1)
325 326 assert( c.save )
326 327 assert_equal s4, c.comments
327 328 end
328 329
329 330 def test_invalid_utf8_sequences_in_paths_should_be_replaced
330 331 proj = Project.find(3)
331 332 str1 = "Texte encod\xe9 en ISO-8859-1"
332 333 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
333 334 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
334 335 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
335 336 r = Repository::Bazaar.create!(
336 337 :project => proj,
337 338 :url => '/tmp/test/bazaar',
338 339 :log_encoding => 'UTF-8' )
339 340 assert r
340 341 cs = Changeset.new(
341 342 :repository => r,
342 343 :committed_on => Time.now,
343 344 :revision => '123',
344 345 :scmid => '12345',
345 346 :comments => "test")
346 347 assert(cs.save)
347 348 ch = Change.new(
348 349 :changeset => cs,
349 350 :action => "A",
350 351 :path => str1,
351 352 :from_path => str2,
352 353 :from_revision => "345")
353 354 assert(ch.save)
354 355 assert_equal "Texte encod? en ISO-8859-1", ch.path
355 356 assert_equal "?a?b?c?d?e test", ch.from_path
356 357 end
357 358
358 359 def test_comments_nil
359 360 proj = Project.find(3)
360 361 r = Repository::Bazaar.create!(
361 362 :project => proj,
362 363 :url => '/tmp/test/bazaar',
363 364 :log_encoding => 'ISO-8859-1' )
364 365 assert r
365 366 c = Changeset.new(:repository => r,
366 367 :committed_on => Time.now,
367 368 :revision => '123',
368 369 :scmid => '12345',
369 370 :comments => nil,
370 371 :committer => nil)
371 372 assert( c.save )
372 373 assert_equal "", c.comments
373 374 assert_equal nil, c.committer
374 375 if c.comments.respond_to?(:force_encoding)
375 376 assert_equal "UTF-8", c.comments.encoding.to_s
376 377 end
377 378 end
378 379
379 380 def test_comments_empty
380 381 proj = Project.find(3)
381 382 r = Repository::Bazaar.create!(
382 383 :project => proj,
383 384 :url => '/tmp/test/bazaar',
384 385 :log_encoding => 'ISO-8859-1' )
385 386 assert r
386 387 c = Changeset.new(:repository => r,
387 388 :committed_on => Time.now,
388 389 :revision => '123',
389 390 :scmid => '12345',
390 391 :comments => "",
391 392 :committer => "")
392 393 assert( c.save )
393 394 assert_equal "", c.comments
394 395 assert_equal "", c.committer
395 396 if c.comments.respond_to?(:force_encoding)
396 397 assert_equal "UTF-8", c.comments.encoding.to_s
397 398 assert_equal "UTF-8", c.committer.encoding.to_s
398 399 end
399 400 end
400 401
401 402 def test_identifier
402 403 c = Changeset.find_by_revision('1')
403 404 assert_equal c.revision, c.identifier
404 405 end
405 406 end
General Comments 0
You need to be logged in to leave comments. Login now