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