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