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