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