##// END OF EJS Templates
scm: code clean up unit changeset test....
Toshi MARUYAMA -
r5353:2507bcd8e7f8
parent child
Show More
@@ -26,7 +26,7 class ChangesetTest < ActiveSupport::TestCase
26
26
27 def setup
27 def setup
28 end
28 end
29
29
30 def test_ref_keywords_any
30 def test_ref_keywords_any
31 ActionMailer::Base.deliveries.clear
31 ActionMailer::Base.deliveries.clear
32 Setting.commit_fix_status_id = IssueStatus.find(
32 Setting.commit_fix_status_id = IssueStatus.find(
@@ -35,9 +35,9 class ChangesetTest < ActiveSupport::TestCase
35 Setting.commit_ref_keywords = '*'
35 Setting.commit_ref_keywords = '*'
36 Setting.commit_fix_keywords = 'fixes , closes'
36 Setting.commit_fix_keywords = 'fixes , closes'
37
37
38 c = Changeset.new(:repository => Project.find(1).repository,
38 c = Changeset.new(:repository => Project.find(1).repository,
39 :committed_on => Time.now,
39 :committed_on => Time.now,
40 :comments => 'New commit (#2). Fixes #1')
40 :comments => 'New commit (#2). Fixes #1')
41 c.scan_comment_for_issue_ids
41 c.scan_comment_for_issue_ids
42
42
43 assert_equal [1, 2], c.issue_ids.sort
43 assert_equal [1, 2], c.issue_ids.sort
@@ -46,14 +46,14 class ChangesetTest < ActiveSupport::TestCase
46 assert_equal 90, fixed.done_ratio
46 assert_equal 90, fixed.done_ratio
47 assert_equal 1, ActionMailer::Base.deliveries.size
47 assert_equal 1, ActionMailer::Base.deliveries.size
48 end
48 end
49
49
50 def test_ref_keywords
50 def test_ref_keywords
51 Setting.commit_ref_keywords = 'refs'
51 Setting.commit_ref_keywords = 'refs'
52 Setting.commit_fix_keywords = ''
52 Setting.commit_fix_keywords = ''
53
53
54 c = Changeset.new(:repository => Project.find(1).repository,
54 c = Changeset.new(:repository => Project.find(1).repository,
55 :committed_on => Time.now,
55 :committed_on => Time.now,
56 :comments => 'Ignores #2. Refs #1')
56 :comments => 'Ignores #2. Refs #1')
57 c.scan_comment_for_issue_ids
57 c.scan_comment_for_issue_ids
58
58
59 assert_equal [1], c.issue_ids.sort
59 assert_equal [1], c.issue_ids.sort
@@ -63,9 +63,9 class ChangesetTest < ActiveSupport::TestCase
63 Setting.commit_ref_keywords = '*'
63 Setting.commit_ref_keywords = '*'
64 Setting.commit_fix_keywords = ''
64 Setting.commit_fix_keywords = ''
65
65
66 c = Changeset.new(:repository => Project.find(1).repository,
66 c = Changeset.new(:repository => Project.find(1).repository,
67 :committed_on => Time.now,
67 :committed_on => Time.now,
68 :comments => 'Ignores #2. Refs #1')
68 :comments => 'Ignores #2. Refs #1')
69 c.scan_comment_for_issue_ids
69 c.scan_comment_for_issue_ids
70
70
71 assert_equal [1, 2], c.issue_ids.sort
71 assert_equal [1, 2], c.issue_ids.sort
@@ -90,16 +90,16 class ChangesetTest < ActiveSupport::TestCase
90 '3,25' => 3.25,
90 '3,25' => 3.25,
91 '3,25h' => 3.25,
91 '3,25h' => 3.25,
92 }.each do |syntax, expected_hours|
92 }.each do |syntax, expected_hours|
93 c = Changeset.new(:repository => Project.find(1).repository,
93 c = Changeset.new(:repository => Project.find(1).repository,
94 :committed_on => 24.hours.ago,
94 :committed_on => 24.hours.ago,
95 :comments => "Worked on this issue #1 @#{syntax}",
95 :comments => "Worked on this issue #1 @#{syntax}",
96 :revision => '520',
96 :revision => '520',
97 :user => User.find(2))
97 :user => User.find(2))
98 assert_difference 'TimeEntry.count' do
98 assert_difference 'TimeEntry.count' do
99 c.scan_comment_for_issue_ids
99 c.scan_comment_for_issue_ids
100 end
100 end
101 assert_equal [1], c.issue_ids.sort
101 assert_equal [1], c.issue_ids.sort
102
102
103 time = TimeEntry.first(:order => 'id desc')
103 time = TimeEntry.first(:order => 'id desc')
104 assert_equal 1, time.issue_id
104 assert_equal 1, time.issue_id
105 assert_equal 1, time.project_id
105 assert_equal 1, time.project_id
@@ -112,7 +112,7 class ChangesetTest < ActiveSupport::TestCase
112 "r520 was expected in time_entry comments: #{time.comments}"
112 "r520 was expected in time_entry comments: #{time.comments}"
113 end
113 end
114 end
114 end
115
115
116 def test_ref_keywords_closing_with_timelog
116 def test_ref_keywords_closing_with_timelog
117 Setting.commit_fix_status_id = IssueStatus.find(
117 Setting.commit_fix_status_id = IssueStatus.find(
118 :first, :conditions => ["is_closed = ?", true]).id
118 :first, :conditions => ["is_closed = ?", true]).id
@@ -120,14 +120,14 class ChangesetTest < ActiveSupport::TestCase
120 Setting.commit_fix_keywords = 'fixes , closes'
120 Setting.commit_fix_keywords = 'fixes , closes'
121 Setting.commit_logtime_enabled = '1'
121 Setting.commit_logtime_enabled = '1'
122
122
123 c = Changeset.new(:repository => Project.find(1).repository,
123 c = Changeset.new(:repository => Project.find(1).repository,
124 :committed_on => Time.now,
124 :committed_on => Time.now,
125 :comments => 'This is a comment. Fixes #1 @4.5, #2 @1',
125 :comments => 'This is a comment. Fixes #1 @4.5, #2 @1',
126 :user => User.find(2))
126 :user => User.find(2))
127 assert_difference 'TimeEntry.count', 2 do
127 assert_difference 'TimeEntry.count', 2 do
128 c.scan_comment_for_issue_ids
128 c.scan_comment_for_issue_ids
129 end
129 end
130
130
131 assert_equal [1, 2], c.issue_ids.sort
131 assert_equal [1, 2], c.issue_ids.sort
132 assert Issue.find(1).closed?
132 assert Issue.find(1).closed?
133 assert Issue.find(2).closed?
133 assert Issue.find(2).closed?
@@ -135,13 +135,13 class ChangesetTest < ActiveSupport::TestCase
135 times = TimeEntry.all(:order => 'id desc', :limit => 2)
135 times = TimeEntry.all(:order => 'id desc', :limit => 2)
136 assert_equal [1, 2], times.collect(&:issue_id).sort
136 assert_equal [1, 2], times.collect(&:issue_id).sort
137 end
137 end
138
138
139 def test_ref_keywords_any_line_start
139 def test_ref_keywords_any_line_start
140 Setting.commit_ref_keywords = '*'
140 Setting.commit_ref_keywords = '*'
141
141
142 c = Changeset.new(:repository => Project.find(1).repository,
142 c = Changeset.new(:repository => Project.find(1).repository,
143 :committed_on => Time.now,
143 :committed_on => Time.now,
144 :comments => '#1 is the reason of this commit')
144 :comments => '#1 is the reason of this commit')
145 c.scan_comment_for_issue_ids
145 c.scan_comment_for_issue_ids
146
146
147 assert_equal [1], c.issue_ids.sort
147 assert_equal [1], c.issue_ids.sort
@@ -150,9 +150,9 class ChangesetTest < ActiveSupport::TestCase
150 def test_ref_keywords_allow_brackets_around_a_issue_number
150 def test_ref_keywords_allow_brackets_around_a_issue_number
151 Setting.commit_ref_keywords = '*'
151 Setting.commit_ref_keywords = '*'
152
152
153 c = Changeset.new(:repository => Project.find(1).repository,
153 c = Changeset.new(:repository => Project.find(1).repository,
154 :committed_on => Time.now,
154 :committed_on => Time.now,
155 :comments => '[#1] Worked on this issue')
155 :comments => '[#1] Worked on this issue')
156 c.scan_comment_for_issue_ids
156 c.scan_comment_for_issue_ids
157
157
158 assert_equal [1], c.issue_ids.sort
158 assert_equal [1], c.issue_ids.sort
@@ -161,20 +161,20 class ChangesetTest < ActiveSupport::TestCase
161 def test_ref_keywords_allow_brackets_around_multiple_issue_numbers
161 def test_ref_keywords_allow_brackets_around_multiple_issue_numbers
162 Setting.commit_ref_keywords = '*'
162 Setting.commit_ref_keywords = '*'
163
163
164 c = Changeset.new(:repository => Project.find(1).repository,
164 c = Changeset.new(:repository => Project.find(1).repository,
165 :committed_on => Time.now,
165 :committed_on => Time.now,
166 :comments => '[#1 #2, #3] Worked on these')
166 :comments => '[#1 #2, #3] Worked on these')
167 c.scan_comment_for_issue_ids
167 c.scan_comment_for_issue_ids
168
168
169 assert_equal [1,2,3], c.issue_ids.sort
169 assert_equal [1,2,3], c.issue_ids.sort
170 end
170 end
171
171
172 def test_commit_referencing_a_subproject_issue
172 def test_commit_referencing_a_subproject_issue
173 c = Changeset.new(:repository => Project.find(1).repository,
173 c = Changeset.new(:repository => Project.find(1).repository,
174 :committed_on => Time.now,
174 :committed_on => Time.now,
175 :comments => 'refs #5, a subproject issue')
175 :comments => 'refs #5, a subproject issue')
176 c.scan_comment_for_issue_ids
176 c.scan_comment_for_issue_ids
177
177
178 assert_equal [5], c.issue_ids.sort
178 assert_equal [5], c.issue_ids.sort
179 assert c.issues.first.project != c.project
179 assert c.issues.first.project != c.project
180 end
180 end
@@ -185,9 +185,9 class ChangesetTest < ActiveSupport::TestCase
185 :project => Project.find(3),
185 :project => Project.find(3),
186 :url => 'svn://localhost/test')
186 :url => 'svn://localhost/test')
187
187
188 c = Changeset.new(:repository => r,
188 c = Changeset.new(:repository => r,
189 :committed_on => Time.now,
189 :committed_on => Time.now,
190 :comments => 'refs #2, an issue of a parent project')
190 :comments => 'refs #2, an issue of a parent project')
191 c.scan_comment_for_issue_ids
191 c.scan_comment_for_issue_ids
192
192
193 assert_equal [2], c.issue_ids.sort
193 assert_equal [2], c.issue_ids.sort
@@ -232,133 +232,137 class ChangesetTest < ActiveSupport::TestCase
232 end
232 end
233
233
234 def test_comments_should_be_converted_to_utf8
234 def test_comments_should_be_converted_to_utf8
235 proj = Project.find(3)
235 proj = Project.find(3)
236 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
236 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
237 str = "Texte encod\xe9 en ISO-8859-1."
237 str = "Texte encod\xe9 en ISO-8859-1."
238 str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding)
238 str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding)
239 r = Repository::Bazaar.create!(
239 r = Repository::Bazaar.create!(
240 :project => proj, :url => '/tmp/test/bazaar',
240 :project => proj,
241 :url => '/tmp/test/bazaar',
241 :log_encoding => 'ISO-8859-1' )
242 :log_encoding => 'ISO-8859-1' )
242 assert r
243 assert r
243 c = Changeset.new(:repository => r,
244 c = Changeset.new(:repository => r,
244 :committed_on => Time.now,
245 :committed_on => Time.now,
245 :revision => '123',
246 :revision => '123',
246 :scmid => '12345',
247 :scmid => '12345',
247 :comments => str)
248 :comments => str)
248 assert( c.save )
249 assert( c.save )
249 str_utf8 = "Texte encod\xc3\xa9 en ISO-8859-1."
250 str_utf8 = "Texte encod\xc3\xa9 en ISO-8859-1."
250 str_utf8.force_encoding("UTF-8") if str_utf8.respond_to?(:force_encoding)
251 str_utf8.force_encoding("UTF-8") if str_utf8.respond_to?(:force_encoding)
251 assert_equal str_utf8, c.comments
252 assert_equal str_utf8, c.comments
252 end
253 end
253
254
254 def test_invalid_utf8_sequences_in_comments_should_be_replaced_latin1
255 def test_invalid_utf8_sequences_in_comments_should_be_replaced_latin1
255 proj = Project.find(3)
256 proj = Project.find(3)
256 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
257 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
257 str1 = "Texte encod\xe9 en ISO-8859-1."
258 str1 = "Texte encod\xe9 en ISO-8859-1."
258 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e"
259 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e"
259 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
260 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
260 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
261 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
261 r = Repository::Bazaar.create!(
262 r = Repository::Bazaar.create!(
262 :project => proj,
263 :project => proj,
263 :url => '/tmp/test/bazaar',
264 :url => '/tmp/test/bazaar',
264 :log_encoding => 'UTF-8' )
265 :log_encoding => 'UTF-8' )
265 assert r
266 assert r
266 c = Changeset.new(:repository => r,
267 c = Changeset.new(:repository => r,
267 :committed_on => Time.now,
268 :committed_on => Time.now,
268 :revision => '123',
269 :revision => '123',
269 :scmid => '12345',
270 :scmid => '12345',
270 :comments => str1,
271 :comments => str1,
271 :committer => str2)
272 :committer => str2)
272 assert( c.save )
273 assert( c.save )
273 assert_equal "Texte encod? en ISO-8859-1.", c.comments
274 assert_equal "Texte encod? en ISO-8859-1.", c.comments
274 assert_equal "?a?b?c?d?e", c.committer
275 assert_equal "?a?b?c?d?e", c.committer
275 end
276 end
276
277
277 def test_invalid_utf8_sequences_in_comments_should_be_replaced_ja_jis
278 def test_invalid_utf8_sequences_in_comments_should_be_replaced_ja_jis
278 proj = Project.find(3)
279 proj = Project.find(3)
279 str = "test\xb5\xfetest\xb5\xfe"
280 str = "test\xb5\xfetest\xb5\xfe"
280 if str.respond_to?(:force_encoding)
281 if str.respond_to?(:force_encoding)
281 str.force_encoding('ASCII-8BIT')
282 str.force_encoding('ASCII-8BIT')
282 end
283 end
283 r = Repository::Bazaar.create!(
284 r = Repository::Bazaar.create!(
284 :project => proj,
285 :project => proj,
285 :url => '/tmp/test/bazaar',
286 :url => '/tmp/test/bazaar',
286 :log_encoding => 'ISO-2022-JP' )
287 :log_encoding => 'ISO-2022-JP' )
287 assert r
288 assert r
288 c = Changeset.new(:repository => r,
289 c = Changeset.new(:repository => r,
289 :committed_on => Time.now,
290 :committed_on => Time.now,
290 :revision => '123',
291 :revision => '123',
291 :scmid => '12345',
292 :scmid => '12345',
292 :comments => str)
293 :comments => str)
293 assert( c.save )
294 assert( c.save )
294 assert_equal "test??test??", c.comments
295 assert_equal "test??test??", c.comments
295 end
296 end
296
297
297 def test_comments_should_be_converted_all_latin1_to_utf8
298 def test_comments_should_be_converted_all_latin1_to_utf8
298 s1 = "\xC2\x80"
299 s1 = "\xC2\x80"
299 s2 = "\xc3\x82\xc2\x80"
300 s2 = "\xc3\x82\xc2\x80"
300 s4 = s2.dup
301 s4 = s2.dup
301 if s1.respond_to?(:force_encoding)
302 if s1.respond_to?(:force_encoding)
302 s3 = s1.dup
303 s3 = s1.dup
303 s1.force_encoding('ASCII-8BIT')
304 s1.force_encoding('ASCII-8BIT')
304 s2.force_encoding('ASCII-8BIT')
305 s2.force_encoding('ASCII-8BIT')
305 s3.force_encoding('ISO-8859-1')
306 s3.force_encoding('ISO-8859-1')
306 s4.force_encoding('UTF-8')
307 s4.force_encoding('UTF-8')
307 assert_equal s3.encode('UTF-8'), s4
308 assert_equal s3.encode('UTF-8'), s4
308 end
309 end
309 proj = Project.find(3)
310 proj = Project.find(3)
310 r = Repository::Bazaar.create!(
311 r = Repository::Bazaar.create!(
311 :project => proj, :url => '/tmp/test/bazaar',
312 :project => proj,
313 :url => '/tmp/test/bazaar',
312 :log_encoding => 'ISO-8859-1' )
314 :log_encoding => 'ISO-8859-1' )
313 assert r
315 assert r
314 c = Changeset.new(:repository => r,
316 c = Changeset.new(:repository => r,
315 :committed_on => Time.now,
317 :committed_on => Time.now,
316 :revision => '123',
318 :revision => '123',
317 :scmid => '12345',
319 :scmid => '12345',
318 :comments => s1)
320 :comments => s1)
319 assert( c.save )
321 assert( c.save )
320 assert_equal s4, c.comments
322 assert_equal s4, c.comments
321 end
323 end
322
324
323 def test_comments_nil
325 def test_comments_nil
324 proj = Project.find(3)
326 proj = Project.find(3)
325 r = Repository::Bazaar.create!(
327 r = Repository::Bazaar.create!(
326 :project => proj, :url => '/tmp/test/bazaar',
328 :project => proj,
329 :url => '/tmp/test/bazaar',
327 :log_encoding => 'ISO-8859-1' )
330 :log_encoding => 'ISO-8859-1' )
328 assert r
331 assert r
329 c = Changeset.new(:repository => r,
332 c = Changeset.new(:repository => r,
330 :committed_on => Time.now,
333 :committed_on => Time.now,
331 :revision => '123',
334 :revision => '123',
332 :scmid => '12345',
335 :scmid => '12345',
333 :comments => nil,
336 :comments => nil,
334 :committer => nil)
337 :committer => nil)
335 assert( c.save )
338 assert( c.save )
336 assert_equal "", c.comments
339 assert_equal "", c.comments
337 assert_equal nil, c.committer
340 assert_equal nil, c.committer
338 if c.comments.respond_to?(:force_encoding)
341 if c.comments.respond_to?(:force_encoding)
339 assert_equal "UTF-8", c.comments.encoding.to_s
342 assert_equal "UTF-8", c.comments.encoding.to_s
340 end
343 end
341 end
344 end
342
345
343 def test_comments_empty
346 def test_comments_empty
344 proj = Project.find(3)
347 proj = Project.find(3)
345 r = Repository::Bazaar.create!(
348 r = Repository::Bazaar.create!(
346 :project => proj, :url => '/tmp/test/bazaar',
349 :project => proj,
350 :url => '/tmp/test/bazaar',
347 :log_encoding => 'ISO-8859-1' )
351 :log_encoding => 'ISO-8859-1' )
348 assert r
352 assert r
349 c = Changeset.new(:repository => r,
353 c = Changeset.new(:repository => r,
350 :committed_on => Time.now,
354 :committed_on => Time.now,
351 :revision => '123',
355 :revision => '123',
352 :scmid => '12345',
356 :scmid => '12345',
353 :comments => "",
357 :comments => "",
354 :committer => "")
358 :committer => "")
355 assert( c.save )
359 assert( c.save )
356 assert_equal "", c.comments
360 assert_equal "", c.comments
357 assert_equal "", c.committer
361 assert_equal "", c.committer
358 if c.comments.respond_to?(:force_encoding)
362 if c.comments.respond_to?(:force_encoding)
359 assert_equal "UTF-8", c.comments.encoding.to_s
363 assert_equal "UTF-8", c.comments.encoding.to_s
360 assert_equal "UTF-8", c.committer.encoding.to_s
364 assert_equal "UTF-8", c.committer.encoding.to_s
361 end
365 end
362 end
366 end
363
367
364 def test_identifier
368 def test_identifier
General Comments 0
You need to be logged in to leave comments. Login now