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