@@ -1,576 +1,578 | |||
|
1 | 1 | # encoding: utf-8 |
|
2 | 2 | # |
|
3 | 3 | # Redmine - project management software |
|
4 | 4 | # Copyright (C) 2006-2015 Jean-Philippe Lang |
|
5 | 5 | # |
|
6 | 6 | # This program is free software; you can redistribute it and/or |
|
7 | 7 | # modify it under the terms of the GNU General Public License |
|
8 | 8 | # as published by the Free Software Foundation; either version 2 |
|
9 | 9 | # of the License, or (at your option) any later version. |
|
10 | 10 | # |
|
11 | 11 | # This program is distributed in the hope that it will be useful, |
|
12 | 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 | 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 | 14 | # GNU General Public License for more details. |
|
15 | 15 | # |
|
16 | 16 | # You should have received a copy of the GNU General Public License |
|
17 | 17 | # along with this program; if not, write to the Free Software |
|
18 | 18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
19 | 19 | |
|
20 | 20 | require File.expand_path('../../test_helper', __FILE__) |
|
21 | 21 | |
|
22 | 22 | class ChangesetTest < ActiveSupport::TestCase |
|
23 | 23 | fixtures :projects, :repositories, |
|
24 | 24 | :issues, :issue_statuses, :issue_categories, |
|
25 | :journals, :journal_details, | |
|
26 | :workflows, | |
|
25 | 27 | :changesets, :changes, |
|
26 | 28 | :enumerations, |
|
27 | 29 | :custom_fields, :custom_values, |
|
28 | 30 | :users, :members, :member_roles, |
|
29 | 31 | :email_addresses, |
|
30 | 32 | :trackers, :projects_trackers, |
|
31 | 33 | :enabled_modules, :roles |
|
32 | 34 | |
|
33 | 35 | def test_ref_keywords_any |
|
34 | 36 | ActionMailer::Base.deliveries.clear |
|
35 | 37 | Setting.commit_ref_keywords = '*' |
|
36 | 38 | Setting.commit_update_keywords = [{'keywords' => 'fixes , closes', 'status_id' => '5', 'done_ratio' => '90'}] |
|
37 | 39 | |
|
38 | 40 | c = Changeset.new(:repository => Project.find(1).repository, |
|
39 | 41 | :committed_on => Time.now, |
|
40 | 42 | :comments => 'New commit (#2). Fixes #1', |
|
41 | 43 | :revision => '12345') |
|
42 | 44 | assert c.save |
|
43 | 45 | assert_equal [1, 2], c.issue_ids.sort |
|
44 | 46 | fixed = Issue.find(1) |
|
45 | 47 | assert fixed.closed? |
|
46 | 48 | assert_equal 90, fixed.done_ratio |
|
47 | 49 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
48 | 50 | end |
|
49 | 51 | |
|
50 | 52 | def test_ref_keywords |
|
51 | 53 | Setting.commit_ref_keywords = 'refs' |
|
52 | 54 | Setting.commit_update_keywords = '' |
|
53 | 55 | c = Changeset.new(:repository => Project.find(1).repository, |
|
54 | 56 | :committed_on => Time.now, |
|
55 | 57 | :comments => 'Ignores #2. Refs #1', |
|
56 | 58 | :revision => '12345') |
|
57 | 59 | assert c.save |
|
58 | 60 | assert_equal [1], c.issue_ids.sort |
|
59 | 61 | end |
|
60 | 62 | |
|
61 | 63 | def test_ref_keywords_any_only |
|
62 | 64 | Setting.commit_ref_keywords = '*' |
|
63 | 65 | Setting.commit_update_keywords = '' |
|
64 | 66 | c = Changeset.new(:repository => Project.find(1).repository, |
|
65 | 67 | :committed_on => Time.now, |
|
66 | 68 | :comments => 'Ignores #2. Refs #1', |
|
67 | 69 | :revision => '12345') |
|
68 | 70 | assert c.save |
|
69 | 71 | assert_equal [1, 2], c.issue_ids.sort |
|
70 | 72 | end |
|
71 | 73 | |
|
72 | 74 | def test_ref_keywords_any_with_timelog |
|
73 | 75 | Setting.commit_ref_keywords = '*' |
|
74 | 76 | Setting.commit_logtime_enabled = '1' |
|
75 | 77 | |
|
76 | 78 | { |
|
77 | 79 | '2' => 2.0, |
|
78 | 80 | '2h' => 2.0, |
|
79 | 81 | '2hours' => 2.0, |
|
80 | 82 | '15m' => 0.25, |
|
81 | 83 | '15min' => 0.25, |
|
82 | 84 | '3h15' => 3.25, |
|
83 | 85 | '3h15m' => 3.25, |
|
84 | 86 | '3h15min' => 3.25, |
|
85 | 87 | '3:15' => 3.25, |
|
86 | 88 | '3.25' => 3.25, |
|
87 | 89 | '3.25h' => 3.25, |
|
88 | 90 | '3,25' => 3.25, |
|
89 | 91 | '3,25h' => 3.25, |
|
90 | 92 | }.each do |syntax, expected_hours| |
|
91 | 93 | c = Changeset.new(:repository => Project.find(1).repository, |
|
92 | 94 | :committed_on => 24.hours.ago, |
|
93 | 95 | :comments => "Worked on this issue #1 @#{syntax}", |
|
94 | 96 | :revision => '520', |
|
95 | 97 | :user => User.find(2)) |
|
96 | 98 | assert_difference 'TimeEntry.count' do |
|
97 | 99 | c.scan_comment_for_issue_ids |
|
98 | 100 | end |
|
99 | 101 | assert_equal [1], c.issue_ids.sort |
|
100 | 102 | |
|
101 | 103 | time = TimeEntry.order('id desc').first |
|
102 | 104 | assert_equal 1, time.issue_id |
|
103 | 105 | assert_equal 1, time.project_id |
|
104 | 106 | assert_equal 2, time.user_id |
|
105 | 107 | assert_equal expected_hours, time.hours, |
|
106 | 108 | "@#{syntax} should be logged as #{expected_hours} hours but was #{time.hours}" |
|
107 | 109 | assert_equal Date.yesterday, time.spent_on |
|
108 | 110 | assert time.activity.is_default? |
|
109 | 111 | assert time.comments.include?('r520'), |
|
110 | 112 | "r520 was expected in time_entry comments: #{time.comments}" |
|
111 | 113 | end |
|
112 | 114 | end |
|
113 | 115 | |
|
114 | 116 | def test_ref_keywords_closing_with_timelog |
|
115 | 117 | Setting.commit_ref_keywords = '*' |
|
116 | 118 | Setting.commit_update_keywords = [{'keywords' => 'fixes , closes', |
|
117 | 119 | 'status_id' => IssueStatus.where(:is_closed => true).first.id.to_s}] |
|
118 | 120 | Setting.commit_logtime_enabled = '1' |
|
119 | 121 | |
|
120 | 122 | c = Changeset.new(:repository => Project.find(1).repository, |
|
121 | 123 | :committed_on => Time.now, |
|
122 | 124 | :comments => 'This is a comment. Fixes #1 @4.5, #2 @1', |
|
123 | 125 | :user => User.find(2)) |
|
124 | 126 | assert_difference 'TimeEntry.count', 2 do |
|
125 | 127 | c.scan_comment_for_issue_ids |
|
126 | 128 | end |
|
127 | 129 | |
|
128 | 130 | assert_equal [1, 2], c.issue_ids.sort |
|
129 | 131 | assert Issue.find(1).closed? |
|
130 | 132 | assert Issue.find(2).closed? |
|
131 | 133 | |
|
132 | 134 | times = TimeEntry.order('id desc').limit(2) |
|
133 | 135 | assert_equal [1, 2], times.collect(&:issue_id).sort |
|
134 | 136 | end |
|
135 | 137 | |
|
136 | 138 | def test_ref_keywords_any_line_start |
|
137 | 139 | Setting.commit_ref_keywords = '*' |
|
138 | 140 | c = Changeset.new(:repository => Project.find(1).repository, |
|
139 | 141 | :committed_on => Time.now, |
|
140 | 142 | :comments => '#1 is the reason of this commit', |
|
141 | 143 | :revision => '12345') |
|
142 | 144 | assert c.save |
|
143 | 145 | assert_equal [1], c.issue_ids.sort |
|
144 | 146 | end |
|
145 | 147 | |
|
146 | 148 | def test_ref_keywords_allow_brackets_around_a_issue_number |
|
147 | 149 | Setting.commit_ref_keywords = '*' |
|
148 | 150 | c = Changeset.new(:repository => Project.find(1).repository, |
|
149 | 151 | :committed_on => Time.now, |
|
150 | 152 | :comments => '[#1] Worked on this issue', |
|
151 | 153 | :revision => '12345') |
|
152 | 154 | assert c.save |
|
153 | 155 | assert_equal [1], c.issue_ids.sort |
|
154 | 156 | end |
|
155 | 157 | |
|
156 | 158 | def test_ref_keywords_allow_brackets_around_multiple_issue_numbers |
|
157 | 159 | Setting.commit_ref_keywords = '*' |
|
158 | 160 | c = Changeset.new(:repository => Project.find(1).repository, |
|
159 | 161 | :committed_on => Time.now, |
|
160 | 162 | :comments => '[#1 #2, #3] Worked on these', |
|
161 | 163 | :revision => '12345') |
|
162 | 164 | assert c.save |
|
163 | 165 | assert_equal [1,2,3], c.issue_ids.sort |
|
164 | 166 | end |
|
165 | 167 | |
|
166 | 168 | def test_update_keywords_with_changes_should_create_journal |
|
167 | 169 | issue = Issue.generate!(:project_id => 1, :status_id => 1) |
|
168 | 170 | |
|
169 | 171 | with_settings :commit_update_keywords => [{'keywords' => 'fixes', 'status_id' => '3'}] do |
|
170 | 172 | assert_difference 'Journal.count' do |
|
171 | 173 | c = Changeset.generate!(:repository => Project.find(1).repository,:comments => "Fixes ##{issue.id}") |
|
172 | 174 | assert_include c.id, issue.reload.changeset_ids |
|
173 | 175 | journal = Journal.order('id DESC').first |
|
174 | 176 | assert_equal 1, journal.details.count |
|
175 | 177 | end |
|
176 | 178 | end |
|
177 | 179 | end |
|
178 | 180 | |
|
179 | 181 | def test_update_keywords_without_change_should_not_create_journal |
|
180 | 182 | issue = Issue.generate!(:project_id => 1, :status_id => 3) |
|
181 | 183 | |
|
182 | 184 | with_settings :commit_update_keywords => [{'keywords' => 'fixes', 'status_id' => '3'}] do |
|
183 | 185 | assert_no_difference 'Journal.count' do |
|
184 | 186 | c = Changeset.generate!(:repository => Project.find(1).repository,:comments => "Fixes ##{issue.id}") |
|
185 | 187 | assert_include c.id, issue.reload.changeset_ids |
|
186 | 188 | end |
|
187 | 189 | end |
|
188 | 190 | end |
|
189 | 191 | |
|
190 | 192 | def test_update_keywords_with_multiple_rules |
|
191 | 193 | with_settings :commit_update_keywords => [ |
|
192 | 194 | {'keywords' => 'fixes, closes', 'status_id' => '5'}, |
|
193 | 195 | {'keywords' => 'resolves', 'status_id' => '3'} |
|
194 | 196 | ] do |
|
195 | 197 | |
|
196 | 198 | issue1 = Issue.generate! |
|
197 | 199 | issue2 = Issue.generate! |
|
198 | 200 | Changeset.generate!(:comments => "Closes ##{issue1.id}\nResolves ##{issue2.id}") |
|
199 | 201 | assert_equal 5, issue1.reload.status_id |
|
200 | 202 | assert_equal 3, issue2.reload.status_id |
|
201 | 203 | end |
|
202 | 204 | end |
|
203 | 205 | |
|
204 | 206 | def test_update_keywords_with_multiple_rules_should_match_tracker |
|
205 | 207 | with_settings :commit_update_keywords => [ |
|
206 | 208 | {'keywords' => 'fixes', 'status_id' => '5', 'if_tracker_id' => '2'}, |
|
207 | 209 | {'keywords' => 'fixes', 'status_id' => '3', 'if_tracker_id' => ''} |
|
208 | 210 | ] do |
|
209 | 211 | |
|
210 | 212 | issue1 = Issue.generate!(:tracker_id => 2) |
|
211 | 213 | issue2 = Issue.generate! |
|
212 | 214 | Changeset.generate!(:comments => "Fixes ##{issue1.id}, ##{issue2.id}") |
|
213 | 215 | assert_equal 5, issue1.reload.status_id |
|
214 | 216 | assert_equal 3, issue2.reload.status_id |
|
215 | 217 | end |
|
216 | 218 | end |
|
217 | 219 | |
|
218 | 220 | def test_update_keywords_with_multiple_rules_and_no_match |
|
219 | 221 | with_settings :commit_update_keywords => [ |
|
220 | 222 | {'keywords' => 'fixes', 'status_id' => '5', 'if_tracker_id' => '2'}, |
|
221 | 223 | {'keywords' => 'fixes', 'status_id' => '3', 'if_tracker_id' => '3'} |
|
222 | 224 | ] do |
|
223 | 225 | |
|
224 | 226 | issue1 = Issue.generate!(:tracker_id => 2) |
|
225 | 227 | issue2 = Issue.generate! |
|
226 | 228 | Changeset.generate!(:comments => "Fixes ##{issue1.id}, ##{issue2.id}") |
|
227 | 229 | assert_equal 5, issue1.reload.status_id |
|
228 | 230 | assert_equal 1, issue2.reload.status_id # no updates |
|
229 | 231 | end |
|
230 | 232 | end |
|
231 | 233 | |
|
232 | 234 | def test_commit_referencing_a_subproject_issue |
|
233 | 235 | c = Changeset.new(:repository => Project.find(1).repository, |
|
234 | 236 | :committed_on => Time.now, |
|
235 | 237 | :comments => 'refs #5, a subproject issue', |
|
236 | 238 | :revision => '12345') |
|
237 | 239 | assert c.save |
|
238 | 240 | assert_equal [5], c.issue_ids.sort |
|
239 | 241 | assert c.issues.first.project != c.project |
|
240 | 242 | end |
|
241 | 243 | |
|
242 | 244 | def test_commit_closing_a_subproject_issue |
|
243 | 245 | with_settings :commit_update_keywords => [{'keywords' => 'closes', 'status_id' => '5'}], |
|
244 | 246 | :default_language => 'en' do |
|
245 | 247 | issue = Issue.find(5) |
|
246 | 248 | assert !issue.closed? |
|
247 | 249 | assert_difference 'Journal.count' do |
|
248 | 250 | c = Changeset.new(:repository => Project.find(1).repository, |
|
249 | 251 | :committed_on => Time.now, |
|
250 | 252 | :comments => 'closes #5, a subproject issue', |
|
251 | 253 | :revision => '12345') |
|
252 | 254 | assert c.save |
|
253 | 255 | end |
|
254 | 256 | assert issue.reload.closed? |
|
255 | 257 | journal = Journal.order('id DESC').first |
|
256 | 258 | assert_equal issue, journal.issue |
|
257 | 259 | assert_include "Applied in changeset ecookbook:r12345.", journal.notes |
|
258 | 260 | end |
|
259 | 261 | end |
|
260 | 262 | |
|
261 | 263 | def test_commit_referencing_a_parent_project_issue |
|
262 | 264 | # repository of child project |
|
263 | 265 | r = Repository::Subversion.create!( |
|
264 | 266 | :project => Project.find(3), |
|
265 | 267 | :url => 'svn://localhost/test') |
|
266 | 268 | c = Changeset.new(:repository => r, |
|
267 | 269 | :committed_on => Time.now, |
|
268 | 270 | :comments => 'refs #2, an issue of a parent project', |
|
269 | 271 | :revision => '12345') |
|
270 | 272 | assert c.save |
|
271 | 273 | assert_equal [2], c.issue_ids.sort |
|
272 | 274 | assert c.issues.first.project != c.project |
|
273 | 275 | end |
|
274 | 276 | |
|
275 | 277 | def test_commit_referencing_a_project_with_commit_cross_project_ref_disabled |
|
276 | 278 | r = Repository::Subversion.create!( |
|
277 | 279 | :project => Project.find(3), |
|
278 | 280 | :url => 'svn://localhost/test') |
|
279 | 281 | with_settings :commit_cross_project_ref => '0' do |
|
280 | 282 | c = Changeset.new(:repository => r, |
|
281 | 283 | :committed_on => Time.now, |
|
282 | 284 | :comments => 'refs #4, an issue of a different project', |
|
283 | 285 | :revision => '12345') |
|
284 | 286 | assert c.save |
|
285 | 287 | assert_equal [], c.issue_ids |
|
286 | 288 | end |
|
287 | 289 | end |
|
288 | 290 | |
|
289 | 291 | def test_commit_referencing_a_project_with_commit_cross_project_ref_enabled |
|
290 | 292 | r = Repository::Subversion.create!( |
|
291 | 293 | :project => Project.find(3), |
|
292 | 294 | :url => 'svn://localhost/test') |
|
293 | 295 | with_settings :commit_cross_project_ref => '1' do |
|
294 | 296 | c = Changeset.new(:repository => r, |
|
295 | 297 | :committed_on => Time.now, |
|
296 | 298 | :comments => 'refs #4, an issue of a different project', |
|
297 | 299 | :revision => '12345') |
|
298 | 300 | assert c.save |
|
299 | 301 | assert_equal [4], c.issue_ids |
|
300 | 302 | end |
|
301 | 303 | end |
|
302 | 304 | |
|
303 | 305 | def test_old_commits_should_not_update_issues_nor_log_time |
|
304 | 306 | Setting.commit_ref_keywords = '*' |
|
305 | 307 | Setting.commit_update_keywords = {'fixes , closes' => {'status_id' => '5', 'done_ratio' => '90'}} |
|
306 | 308 | Setting.commit_logtime_enabled = '1' |
|
307 | 309 | |
|
308 | 310 | repository = Project.find(1).repository |
|
309 | 311 | repository.created_on = Time.now |
|
310 | 312 | repository.save! |
|
311 | 313 | |
|
312 | 314 | c = Changeset.new(:repository => repository, |
|
313 | 315 | :committed_on => 1.month.ago, |
|
314 | 316 | :comments => 'New commit (#2). Fixes #1 @1h', |
|
315 | 317 | :revision => '12345') |
|
316 | 318 | assert_no_difference 'TimeEntry.count' do |
|
317 | 319 | assert c.save |
|
318 | 320 | end |
|
319 | 321 | assert_equal [1, 2], c.issue_ids.sort |
|
320 | 322 | issue = Issue.find(1) |
|
321 | 323 | assert_equal 1, issue.status_id |
|
322 | 324 | assert_equal 0, issue.done_ratio |
|
323 | 325 | end |
|
324 | 326 | |
|
325 | 327 | def test_2_repositories_with_same_backend_should_not_link_issue_multiple_times |
|
326 | 328 | Setting.commit_ref_keywords = '*' |
|
327 | 329 | r1 = Repository::Subversion.create!(:project_id => 1, :identifier => 'svn1', :url => 'file:///svn1') |
|
328 | 330 | r2 = Repository::Subversion.create!(:project_id => 1, :identifier => 'svn2', :url => 'file:///svn1') |
|
329 | 331 | now = Time.now |
|
330 | 332 | assert_difference 'Issue.find(1).changesets.count' do |
|
331 | 333 | c1 = Changeset.create!(:repository => r1, :committed_on => now, :comments => 'Fixes #1', :revision => '12345') |
|
332 | 334 | c1 = Changeset.create!(:repository => r2, :committed_on => now, :comments => 'Fixes #1', :revision => '12345') |
|
333 | 335 | end |
|
334 | 336 | end |
|
335 | 337 | |
|
336 | 338 | def test_text_tag_revision |
|
337 | 339 | c = Changeset.new(:revision => '520') |
|
338 | 340 | assert_equal 'r520', c.text_tag |
|
339 | 341 | end |
|
340 | 342 | |
|
341 | 343 | def test_text_tag_revision_with_same_project |
|
342 | 344 | c = Changeset.new(:revision => '520', :repository => Project.find(1).repository) |
|
343 | 345 | assert_equal 'r520', c.text_tag(Project.find(1)) |
|
344 | 346 | end |
|
345 | 347 | |
|
346 | 348 | def test_text_tag_revision_with_different_project |
|
347 | 349 | c = Changeset.new(:revision => '520', :repository => Project.find(1).repository) |
|
348 | 350 | assert_equal 'ecookbook:r520', c.text_tag(Project.find(2)) |
|
349 | 351 | end |
|
350 | 352 | |
|
351 | 353 | def test_text_tag_revision_with_repository_identifier |
|
352 | 354 | r = Repository::Subversion.create!( |
|
353 | 355 | :project_id => 1, |
|
354 | 356 | :url => 'svn://localhost/test', |
|
355 | 357 | :identifier => 'documents') |
|
356 | 358 | c = Changeset.new(:revision => '520', :repository => r) |
|
357 | 359 | assert_equal 'documents|r520', c.text_tag |
|
358 | 360 | assert_equal 'ecookbook:documents|r520', c.text_tag(Project.find(2)) |
|
359 | 361 | end |
|
360 | 362 | |
|
361 | 363 | def test_text_tag_hash |
|
362 | 364 | c = Changeset.new( |
|
363 | 365 | :scmid => '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
364 | 366 | :revision => '7234cb2750b63f47bff735edc50a1c0a433c2518') |
|
365 | 367 | assert_equal 'commit:7234cb2750b63f47bff735edc50a1c0a433c2518', c.text_tag |
|
366 | 368 | end |
|
367 | 369 | |
|
368 | 370 | def test_text_tag_hash_with_same_project |
|
369 | 371 | c = Changeset.new(:revision => '7234cb27', :scmid => '7234cb27', :repository => Project.find(1).repository) |
|
370 | 372 | assert_equal 'commit:7234cb27', c.text_tag(Project.find(1)) |
|
371 | 373 | end |
|
372 | 374 | |
|
373 | 375 | def test_text_tag_hash_with_different_project |
|
374 | 376 | c = Changeset.new(:revision => '7234cb27', :scmid => '7234cb27', :repository => Project.find(1).repository) |
|
375 | 377 | assert_equal 'ecookbook:commit:7234cb27', c.text_tag(Project.find(2)) |
|
376 | 378 | end |
|
377 | 379 | |
|
378 | 380 | def test_text_tag_hash_all_number |
|
379 | 381 | c = Changeset.new(:scmid => '0123456789', :revision => '0123456789') |
|
380 | 382 | assert_equal 'commit:0123456789', c.text_tag |
|
381 | 383 | end |
|
382 | 384 | |
|
383 | 385 | def test_text_tag_hash_with_repository_identifier |
|
384 | 386 | r = Repository::Subversion.new( |
|
385 | 387 | :project_id => 1, |
|
386 | 388 | :url => 'svn://localhost/test', |
|
387 | 389 | :identifier => 'documents') |
|
388 | 390 | c = Changeset.new(:revision => '7234cb27', :scmid => '7234cb27', :repository => r) |
|
389 | 391 | assert_equal 'commit:documents|7234cb27', c.text_tag |
|
390 | 392 | assert_equal 'ecookbook:commit:documents|7234cb27', c.text_tag(Project.find(2)) |
|
391 | 393 | end |
|
392 | 394 | |
|
393 | 395 | def test_previous |
|
394 | 396 | changeset = Changeset.find_by_revision('3') |
|
395 | 397 | assert_equal Changeset.find_by_revision('2'), changeset.previous |
|
396 | 398 | end |
|
397 | 399 | |
|
398 | 400 | def test_previous_nil |
|
399 | 401 | changeset = Changeset.find_by_revision('1') |
|
400 | 402 | assert_nil changeset.previous |
|
401 | 403 | end |
|
402 | 404 | |
|
403 | 405 | def test_next |
|
404 | 406 | changeset = Changeset.find_by_revision('2') |
|
405 | 407 | assert_equal Changeset.find_by_revision('3'), changeset.next |
|
406 | 408 | end |
|
407 | 409 | |
|
408 | 410 | def test_next_nil |
|
409 | 411 | changeset = Changeset.find_by_revision('10') |
|
410 | 412 | assert_nil changeset.next |
|
411 | 413 | end |
|
412 | 414 | |
|
413 | 415 | def test_comments_should_be_converted_to_utf8 |
|
414 | 416 | proj = Project.find(3) |
|
415 | 417 | # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt") |
|
416 | 418 | str = "Texte encod\xe9 en ISO-8859-1.".force_encoding("ASCII-8BIT") |
|
417 | 419 | r = Repository::Bazaar.create!( |
|
418 | 420 | :project => proj, |
|
419 | 421 | :url => '/tmp/test/bazaar', |
|
420 | 422 | :log_encoding => 'ISO-8859-1' ) |
|
421 | 423 | assert r |
|
422 | 424 | c = Changeset.new(:repository => r, |
|
423 | 425 | :committed_on => Time.now, |
|
424 | 426 | :revision => '123', |
|
425 | 427 | :scmid => '12345', |
|
426 | 428 | :comments => str) |
|
427 | 429 | assert( c.save ) |
|
428 | 430 | str_utf8 = "Texte encod\xc3\xa9 en ISO-8859-1.".force_encoding("UTF-8") |
|
429 | 431 | assert_equal str_utf8, c.comments |
|
430 | 432 | end |
|
431 | 433 | |
|
432 | 434 | def test_invalid_utf8_sequences_in_comments_should_be_replaced_latin1 |
|
433 | 435 | proj = Project.find(3) |
|
434 | 436 | # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt") |
|
435 | 437 | str1 = "Texte encod\xe9 en ISO-8859-1.".force_encoding("UTF-8") |
|
436 | 438 | str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test".force_encoding("ASCII-8BIT") |
|
437 | 439 | r = Repository::Bazaar.create!( |
|
438 | 440 | :project => proj, |
|
439 | 441 | :url => '/tmp/test/bazaar', |
|
440 | 442 | :log_encoding => 'UTF-8' ) |
|
441 | 443 | assert r |
|
442 | 444 | c = Changeset.new(:repository => r, |
|
443 | 445 | :committed_on => Time.now, |
|
444 | 446 | :revision => '123', |
|
445 | 447 | :scmid => '12345', |
|
446 | 448 | :comments => str1, |
|
447 | 449 | :committer => str2) |
|
448 | 450 | assert( c.save ) |
|
449 | 451 | assert_equal "Texte encod? en ISO-8859-1.", c.comments |
|
450 | 452 | assert_equal "?a?b?c?d?e test", c.committer |
|
451 | 453 | end |
|
452 | 454 | |
|
453 | 455 | def test_invalid_utf8_sequences_in_comments_should_be_replaced_ja_jis |
|
454 | 456 | proj = Project.find(3) |
|
455 | 457 | str = "test\xb5\xfetest\xb5\xfe".force_encoding('ASCII-8BIT') |
|
456 | 458 | r = Repository::Bazaar.create!( |
|
457 | 459 | :project => proj, |
|
458 | 460 | :url => '/tmp/test/bazaar', |
|
459 | 461 | :log_encoding => 'ISO-2022-JP' ) |
|
460 | 462 | assert r |
|
461 | 463 | c = Changeset.new(:repository => r, |
|
462 | 464 | :committed_on => Time.now, |
|
463 | 465 | :revision => '123', |
|
464 | 466 | :scmid => '12345', |
|
465 | 467 | :comments => str) |
|
466 | 468 | assert( c.save ) |
|
467 | 469 | assert_equal "test??test??", c.comments |
|
468 | 470 | end |
|
469 | 471 | |
|
470 | 472 | def test_comments_should_be_converted_all_latin1_to_utf8 |
|
471 | 473 | s1 = "\xC2\x80" |
|
472 | 474 | s2 = "\xc3\x82\xc2\x80" |
|
473 | 475 | s4 = s2.dup |
|
474 | 476 | s3 = s1.dup |
|
475 | 477 | s1.force_encoding('ASCII-8BIT') |
|
476 | 478 | s2.force_encoding('ASCII-8BIT') |
|
477 | 479 | s3.force_encoding('ISO-8859-1') |
|
478 | 480 | s4.force_encoding('UTF-8') |
|
479 | 481 | assert_equal s3.encode('UTF-8'), s4 |
|
480 | 482 | proj = Project.find(3) |
|
481 | 483 | r = Repository::Bazaar.create!( |
|
482 | 484 | :project => proj, |
|
483 | 485 | :url => '/tmp/test/bazaar', |
|
484 | 486 | :log_encoding => 'ISO-8859-1' ) |
|
485 | 487 | assert r |
|
486 | 488 | c = Changeset.new(:repository => r, |
|
487 | 489 | :committed_on => Time.now, |
|
488 | 490 | :revision => '123', |
|
489 | 491 | :scmid => '12345', |
|
490 | 492 | :comments => s1) |
|
491 | 493 | assert( c.save ) |
|
492 | 494 | assert_equal s4, c.comments |
|
493 | 495 | end |
|
494 | 496 | |
|
495 | 497 | def test_invalid_utf8_sequences_in_paths_should_be_replaced |
|
496 | 498 | proj = Project.find(3) |
|
497 | 499 | str1 = "Texte encod\xe9 en ISO-8859-1".force_encoding("UTF-8") |
|
498 | 500 | str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test".force_encoding("ASCII-8BIT") |
|
499 | 501 | r = Repository::Bazaar.create!( |
|
500 | 502 | :project => proj, |
|
501 | 503 | :url => '/tmp/test/bazaar', |
|
502 | 504 | :log_encoding => 'UTF-8' ) |
|
503 | 505 | assert r |
|
504 | 506 | cs = Changeset.new( |
|
505 | 507 | :repository => r, |
|
506 | 508 | :committed_on => Time.now, |
|
507 | 509 | :revision => '123', |
|
508 | 510 | :scmid => '12345', |
|
509 | 511 | :comments => "test") |
|
510 | 512 | assert(cs.save) |
|
511 | 513 | ch = Change.new( |
|
512 | 514 | :changeset => cs, |
|
513 | 515 | :action => "A", |
|
514 | 516 | :path => str1, |
|
515 | 517 | :from_path => str2, |
|
516 | 518 | :from_revision => "345") |
|
517 | 519 | assert(ch.save) |
|
518 | 520 | assert_equal "Texte encod? en ISO-8859-1", ch.path |
|
519 | 521 | assert_equal "?a?b?c?d?e test", ch.from_path |
|
520 | 522 | end |
|
521 | 523 | |
|
522 | 524 | def test_comments_nil |
|
523 | 525 | proj = Project.find(3) |
|
524 | 526 | r = Repository::Bazaar.create!( |
|
525 | 527 | :project => proj, |
|
526 | 528 | :url => '/tmp/test/bazaar', |
|
527 | 529 | :log_encoding => 'ISO-8859-1' ) |
|
528 | 530 | assert r |
|
529 | 531 | c = Changeset.new(:repository => r, |
|
530 | 532 | :committed_on => Time.now, |
|
531 | 533 | :revision => '123', |
|
532 | 534 | :scmid => '12345', |
|
533 | 535 | :comments => nil, |
|
534 | 536 | :committer => nil) |
|
535 | 537 | assert( c.save ) |
|
536 | 538 | assert_equal "", c.comments |
|
537 | 539 | assert_equal nil, c.committer |
|
538 | 540 | assert_equal "UTF-8", c.comments.encoding.to_s |
|
539 | 541 | end |
|
540 | 542 | |
|
541 | 543 | def test_comments_empty |
|
542 | 544 | proj = Project.find(3) |
|
543 | 545 | r = Repository::Bazaar.create!( |
|
544 | 546 | :project => proj, |
|
545 | 547 | :url => '/tmp/test/bazaar', |
|
546 | 548 | :log_encoding => 'ISO-8859-1' ) |
|
547 | 549 | assert r |
|
548 | 550 | c = Changeset.new(:repository => r, |
|
549 | 551 | :committed_on => Time.now, |
|
550 | 552 | :revision => '123', |
|
551 | 553 | :scmid => '12345', |
|
552 | 554 | :comments => "", |
|
553 | 555 | :committer => "") |
|
554 | 556 | assert( c.save ) |
|
555 | 557 | assert_equal "", c.comments |
|
556 | 558 | assert_equal "", c.committer |
|
557 | 559 | assert_equal "UTF-8", c.comments.encoding.to_s |
|
558 | 560 | assert_equal "UTF-8", c.committer.encoding.to_s |
|
559 | 561 | end |
|
560 | 562 | |
|
561 | 563 | def test_comments_should_accept_more_than_64k |
|
562 | 564 | c = Changeset.new(:repository => Repository.first, |
|
563 | 565 | :committed_on => Time.now, |
|
564 | 566 | :revision => '123', |
|
565 | 567 | :scmid => '12345', |
|
566 | 568 | :comments => "a" * 500.kilobyte) |
|
567 | 569 | assert c.save |
|
568 | 570 | c.reload |
|
569 | 571 | assert_equal 500.kilobyte, c.comments.size |
|
570 | 572 | end |
|
571 | 573 | |
|
572 | 574 | def test_identifier |
|
573 | 575 | c = Changeset.find_by_revision('1') |
|
574 | 576 | assert_equal c.revision, c.identifier |
|
575 | 577 | end |
|
576 | 578 | end |
General Comments 0
You need to be logged in to leave comments.
Login now