##// END OF EJS Templates
set default_language en at test_commit_closing_a_subproject_issue of unit changeset test...
Toshi MARUYAMA -
r10270:cf52a6ccb43a
parent child
Show More
@@ -1,478 +1,479
1 # encoding: utf-8
1 # encoding: utf-8
2 #
2 #
3 # Redmine - project management software
3 # Redmine - project management software
4 # Copyright (C) 2006-2012 Jean-Philippe Lang
4 # Copyright (C) 2006-2012 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 assert c.save
167 assert c.save
168 assert_equal [1,2,3], c.issue_ids.sort
168 assert_equal [1,2,3], c.issue_ids.sort
169 end
169 end
170
170
171 def test_commit_referencing_a_subproject_issue
171 def test_commit_referencing_a_subproject_issue
172 c = Changeset.new(:repository => Project.find(1).repository,
172 c = Changeset.new(:repository => Project.find(1).repository,
173 :committed_on => Time.now,
173 :committed_on => Time.now,
174 :comments => 'refs #5, a subproject issue',
174 :comments => 'refs #5, a subproject issue',
175 :revision => '12345')
175 :revision => '12345')
176 assert c.save
176 assert c.save
177 assert_equal [5], c.issue_ids.sort
177 assert_equal [5], c.issue_ids.sort
178 assert c.issues.first.project != c.project
178 assert c.issues.first.project != c.project
179 end
179 end
180
180
181 def test_commit_closing_a_subproject_issue
181 def test_commit_closing_a_subproject_issue
182 with_settings :commit_fix_status_id => 5, :commit_fix_keywords => 'closes' do
182 with_settings :commit_fix_status_id => 5, :commit_fix_keywords => 'closes',
183 :default_language => 'en' do
183 issue = Issue.find(5)
184 issue = Issue.find(5)
184 assert !issue.closed?
185 assert !issue.closed?
185 assert_difference 'Journal.count' do
186 assert_difference 'Journal.count' do
186 c = Changeset.new(:repository => Project.find(1).repository,
187 c = Changeset.new(:repository => Project.find(1).repository,
187 :committed_on => Time.now,
188 :committed_on => Time.now,
188 :comments => 'closes #5, a subproject issue',
189 :comments => 'closes #5, a subproject issue',
189 :revision => '12345')
190 :revision => '12345')
190 assert c.save
191 assert c.save
191 end
192 end
192 assert issue.reload.closed?
193 assert issue.reload.closed?
193 journal = Journal.first(:order => 'id DESC')
194 journal = Journal.first(:order => 'id DESC')
194 assert_equal issue, journal.issue
195 assert_equal issue, journal.issue
195 assert_include "Applied in changeset ecookbook:r12345.", journal.notes
196 assert_include "Applied in changeset ecookbook:r12345.", journal.notes
196 end
197 end
197 end
198 end
198
199
199 def test_commit_referencing_a_parent_project_issue
200 def test_commit_referencing_a_parent_project_issue
200 # repository of child project
201 # repository of child project
201 r = Repository::Subversion.create!(
202 r = Repository::Subversion.create!(
202 :project => Project.find(3),
203 :project => Project.find(3),
203 :url => 'svn://localhost/test')
204 :url => 'svn://localhost/test')
204 c = Changeset.new(:repository => r,
205 c = Changeset.new(:repository => r,
205 :committed_on => Time.now,
206 :committed_on => Time.now,
206 :comments => 'refs #2, an issue of a parent project',
207 :comments => 'refs #2, an issue of a parent project',
207 :revision => '12345')
208 :revision => '12345')
208 assert c.save
209 assert c.save
209 assert_equal [2], c.issue_ids.sort
210 assert_equal [2], c.issue_ids.sort
210 assert c.issues.first.project != c.project
211 assert c.issues.first.project != c.project
211 end
212 end
212
213
213 def test_commit_referencing_a_project_with_commit_cross_project_ref_disabled
214 def test_commit_referencing_a_project_with_commit_cross_project_ref_disabled
214 r = Repository::Subversion.create!(
215 r = Repository::Subversion.create!(
215 :project => Project.find(3),
216 :project => Project.find(3),
216 :url => 'svn://localhost/test')
217 :url => 'svn://localhost/test')
217
218
218 with_settings :commit_cross_project_ref => '0' do
219 with_settings :commit_cross_project_ref => '0' do
219 c = Changeset.new(:repository => r,
220 c = Changeset.new(:repository => r,
220 :committed_on => Time.now,
221 :committed_on => Time.now,
221 :comments => 'refs #4, an issue of a different project',
222 :comments => 'refs #4, an issue of a different project',
222 :revision => '12345')
223 :revision => '12345')
223 assert c.save
224 assert c.save
224 assert_equal [], c.issue_ids
225 assert_equal [], c.issue_ids
225 end
226 end
226 end
227 end
227
228
228 def test_commit_referencing_a_project_with_commit_cross_project_ref_enabled
229 def test_commit_referencing_a_project_with_commit_cross_project_ref_enabled
229 r = Repository::Subversion.create!(
230 r = Repository::Subversion.create!(
230 :project => Project.find(3),
231 :project => Project.find(3),
231 :url => 'svn://localhost/test')
232 :url => 'svn://localhost/test')
232
233
233 with_settings :commit_cross_project_ref => '1' do
234 with_settings :commit_cross_project_ref => '1' do
234 c = Changeset.new(:repository => r,
235 c = Changeset.new(:repository => r,
235 :committed_on => Time.now,
236 :committed_on => Time.now,
236 :comments => 'refs #4, an issue of a different project',
237 :comments => 'refs #4, an issue of a different project',
237 :revision => '12345')
238 :revision => '12345')
238 assert c.save
239 assert c.save
239 assert_equal [4], c.issue_ids
240 assert_equal [4], c.issue_ids
240 end
241 end
241 end
242 end
242
243
243 def test_text_tag_revision
244 def test_text_tag_revision
244 c = Changeset.new(:revision => '520')
245 c = Changeset.new(:revision => '520')
245 assert_equal 'r520', c.text_tag
246 assert_equal 'r520', c.text_tag
246 end
247 end
247
248
248 def test_text_tag_revision_with_same_project
249 def test_text_tag_revision_with_same_project
249 c = Changeset.new(:revision => '520', :repository => Project.find(1).repository)
250 c = Changeset.new(:revision => '520', :repository => Project.find(1).repository)
250 assert_equal 'r520', c.text_tag(Project.find(1))
251 assert_equal 'r520', c.text_tag(Project.find(1))
251 end
252 end
252
253
253 def test_text_tag_revision_with_different_project
254 def test_text_tag_revision_with_different_project
254 c = Changeset.new(:revision => '520', :repository => Project.find(1).repository)
255 c = Changeset.new(:revision => '520', :repository => Project.find(1).repository)
255 assert_equal 'ecookbook:r520', c.text_tag(Project.find(2))
256 assert_equal 'ecookbook:r520', c.text_tag(Project.find(2))
256 end
257 end
257
258
258 def test_text_tag_revision_with_repository_identifier
259 def test_text_tag_revision_with_repository_identifier
259 r = Repository::Subversion.create!(
260 r = Repository::Subversion.create!(
260 :project_id => 1,
261 :project_id => 1,
261 :url => 'svn://localhost/test',
262 :url => 'svn://localhost/test',
262 :identifier => 'documents')
263 :identifier => 'documents')
263
264
264 c = Changeset.new(:revision => '520', :repository => r)
265 c = Changeset.new(:revision => '520', :repository => r)
265 assert_equal 'documents|r520', c.text_tag
266 assert_equal 'documents|r520', c.text_tag
266 assert_equal 'ecookbook:documents|r520', c.text_tag(Project.find(2))
267 assert_equal 'ecookbook:documents|r520', c.text_tag(Project.find(2))
267 end
268 end
268
269
269 def test_text_tag_hash
270 def test_text_tag_hash
270 c = Changeset.new(
271 c = Changeset.new(
271 :scmid => '7234cb2750b63f47bff735edc50a1c0a433c2518',
272 :scmid => '7234cb2750b63f47bff735edc50a1c0a433c2518',
272 :revision => '7234cb2750b63f47bff735edc50a1c0a433c2518')
273 :revision => '7234cb2750b63f47bff735edc50a1c0a433c2518')
273 assert_equal 'commit:7234cb2750b63f47bff735edc50a1c0a433c2518', c.text_tag
274 assert_equal 'commit:7234cb2750b63f47bff735edc50a1c0a433c2518', c.text_tag
274 end
275 end
275
276
276 def test_text_tag_hash_with_same_project
277 def test_text_tag_hash_with_same_project
277 c = Changeset.new(:revision => '7234cb27', :scmid => '7234cb27', :repository => Project.find(1).repository)
278 c = Changeset.new(:revision => '7234cb27', :scmid => '7234cb27', :repository => Project.find(1).repository)
278 assert_equal 'commit:7234cb27', c.text_tag(Project.find(1))
279 assert_equal 'commit:7234cb27', c.text_tag(Project.find(1))
279 end
280 end
280
281
281 def test_text_tag_hash_with_different_project
282 def test_text_tag_hash_with_different_project
282 c = Changeset.new(:revision => '7234cb27', :scmid => '7234cb27', :repository => Project.find(1).repository)
283 c = Changeset.new(:revision => '7234cb27', :scmid => '7234cb27', :repository => Project.find(1).repository)
283 assert_equal 'ecookbook:commit:7234cb27', c.text_tag(Project.find(2))
284 assert_equal 'ecookbook:commit:7234cb27', c.text_tag(Project.find(2))
284 end
285 end
285
286
286 def test_text_tag_hash_all_number
287 def test_text_tag_hash_all_number
287 c = Changeset.new(:scmid => '0123456789', :revision => '0123456789')
288 c = Changeset.new(:scmid => '0123456789', :revision => '0123456789')
288 assert_equal 'commit:0123456789', c.text_tag
289 assert_equal 'commit:0123456789', c.text_tag
289 end
290 end
290
291
291 def test_previous
292 def test_previous
292 changeset = Changeset.find_by_revision('3')
293 changeset = Changeset.find_by_revision('3')
293 assert_equal Changeset.find_by_revision('2'), changeset.previous
294 assert_equal Changeset.find_by_revision('2'), changeset.previous
294 end
295 end
295
296
296 def test_previous_nil
297 def test_previous_nil
297 changeset = Changeset.find_by_revision('1')
298 changeset = Changeset.find_by_revision('1')
298 assert_nil changeset.previous
299 assert_nil changeset.previous
299 end
300 end
300
301
301 def test_next
302 def test_next
302 changeset = Changeset.find_by_revision('2')
303 changeset = Changeset.find_by_revision('2')
303 assert_equal Changeset.find_by_revision('3'), changeset.next
304 assert_equal Changeset.find_by_revision('3'), changeset.next
304 end
305 end
305
306
306 def test_next_nil
307 def test_next_nil
307 changeset = Changeset.find_by_revision('10')
308 changeset = Changeset.find_by_revision('10')
308 assert_nil changeset.next
309 assert_nil changeset.next
309 end
310 end
310
311
311 def test_comments_should_be_converted_to_utf8
312 def test_comments_should_be_converted_to_utf8
312 proj = Project.find(3)
313 proj = Project.find(3)
313 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
314 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
314 str = "Texte encod\xe9 en ISO-8859-1."
315 str = "Texte encod\xe9 en ISO-8859-1."
315 str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding)
316 str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding)
316 r = Repository::Bazaar.create!(
317 r = Repository::Bazaar.create!(
317 :project => proj,
318 :project => proj,
318 :url => '/tmp/test/bazaar',
319 :url => '/tmp/test/bazaar',
319 :log_encoding => 'ISO-8859-1' )
320 :log_encoding => 'ISO-8859-1' )
320 assert r
321 assert r
321 c = Changeset.new(:repository => r,
322 c = Changeset.new(:repository => r,
322 :committed_on => Time.now,
323 :committed_on => Time.now,
323 :revision => '123',
324 :revision => '123',
324 :scmid => '12345',
325 :scmid => '12345',
325 :comments => str)
326 :comments => str)
326 assert( c.save )
327 assert( c.save )
327 str_utf8 = "Texte encod\xc3\xa9 en ISO-8859-1."
328 str_utf8 = "Texte encod\xc3\xa9 en ISO-8859-1."
328 str_utf8.force_encoding("UTF-8") if str_utf8.respond_to?(:force_encoding)
329 str_utf8.force_encoding("UTF-8") if str_utf8.respond_to?(:force_encoding)
329 assert_equal str_utf8, c.comments
330 assert_equal str_utf8, c.comments
330 end
331 end
331
332
332 def test_invalid_utf8_sequences_in_comments_should_be_replaced_latin1
333 def test_invalid_utf8_sequences_in_comments_should_be_replaced_latin1
333 proj = Project.find(3)
334 proj = Project.find(3)
334 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
335 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
335 str1 = "Texte encod\xe9 en ISO-8859-1."
336 str1 = "Texte encod\xe9 en ISO-8859-1."
336 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
337 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
337 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
338 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
338 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
339 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
339 r = Repository::Bazaar.create!(
340 r = Repository::Bazaar.create!(
340 :project => proj,
341 :project => proj,
341 :url => '/tmp/test/bazaar',
342 :url => '/tmp/test/bazaar',
342 :log_encoding => 'UTF-8' )
343 :log_encoding => 'UTF-8' )
343 assert r
344 assert r
344 c = Changeset.new(:repository => r,
345 c = Changeset.new(:repository => r,
345 :committed_on => Time.now,
346 :committed_on => Time.now,
346 :revision => '123',
347 :revision => '123',
347 :scmid => '12345',
348 :scmid => '12345',
348 :comments => str1,
349 :comments => str1,
349 :committer => str2)
350 :committer => str2)
350 assert( c.save )
351 assert( c.save )
351 assert_equal "Texte encod? en ISO-8859-1.", c.comments
352 assert_equal "Texte encod? en ISO-8859-1.", c.comments
352 assert_equal "?a?b?c?d?e test", c.committer
353 assert_equal "?a?b?c?d?e test", c.committer
353 end
354 end
354
355
355 def test_invalid_utf8_sequences_in_comments_should_be_replaced_ja_jis
356 def test_invalid_utf8_sequences_in_comments_should_be_replaced_ja_jis
356 proj = Project.find(3)
357 proj = Project.find(3)
357 str = "test\xb5\xfetest\xb5\xfe"
358 str = "test\xb5\xfetest\xb5\xfe"
358 if str.respond_to?(:force_encoding)
359 if str.respond_to?(:force_encoding)
359 str.force_encoding('ASCII-8BIT')
360 str.force_encoding('ASCII-8BIT')
360 end
361 end
361 r = Repository::Bazaar.create!(
362 r = Repository::Bazaar.create!(
362 :project => proj,
363 :project => proj,
363 :url => '/tmp/test/bazaar',
364 :url => '/tmp/test/bazaar',
364 :log_encoding => 'ISO-2022-JP' )
365 :log_encoding => 'ISO-2022-JP' )
365 assert r
366 assert r
366 c = Changeset.new(:repository => r,
367 c = Changeset.new(:repository => r,
367 :committed_on => Time.now,
368 :committed_on => Time.now,
368 :revision => '123',
369 :revision => '123',
369 :scmid => '12345',
370 :scmid => '12345',
370 :comments => str)
371 :comments => str)
371 assert( c.save )
372 assert( c.save )
372 assert_equal "test??test??", c.comments
373 assert_equal "test??test??", c.comments
373 end
374 end
374
375
375 def test_comments_should_be_converted_all_latin1_to_utf8
376 def test_comments_should_be_converted_all_latin1_to_utf8
376 s1 = "\xC2\x80"
377 s1 = "\xC2\x80"
377 s2 = "\xc3\x82\xc2\x80"
378 s2 = "\xc3\x82\xc2\x80"
378 s4 = s2.dup
379 s4 = s2.dup
379 if s1.respond_to?(:force_encoding)
380 if s1.respond_to?(:force_encoding)
380 s3 = s1.dup
381 s3 = s1.dup
381 s1.force_encoding('ASCII-8BIT')
382 s1.force_encoding('ASCII-8BIT')
382 s2.force_encoding('ASCII-8BIT')
383 s2.force_encoding('ASCII-8BIT')
383 s3.force_encoding('ISO-8859-1')
384 s3.force_encoding('ISO-8859-1')
384 s4.force_encoding('UTF-8')
385 s4.force_encoding('UTF-8')
385 assert_equal s3.encode('UTF-8'), s4
386 assert_equal s3.encode('UTF-8'), s4
386 end
387 end
387 proj = Project.find(3)
388 proj = Project.find(3)
388 r = Repository::Bazaar.create!(
389 r = Repository::Bazaar.create!(
389 :project => proj,
390 :project => proj,
390 :url => '/tmp/test/bazaar',
391 :url => '/tmp/test/bazaar',
391 :log_encoding => 'ISO-8859-1' )
392 :log_encoding => 'ISO-8859-1' )
392 assert r
393 assert r
393 c = Changeset.new(:repository => r,
394 c = Changeset.new(:repository => r,
394 :committed_on => Time.now,
395 :committed_on => Time.now,
395 :revision => '123',
396 :revision => '123',
396 :scmid => '12345',
397 :scmid => '12345',
397 :comments => s1)
398 :comments => s1)
398 assert( c.save )
399 assert( c.save )
399 assert_equal s4, c.comments
400 assert_equal s4, c.comments
400 end
401 end
401
402
402 def test_invalid_utf8_sequences_in_paths_should_be_replaced
403 def test_invalid_utf8_sequences_in_paths_should_be_replaced
403 proj = Project.find(3)
404 proj = Project.find(3)
404 str1 = "Texte encod\xe9 en ISO-8859-1"
405 str1 = "Texte encod\xe9 en ISO-8859-1"
405 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
406 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
406 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
407 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
407 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
408 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
408 r = Repository::Bazaar.create!(
409 r = Repository::Bazaar.create!(
409 :project => proj,
410 :project => proj,
410 :url => '/tmp/test/bazaar',
411 :url => '/tmp/test/bazaar',
411 :log_encoding => 'UTF-8' )
412 :log_encoding => 'UTF-8' )
412 assert r
413 assert r
413 cs = Changeset.new(
414 cs = Changeset.new(
414 :repository => r,
415 :repository => r,
415 :committed_on => Time.now,
416 :committed_on => Time.now,
416 :revision => '123',
417 :revision => '123',
417 :scmid => '12345',
418 :scmid => '12345',
418 :comments => "test")
419 :comments => "test")
419 assert(cs.save)
420 assert(cs.save)
420 ch = Change.new(
421 ch = Change.new(
421 :changeset => cs,
422 :changeset => cs,
422 :action => "A",
423 :action => "A",
423 :path => str1,
424 :path => str1,
424 :from_path => str2,
425 :from_path => str2,
425 :from_revision => "345")
426 :from_revision => "345")
426 assert(ch.save)
427 assert(ch.save)
427 assert_equal "Texte encod? en ISO-8859-1", ch.path
428 assert_equal "Texte encod? en ISO-8859-1", ch.path
428 assert_equal "?a?b?c?d?e test", ch.from_path
429 assert_equal "?a?b?c?d?e test", ch.from_path
429 end
430 end
430
431
431 def test_comments_nil
432 def test_comments_nil
432 proj = Project.find(3)
433 proj = Project.find(3)
433 r = Repository::Bazaar.create!(
434 r = Repository::Bazaar.create!(
434 :project => proj,
435 :project => proj,
435 :url => '/tmp/test/bazaar',
436 :url => '/tmp/test/bazaar',
436 :log_encoding => 'ISO-8859-1' )
437 :log_encoding => 'ISO-8859-1' )
437 assert r
438 assert r
438 c = Changeset.new(:repository => r,
439 c = Changeset.new(:repository => r,
439 :committed_on => Time.now,
440 :committed_on => Time.now,
440 :revision => '123',
441 :revision => '123',
441 :scmid => '12345',
442 :scmid => '12345',
442 :comments => nil,
443 :comments => nil,
443 :committer => nil)
444 :committer => nil)
444 assert( c.save )
445 assert( c.save )
445 assert_equal "", c.comments
446 assert_equal "", c.comments
446 assert_equal nil, c.committer
447 assert_equal nil, c.committer
447 if c.comments.respond_to?(:force_encoding)
448 if c.comments.respond_to?(:force_encoding)
448 assert_equal "UTF-8", c.comments.encoding.to_s
449 assert_equal "UTF-8", c.comments.encoding.to_s
449 end
450 end
450 end
451 end
451
452
452 def test_comments_empty
453 def test_comments_empty
453 proj = Project.find(3)
454 proj = Project.find(3)
454 r = Repository::Bazaar.create!(
455 r = Repository::Bazaar.create!(
455 :project => proj,
456 :project => proj,
456 :url => '/tmp/test/bazaar',
457 :url => '/tmp/test/bazaar',
457 :log_encoding => 'ISO-8859-1' )
458 :log_encoding => 'ISO-8859-1' )
458 assert r
459 assert r
459 c = Changeset.new(:repository => r,
460 c = Changeset.new(:repository => r,
460 :committed_on => Time.now,
461 :committed_on => Time.now,
461 :revision => '123',
462 :revision => '123',
462 :scmid => '12345',
463 :scmid => '12345',
463 :comments => "",
464 :comments => "",
464 :committer => "")
465 :committer => "")
465 assert( c.save )
466 assert( c.save )
466 assert_equal "", c.comments
467 assert_equal "", c.comments
467 assert_equal "", c.committer
468 assert_equal "", c.committer
468 if c.comments.respond_to?(:force_encoding)
469 if c.comments.respond_to?(:force_encoding)
469 assert_equal "UTF-8", c.comments.encoding.to_s
470 assert_equal "UTF-8", c.comments.encoding.to_s
470 assert_equal "UTF-8", c.committer.encoding.to_s
471 assert_equal "UTF-8", c.committer.encoding.to_s
471 end
472 end
472 end
473 end
473
474
474 def test_identifier
475 def test_identifier
475 c = Changeset.find_by_revision('1')
476 c = Changeset.find_by_revision('1')
476 assert_equal c.revision, c.identifier
477 assert_equal c.revision, c.identifier
477 end
478 end
478 end
479 end
General Comments 0
You need to be logged in to leave comments. Login now