annotate test/unit/changeset_test.rb @ 1516:b450a9d58aed redmine-2.4

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