##// END OF EJS Templates
scm: add dummy revision at test_ref_keywords_allow_brackets_around_a_issue_number of unit changeset test....
Toshi MARUYAMA -
r6612:c26be908bfe5
parent child
Show More
@@ -1,402 +1,402
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
154 c = Changeset.new(:repository => Project.find(1).repository,
153 c = Changeset.new(:repository => Project.find(1).repository,
155 :committed_on => Time.now,
154 :committed_on => Time.now,
156 :comments => '[#1] Worked on this issue')
155 :comments => '[#1] Worked on this issue',
156 :revision => '12345')
157 c.scan_comment_for_issue_ids
157 c.scan_comment_for_issue_ids
158
158
159 assert_equal [1], c.issue_ids.sort
159 assert_equal [1], c.issue_ids.sort
160 end
160 end
161
161
162 def test_ref_keywords_allow_brackets_around_multiple_issue_numbers
162 def test_ref_keywords_allow_brackets_around_multiple_issue_numbers
163 Setting.commit_ref_keywords = '*'
163 Setting.commit_ref_keywords = '*'
164
164
165 c = Changeset.new(:repository => Project.find(1).repository,
165 c = Changeset.new(:repository => Project.find(1).repository,
166 :committed_on => Time.now,
166 :committed_on => Time.now,
167 :comments => '[#1 #2, #3] Worked on these')
167 :comments => '[#1 #2, #3] Worked on these')
168 c.scan_comment_for_issue_ids
168 c.scan_comment_for_issue_ids
169
169
170 assert_equal [1,2,3], c.issue_ids.sort
170 assert_equal [1,2,3], c.issue_ids.sort
171 end
171 end
172
172
173 def test_commit_referencing_a_subproject_issue
173 def test_commit_referencing_a_subproject_issue
174 c = Changeset.new(:repository => Project.find(1).repository,
174 c = Changeset.new(:repository => Project.find(1).repository,
175 :committed_on => Time.now,
175 :committed_on => Time.now,
176 :comments => 'refs #5, a subproject issue')
176 :comments => 'refs #5, a subproject issue')
177 c.scan_comment_for_issue_ids
177 c.scan_comment_for_issue_ids
178
178
179 assert_equal [5], c.issue_ids.sort
179 assert_equal [5], c.issue_ids.sort
180 assert c.issues.first.project != c.project
180 assert c.issues.first.project != c.project
181 end
181 end
182
182
183 def test_commit_referencing_a_parent_project_issue
183 def test_commit_referencing_a_parent_project_issue
184 # repository of child project
184 # repository of child project
185 r = Repository::Subversion.create!(
185 r = Repository::Subversion.create!(
186 :project => Project.find(3),
186 :project => Project.find(3),
187 :url => 'svn://localhost/test')
187 :url => 'svn://localhost/test')
188
188
189 c = Changeset.new(:repository => r,
189 c = Changeset.new(:repository => r,
190 :committed_on => Time.now,
190 :committed_on => Time.now,
191 :comments => 'refs #2, an issue of a parent project')
191 :comments => 'refs #2, an issue of a parent project')
192 c.scan_comment_for_issue_ids
192 c.scan_comment_for_issue_ids
193
193
194 assert_equal [2], c.issue_ids.sort
194 assert_equal [2], c.issue_ids.sort
195 assert c.issues.first.project != c.project
195 assert c.issues.first.project != c.project
196 end
196 end
197
197
198 def test_text_tag_revision
198 def test_text_tag_revision
199 c = Changeset.new(:revision => '520')
199 c = Changeset.new(:revision => '520')
200 assert_equal 'r520', c.text_tag
200 assert_equal 'r520', c.text_tag
201 end
201 end
202
202
203 def test_text_tag_hash
203 def test_text_tag_hash
204 c = Changeset.new(
204 c = Changeset.new(
205 :scmid => '7234cb2750b63f47bff735edc50a1c0a433c2518',
205 :scmid => '7234cb2750b63f47bff735edc50a1c0a433c2518',
206 :revision => '7234cb2750b63f47bff735edc50a1c0a433c2518')
206 :revision => '7234cb2750b63f47bff735edc50a1c0a433c2518')
207 assert_equal 'commit:7234cb2750b63f47bff735edc50a1c0a433c2518', c.text_tag
207 assert_equal 'commit:7234cb2750b63f47bff735edc50a1c0a433c2518', c.text_tag
208 end
208 end
209
209
210 def test_text_tag_hash_all_number
210 def test_text_tag_hash_all_number
211 c = Changeset.new(:scmid => '0123456789', :revision => '0123456789')
211 c = Changeset.new(:scmid => '0123456789', :revision => '0123456789')
212 assert_equal 'commit:0123456789', c.text_tag
212 assert_equal 'commit:0123456789', c.text_tag
213 end
213 end
214
214
215 def test_previous
215 def test_previous
216 changeset = Changeset.find_by_revision('3')
216 changeset = Changeset.find_by_revision('3')
217 assert_equal Changeset.find_by_revision('2'), changeset.previous
217 assert_equal Changeset.find_by_revision('2'), changeset.previous
218 end
218 end
219
219
220 def test_previous_nil
220 def test_previous_nil
221 changeset = Changeset.find_by_revision('1')
221 changeset = Changeset.find_by_revision('1')
222 assert_nil changeset.previous
222 assert_nil changeset.previous
223 end
223 end
224
224
225 def test_next
225 def test_next
226 changeset = Changeset.find_by_revision('2')
226 changeset = Changeset.find_by_revision('2')
227 assert_equal Changeset.find_by_revision('3'), changeset.next
227 assert_equal Changeset.find_by_revision('3'), changeset.next
228 end
228 end
229
229
230 def test_next_nil
230 def test_next_nil
231 changeset = Changeset.find_by_revision('10')
231 changeset = Changeset.find_by_revision('10')
232 assert_nil changeset.next
232 assert_nil changeset.next
233 end
233 end
234
234
235 def test_comments_should_be_converted_to_utf8
235 def test_comments_should_be_converted_to_utf8
236 proj = Project.find(3)
236 proj = Project.find(3)
237 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
237 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
238 str = "Texte encod\xe9 en ISO-8859-1."
238 str = "Texte encod\xe9 en ISO-8859-1."
239 str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding)
239 str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding)
240 r = Repository::Bazaar.create!(
240 r = Repository::Bazaar.create!(
241 :project => proj,
241 :project => proj,
242 :url => '/tmp/test/bazaar',
242 :url => '/tmp/test/bazaar',
243 :log_encoding => 'ISO-8859-1' )
243 :log_encoding => 'ISO-8859-1' )
244 assert r
244 assert r
245 c = Changeset.new(:repository => r,
245 c = Changeset.new(:repository => r,
246 :committed_on => Time.now,
246 :committed_on => Time.now,
247 :revision => '123',
247 :revision => '123',
248 :scmid => '12345',
248 :scmid => '12345',
249 :comments => str)
249 :comments => str)
250 assert( c.save )
250 assert( c.save )
251 str_utf8 = "Texte encod\xc3\xa9 en ISO-8859-1."
251 str_utf8 = "Texte encod\xc3\xa9 en ISO-8859-1."
252 str_utf8.force_encoding("UTF-8") if str_utf8.respond_to?(:force_encoding)
252 str_utf8.force_encoding("UTF-8") if str_utf8.respond_to?(:force_encoding)
253 assert_equal str_utf8, c.comments
253 assert_equal str_utf8, c.comments
254 end
254 end
255
255
256 def test_invalid_utf8_sequences_in_comments_should_be_replaced_latin1
256 def test_invalid_utf8_sequences_in_comments_should_be_replaced_latin1
257 proj = Project.find(3)
257 proj = Project.find(3)
258 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
258 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
259 str1 = "Texte encod\xe9 en ISO-8859-1."
259 str1 = "Texte encod\xe9 en ISO-8859-1."
260 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
260 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
261 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
261 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
262 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
262 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
263 r = Repository::Bazaar.create!(
263 r = Repository::Bazaar.create!(
264 :project => proj,
264 :project => proj,
265 :url => '/tmp/test/bazaar',
265 :url => '/tmp/test/bazaar',
266 :log_encoding => 'UTF-8' )
266 :log_encoding => 'UTF-8' )
267 assert r
267 assert r
268 c = Changeset.new(:repository => r,
268 c = Changeset.new(:repository => r,
269 :committed_on => Time.now,
269 :committed_on => Time.now,
270 :revision => '123',
270 :revision => '123',
271 :scmid => '12345',
271 :scmid => '12345',
272 :comments => str1,
272 :comments => str1,
273 :committer => str2)
273 :committer => str2)
274 assert( c.save )
274 assert( c.save )
275 assert_equal "Texte encod? en ISO-8859-1.", c.comments
275 assert_equal "Texte encod? en ISO-8859-1.", c.comments
276 assert_equal "?a?b?c?d?e test", c.committer
276 assert_equal "?a?b?c?d?e test", c.committer
277 end
277 end
278
278
279 def test_invalid_utf8_sequences_in_comments_should_be_replaced_ja_jis
279 def test_invalid_utf8_sequences_in_comments_should_be_replaced_ja_jis
280 proj = Project.find(3)
280 proj = Project.find(3)
281 str = "test\xb5\xfetest\xb5\xfe"
281 str = "test\xb5\xfetest\xb5\xfe"
282 if str.respond_to?(:force_encoding)
282 if str.respond_to?(:force_encoding)
283 str.force_encoding('ASCII-8BIT')
283 str.force_encoding('ASCII-8BIT')
284 end
284 end
285 r = Repository::Bazaar.create!(
285 r = Repository::Bazaar.create!(
286 :project => proj,
286 :project => proj,
287 :url => '/tmp/test/bazaar',
287 :url => '/tmp/test/bazaar',
288 :log_encoding => 'ISO-2022-JP' )
288 :log_encoding => 'ISO-2022-JP' )
289 assert r
289 assert r
290 c = Changeset.new(:repository => r,
290 c = Changeset.new(:repository => r,
291 :committed_on => Time.now,
291 :committed_on => Time.now,
292 :revision => '123',
292 :revision => '123',
293 :scmid => '12345',
293 :scmid => '12345',
294 :comments => str)
294 :comments => str)
295 assert( c.save )
295 assert( c.save )
296 assert_equal "test??test??", c.comments
296 assert_equal "test??test??", c.comments
297 end
297 end
298
298
299 def test_comments_should_be_converted_all_latin1_to_utf8
299 def test_comments_should_be_converted_all_latin1_to_utf8
300 s1 = "\xC2\x80"
300 s1 = "\xC2\x80"
301 s2 = "\xc3\x82\xc2\x80"
301 s2 = "\xc3\x82\xc2\x80"
302 s4 = s2.dup
302 s4 = s2.dup
303 if s1.respond_to?(:force_encoding)
303 if s1.respond_to?(:force_encoding)
304 s3 = s1.dup
304 s3 = s1.dup
305 s1.force_encoding('ASCII-8BIT')
305 s1.force_encoding('ASCII-8BIT')
306 s2.force_encoding('ASCII-8BIT')
306 s2.force_encoding('ASCII-8BIT')
307 s3.force_encoding('ISO-8859-1')
307 s3.force_encoding('ISO-8859-1')
308 s4.force_encoding('UTF-8')
308 s4.force_encoding('UTF-8')
309 assert_equal s3.encode('UTF-8'), s4
309 assert_equal s3.encode('UTF-8'), s4
310 end
310 end
311 proj = Project.find(3)
311 proj = Project.find(3)
312 r = Repository::Bazaar.create!(
312 r = Repository::Bazaar.create!(
313 :project => proj,
313 :project => proj,
314 :url => '/tmp/test/bazaar',
314 :url => '/tmp/test/bazaar',
315 :log_encoding => 'ISO-8859-1' )
315 :log_encoding => 'ISO-8859-1' )
316 assert r
316 assert r
317 c = Changeset.new(:repository => r,
317 c = Changeset.new(:repository => r,
318 :committed_on => Time.now,
318 :committed_on => Time.now,
319 :revision => '123',
319 :revision => '123',
320 :scmid => '12345',
320 :scmid => '12345',
321 :comments => s1)
321 :comments => s1)
322 assert( c.save )
322 assert( c.save )
323 assert_equal s4, c.comments
323 assert_equal s4, c.comments
324 end
324 end
325
325
326 def test_invalid_utf8_sequences_in_paths_should_be_replaced
326 def test_invalid_utf8_sequences_in_paths_should_be_replaced
327 proj = Project.find(3)
327 proj = Project.find(3)
328 str1 = "Texte encod\xe9 en ISO-8859-1"
328 str1 = "Texte encod\xe9 en ISO-8859-1"
329 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
329 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
330 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
330 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
331 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
331 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
332 r = Repository::Bazaar.create!(
332 r = Repository::Bazaar.create!(
333 :project => proj,
333 :project => proj,
334 :url => '/tmp/test/bazaar',
334 :url => '/tmp/test/bazaar',
335 :log_encoding => 'UTF-8' )
335 :log_encoding => 'UTF-8' )
336 assert r
336 assert r
337 cs = Changeset.new(
337 cs = Changeset.new(
338 :repository => r,
338 :repository => r,
339 :committed_on => Time.now,
339 :committed_on => Time.now,
340 :revision => '123',
340 :revision => '123',
341 :scmid => '12345',
341 :scmid => '12345',
342 :comments => "test")
342 :comments => "test")
343 assert(cs.save)
343 assert(cs.save)
344 ch = Change.new(
344 ch = Change.new(
345 :changeset => cs,
345 :changeset => cs,
346 :action => "A",
346 :action => "A",
347 :path => str1,
347 :path => str1,
348 :from_path => str2,
348 :from_path => str2,
349 :from_revision => "345")
349 :from_revision => "345")
350 assert(ch.save)
350 assert(ch.save)
351 assert_equal "Texte encod? en ISO-8859-1", ch.path
351 assert_equal "Texte encod? en ISO-8859-1", ch.path
352 assert_equal "?a?b?c?d?e test", ch.from_path
352 assert_equal "?a?b?c?d?e test", ch.from_path
353 end
353 end
354
354
355 def test_comments_nil
355 def test_comments_nil
356 proj = Project.find(3)
356 proj = Project.find(3)
357 r = Repository::Bazaar.create!(
357 r = Repository::Bazaar.create!(
358 :project => proj,
358 :project => proj,
359 :url => '/tmp/test/bazaar',
359 :url => '/tmp/test/bazaar',
360 :log_encoding => 'ISO-8859-1' )
360 :log_encoding => 'ISO-8859-1' )
361 assert r
361 assert r
362 c = Changeset.new(:repository => r,
362 c = Changeset.new(:repository => r,
363 :committed_on => Time.now,
363 :committed_on => Time.now,
364 :revision => '123',
364 :revision => '123',
365 :scmid => '12345',
365 :scmid => '12345',
366 :comments => nil,
366 :comments => nil,
367 :committer => nil)
367 :committer => nil)
368 assert( c.save )
368 assert( c.save )
369 assert_equal "", c.comments
369 assert_equal "", c.comments
370 assert_equal nil, c.committer
370 assert_equal nil, c.committer
371 if c.comments.respond_to?(:force_encoding)
371 if c.comments.respond_to?(:force_encoding)
372 assert_equal "UTF-8", c.comments.encoding.to_s
372 assert_equal "UTF-8", c.comments.encoding.to_s
373 end
373 end
374 end
374 end
375
375
376 def test_comments_empty
376 def test_comments_empty
377 proj = Project.find(3)
377 proj = Project.find(3)
378 r = Repository::Bazaar.create!(
378 r = Repository::Bazaar.create!(
379 :project => proj,
379 :project => proj,
380 :url => '/tmp/test/bazaar',
380 :url => '/tmp/test/bazaar',
381 :log_encoding => 'ISO-8859-1' )
381 :log_encoding => 'ISO-8859-1' )
382 assert r
382 assert r
383 c = Changeset.new(:repository => r,
383 c = Changeset.new(:repository => r,
384 :committed_on => Time.now,
384 :committed_on => Time.now,
385 :revision => '123',
385 :revision => '123',
386 :scmid => '12345',
386 :scmid => '12345',
387 :comments => "",
387 :comments => "",
388 :committer => "")
388 :committer => "")
389 assert( c.save )
389 assert( c.save )
390 assert_equal "", c.comments
390 assert_equal "", c.comments
391 assert_equal "", c.committer
391 assert_equal "", c.committer
392 if c.comments.respond_to?(:force_encoding)
392 if c.comments.respond_to?(:force_encoding)
393 assert_equal "UTF-8", c.comments.encoding.to_s
393 assert_equal "UTF-8", c.comments.encoding.to_s
394 assert_equal "UTF-8", c.committer.encoding.to_s
394 assert_equal "UTF-8", c.committer.encoding.to_s
395 end
395 end
396 end
396 end
397
397
398 def test_identifier
398 def test_identifier
399 c = Changeset.find_by_revision('1')
399 c = Changeset.find_by_revision('1')
400 assert_equal c.revision, c.identifier
400 assert_equal c.revision, c.identifier
401 end
401 end
402 end
402 end
General Comments 0
You need to be logged in to leave comments. Login now