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