annotate test/unit/changeset_test.rb @ 1628:9c5f8e24dadc live tip

Quieten this cron script
author Chris Cannam
date Tue, 25 Aug 2020 11:38:49 +0100
parents dffacf8a6908
children
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@1517 99 time = TimeEntry.order('id desc').first
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@1517 114 Setting.commit_update_keywords = [{'keywords' => 'fixes , closes',
Chris@1517 115 'status_id' => IssueStatus.where(:is_closed => true).first.id.to_s}]
Chris@119 116 Setting.commit_logtime_enabled = '1'
Chris@909 117
Chris@441 118 c = Changeset.new(:repository => Project.find(1).repository,
Chris@119 119 :committed_on => Time.now,
Chris@441 120 :comments => 'This is a comment. Fixes #1 @4.5, #2 @1',
Chris@441 121 :user => User.find(2))
Chris@119 122 assert_difference 'TimeEntry.count', 2 do
Chris@119 123 c.scan_comment_for_issue_ids
Chris@119 124 end
Chris@441 125
Chris@119 126 assert_equal [1, 2], c.issue_ids.sort
Chris@119 127 assert Issue.find(1).closed?
Chris@119 128 assert Issue.find(2).closed?
Chris@119 129
Chris@1517 130 times = TimeEntry.order('id desc').limit(2)
Chris@119 131 assert_equal [1, 2], times.collect(&:issue_id).sort
Chris@119 132 end
Chris@441 133
Chris@0 134 def test_ref_keywords_any_line_start
Chris@0 135 Setting.commit_ref_keywords = '*'
Chris@441 136 c = Changeset.new(:repository => Project.find(1).repository,
Chris@0 137 :committed_on => Time.now,
Chris@909 138 :comments => '#1 is the reason of this commit',
Chris@909 139 :revision => '12345')
Chris@909 140 assert c.save
Chris@0 141 assert_equal [1], c.issue_ids.sort
Chris@0 142 end
Chris@0 143
Chris@0 144 def test_ref_keywords_allow_brackets_around_a_issue_number
Chris@0 145 Setting.commit_ref_keywords = '*'
Chris@441 146 c = Changeset.new(:repository => Project.find(1).repository,
Chris@0 147 :committed_on => Time.now,
Chris@909 148 :comments => '[#1] Worked on this issue',
Chris@909 149 :revision => '12345')
Chris@909 150 assert c.save
Chris@0 151 assert_equal [1], c.issue_ids.sort
Chris@0 152 end
Chris@0 153
Chris@0 154 def test_ref_keywords_allow_brackets_around_multiple_issue_numbers
Chris@0 155 Setting.commit_ref_keywords = '*'
Chris@441 156 c = Changeset.new(:repository => Project.find(1).repository,
Chris@0 157 :committed_on => Time.now,
Chris@909 158 :comments => '[#1 #2, #3] Worked on these',
Chris@909 159 :revision => '12345')
Chris@909 160 assert c.save
Chris@0 161 assert_equal [1,2,3], c.issue_ids.sort
Chris@0 162 end
Chris@441 163
Chris@1464 164 def test_update_keywords_with_multiple_rules
Chris@1464 165 with_settings :commit_update_keywords => [
Chris@1464 166 {'keywords' => 'fixes, closes', 'status_id' => '5'},
Chris@1464 167 {'keywords' => 'resolves', 'status_id' => '3'}
Chris@1464 168 ] do
Chris@1464 169
Chris@1464 170 issue1 = Issue.generate!
Chris@1464 171 issue2 = Issue.generate!
Chris@1464 172 Changeset.generate!(:comments => "Closes ##{issue1.id}\nResolves ##{issue2.id}")
Chris@1464 173 assert_equal 5, issue1.reload.status_id
Chris@1464 174 assert_equal 3, issue2.reload.status_id
Chris@1464 175 end
Chris@1464 176 end
Chris@1464 177
Chris@1464 178 def test_update_keywords_with_multiple_rules_should_match_tracker
Chris@1464 179 with_settings :commit_update_keywords => [
Chris@1464 180 {'keywords' => 'fixes', 'status_id' => '5', 'if_tracker_id' => '2'},
Chris@1464 181 {'keywords' => 'fixes', 'status_id' => '3', 'if_tracker_id' => ''}
Chris@1464 182 ] do
Chris@1464 183
Chris@1464 184 issue1 = Issue.generate!(:tracker_id => 2)
Chris@1464 185 issue2 = Issue.generate!
Chris@1464 186 Changeset.generate!(:comments => "Fixes ##{issue1.id}, ##{issue2.id}")
Chris@1464 187 assert_equal 5, issue1.reload.status_id
Chris@1464 188 assert_equal 3, issue2.reload.status_id
Chris@1464 189 end
Chris@1464 190 end
Chris@1464 191
Chris@1464 192 def test_update_keywords_with_multiple_rules_and_no_match
Chris@1464 193 with_settings :commit_update_keywords => [
Chris@1464 194 {'keywords' => 'fixes', 'status_id' => '5', 'if_tracker_id' => '2'},
Chris@1464 195 {'keywords' => 'fixes', 'status_id' => '3', 'if_tracker_id' => '3'}
Chris@1464 196 ] do
Chris@1464 197
Chris@1464 198 issue1 = Issue.generate!(:tracker_id => 2)
Chris@1464 199 issue2 = Issue.generate!
Chris@1464 200 Changeset.generate!(:comments => "Fixes ##{issue1.id}, ##{issue2.id}")
Chris@1464 201 assert_equal 5, issue1.reload.status_id
Chris@1464 202 assert_equal 1, issue2.reload.status_id # no updates
Chris@1464 203 end
Chris@1464 204 end
Chris@1464 205
Chris@0 206 def test_commit_referencing_a_subproject_issue
Chris@441 207 c = Changeset.new(:repository => Project.find(1).repository,
Chris@0 208 :committed_on => Time.now,
Chris@909 209 :comments => 'refs #5, a subproject issue',
Chris@909 210 :revision => '12345')
Chris@909 211 assert c.save
Chris@0 212 assert_equal [5], c.issue_ids.sort
Chris@0 213 assert c.issues.first.project != c.project
Chris@0 214 end
Chris@0 215
Chris@929 216 def test_commit_closing_a_subproject_issue
Chris@1464 217 with_settings :commit_update_keywords => [{'keywords' => 'closes', 'status_id' => '5'}],
Chris@1115 218 :default_language => 'en' do
Chris@929 219 issue = Issue.find(5)
Chris@929 220 assert !issue.closed?
Chris@929 221 assert_difference 'Journal.count' do
Chris@929 222 c = Changeset.new(:repository => Project.find(1).repository,
Chris@929 223 :committed_on => Time.now,
Chris@929 224 :comments => 'closes #5, a subproject issue',
Chris@929 225 :revision => '12345')
Chris@929 226 assert c.save
Chris@929 227 end
Chris@929 228 assert issue.reload.closed?
Chris@1517 229 journal = Journal.order('id DESC').first
Chris@929 230 assert_equal issue, journal.issue
Chris@929 231 assert_include "Applied in changeset ecookbook:r12345.", journal.notes
Chris@929 232 end
Chris@929 233 end
Chris@929 234
Chris@0 235 def test_commit_referencing_a_parent_project_issue
Chris@0 236 # repository of child project
Chris@441 237 r = Repository::Subversion.create!(
Chris@441 238 :project => Project.find(3),
Chris@441 239 :url => 'svn://localhost/test')
Chris@441 240 c = Changeset.new(:repository => r,
Chris@0 241 :committed_on => Time.now,
Chris@909 242 :comments => 'refs #2, an issue of a parent project',
Chris@909 243 :revision => '12345')
Chris@909 244 assert c.save
Chris@0 245 assert_equal [2], c.issue_ids.sort
Chris@0 246 assert c.issues.first.project != c.project
Chris@0 247 end
Chris@245 248
Chris@1115 249 def test_commit_referencing_a_project_with_commit_cross_project_ref_disabled
Chris@1115 250 r = Repository::Subversion.create!(
Chris@1115 251 :project => Project.find(3),
Chris@1115 252 :url => 'svn://localhost/test')
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 with_settings :commit_cross_project_ref => '1' do
Chris@1115 268 c = Changeset.new(:repository => r,
Chris@1115 269 :committed_on => Time.now,
Chris@1115 270 :comments => 'refs #4, an issue of a different project',
Chris@1115 271 :revision => '12345')
Chris@1115 272 assert c.save
Chris@1115 273 assert_equal [4], c.issue_ids
Chris@1115 274 end
Chris@1115 275 end
Chris@1115 276
Chris@1464 277 def test_old_commits_should_not_update_issues_nor_log_time
Chris@1464 278 Setting.commit_ref_keywords = '*'
Chris@1464 279 Setting.commit_update_keywords = {'fixes , closes' => {'status_id' => '5', 'done_ratio' => '90'}}
Chris@1464 280 Setting.commit_logtime_enabled = '1'
Chris@1464 281
Chris@1464 282 repository = Project.find(1).repository
Chris@1464 283 repository.created_on = Time.now
Chris@1464 284 repository.save!
Chris@1464 285
Chris@1464 286 c = Changeset.new(:repository => repository,
Chris@1464 287 :committed_on => 1.month.ago,
Chris@1464 288 :comments => 'New commit (#2). Fixes #1 @1h',
Chris@1464 289 :revision => '12345')
Chris@1464 290 assert_no_difference 'TimeEntry.count' do
Chris@1464 291 assert c.save
Chris@1464 292 end
Chris@1464 293 assert_equal [1, 2], c.issue_ids.sort
Chris@1464 294 issue = Issue.find(1)
Chris@1464 295 assert_equal 1, issue.status_id
Chris@1464 296 assert_equal 0, issue.done_ratio
Chris@1464 297 end
Chris@1464 298
Chris@119 299 def test_text_tag_revision
Chris@119 300 c = Changeset.new(:revision => '520')
Chris@119 301 assert_equal 'r520', c.text_tag
Chris@119 302 end
Chris@245 303
Chris@929 304 def test_text_tag_revision_with_same_project
Chris@929 305 c = Changeset.new(:revision => '520', :repository => Project.find(1).repository)
Chris@929 306 assert_equal 'r520', c.text_tag(Project.find(1))
Chris@929 307 end
Chris@929 308
Chris@929 309 def test_text_tag_revision_with_different_project
Chris@929 310 c = Changeset.new(:revision => '520', :repository => Project.find(1).repository)
Chris@929 311 assert_equal 'ecookbook:r520', c.text_tag(Project.find(2))
Chris@929 312 end
Chris@929 313
Chris@1115 314 def test_text_tag_revision_with_repository_identifier
Chris@1115 315 r = Repository::Subversion.create!(
Chris@1115 316 :project_id => 1,
Chris@1115 317 :url => 'svn://localhost/test',
Chris@1115 318 :identifier => 'documents')
Chris@1115 319 c = Changeset.new(:revision => '520', :repository => r)
Chris@1115 320 assert_equal 'documents|r520', c.text_tag
Chris@1115 321 assert_equal 'ecookbook:documents|r520', c.text_tag(Project.find(2))
Chris@1115 322 end
Chris@1115 323
Chris@119 324 def test_text_tag_hash
Chris@441 325 c = Changeset.new(
Chris@441 326 :scmid => '7234cb2750b63f47bff735edc50a1c0a433c2518',
Chris@441 327 :revision => '7234cb2750b63f47bff735edc50a1c0a433c2518')
Chris@119 328 assert_equal 'commit:7234cb2750b63f47bff735edc50a1c0a433c2518', c.text_tag
Chris@119 329 end
Chris@119 330
Chris@929 331 def test_text_tag_hash_with_same_project
Chris@929 332 c = Changeset.new(:revision => '7234cb27', :scmid => '7234cb27', :repository => Project.find(1).repository)
Chris@929 333 assert_equal 'commit:7234cb27', c.text_tag(Project.find(1))
Chris@929 334 end
Chris@929 335
Chris@929 336 def test_text_tag_hash_with_different_project
Chris@929 337 c = Changeset.new(:revision => '7234cb27', :scmid => '7234cb27', :repository => Project.find(1).repository)
Chris@929 338 assert_equal 'ecookbook:commit:7234cb27', c.text_tag(Project.find(2))
Chris@929 339 end
Chris@929 340
Chris@119 341 def test_text_tag_hash_all_number
Chris@119 342 c = Changeset.new(:scmid => '0123456789', :revision => '0123456789')
Chris@119 343 assert_equal 'commit:0123456789', c.text_tag
Chris@119 344 end
Chris@0 345
Chris@1494 346 def test_text_tag_hash_with_repository_identifier
Chris@1494 347 r = Repository::Subversion.new(
Chris@1494 348 :project_id => 1,
Chris@1494 349 :url => 'svn://localhost/test',
Chris@1494 350 :identifier => 'documents')
Chris@1494 351 c = Changeset.new(:revision => '7234cb27', :scmid => '7234cb27', :repository => r)
Chris@1494 352 assert_equal 'commit:documents|7234cb27', c.text_tag
Chris@1494 353 assert_equal 'ecookbook:commit:documents|7234cb27', c.text_tag(Project.find(2))
Chris@1494 354 end
Chris@1494 355
Chris@0 356 def test_previous
Chris@0 357 changeset = Changeset.find_by_revision('3')
Chris@0 358 assert_equal Changeset.find_by_revision('2'), changeset.previous
Chris@0 359 end
Chris@0 360
Chris@0 361 def test_previous_nil
Chris@0 362 changeset = Changeset.find_by_revision('1')
Chris@0 363 assert_nil changeset.previous
Chris@0 364 end
Chris@0 365
Chris@0 366 def test_next
Chris@0 367 changeset = Changeset.find_by_revision('2')
Chris@0 368 assert_equal Changeset.find_by_revision('3'), changeset.next
Chris@0 369 end
Chris@0 370
Chris@0 371 def test_next_nil
Chris@0 372 changeset = Changeset.find_by_revision('10')
Chris@0 373 assert_nil changeset.next
Chris@0 374 end
Chris@245 375
Chris@0 376 def test_comments_should_be_converted_to_utf8
Chris@441 377 proj = Project.find(3)
Chris@441 378 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
Chris@441 379 str = "Texte encod\xe9 en ISO-8859-1."
Chris@441 380 str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding)
Chris@441 381 r = Repository::Bazaar.create!(
Chris@441 382 :project => proj,
Chris@441 383 :url => '/tmp/test/bazaar',
Chris@245 384 :log_encoding => 'ISO-8859-1' )
Chris@441 385 assert r
Chris@441 386 c = Changeset.new(:repository => r,
Chris@441 387 :committed_on => Time.now,
Chris@441 388 :revision => '123',
Chris@441 389 :scmid => '12345',
Chris@441 390 :comments => str)
Chris@441 391 assert( c.save )
Chris@441 392 str_utf8 = "Texte encod\xc3\xa9 en ISO-8859-1."
Chris@441 393 str_utf8.force_encoding("UTF-8") if str_utf8.respond_to?(:force_encoding)
Chris@441 394 assert_equal str_utf8, c.comments
Chris@0 395 end
Chris@245 396
Chris@441 397 def test_invalid_utf8_sequences_in_comments_should_be_replaced_latin1
Chris@441 398 proj = Project.find(3)
Chris@441 399 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
Chris@441 400 str1 = "Texte encod\xe9 en ISO-8859-1."
Chris@441 401 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
Chris@441 402 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
Chris@441 403 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
Chris@441 404 r = Repository::Bazaar.create!(
Chris@441 405 :project => proj,
Chris@441 406 :url => '/tmp/test/bazaar',
Chris@245 407 :log_encoding => 'UTF-8' )
Chris@441 408 assert r
Chris@441 409 c = Changeset.new(:repository => r,
Chris@441 410 :committed_on => Time.now,
Chris@441 411 :revision => '123',
Chris@441 412 :scmid => '12345',
Chris@441 413 :comments => str1,
Chris@441 414 :committer => str2)
Chris@441 415 assert( c.save )
Chris@441 416 assert_equal "Texte encod? en ISO-8859-1.", c.comments
Chris@441 417 assert_equal "?a?b?c?d?e test", c.committer
Chris@441 418 end
Chris@441 419
Chris@441 420 def test_invalid_utf8_sequences_in_comments_should_be_replaced_ja_jis
Chris@441 421 proj = Project.find(3)
Chris@441 422 str = "test\xb5\xfetest\xb5\xfe"
Chris@441 423 if str.respond_to?(:force_encoding)
Chris@441 424 str.force_encoding('ASCII-8BIT')
Chris@441 425 end
Chris@441 426 r = Repository::Bazaar.create!(
Chris@441 427 :project => proj,
Chris@441 428 :url => '/tmp/test/bazaar',
Chris@441 429 :log_encoding => 'ISO-2022-JP' )
Chris@441 430 assert r
Chris@441 431 c = Changeset.new(:repository => r,
Chris@441 432 :committed_on => Time.now,
Chris@441 433 :revision => '123',
Chris@441 434 :scmid => '12345',
Chris@441 435 :comments => str)
Chris@441 436 assert( c.save )
Chris@441 437 assert_equal "test??test??", c.comments
Chris@245 438 end
Chris@245 439
Chris@245 440 def test_comments_should_be_converted_all_latin1_to_utf8
Chris@441 441 s1 = "\xC2\x80"
Chris@441 442 s2 = "\xc3\x82\xc2\x80"
Chris@441 443 s4 = s2.dup
Chris@441 444 if s1.respond_to?(:force_encoding)
Chris@441 445 s3 = s1.dup
Chris@441 446 s1.force_encoding('ASCII-8BIT')
Chris@441 447 s2.force_encoding('ASCII-8BIT')
Chris@441 448 s3.force_encoding('ISO-8859-1')
Chris@441 449 s4.force_encoding('UTF-8')
Chris@441 450 assert_equal s3.encode('UTF-8'), s4
Chris@441 451 end
Chris@441 452 proj = Project.find(3)
Chris@441 453 r = Repository::Bazaar.create!(
Chris@441 454 :project => proj,
Chris@441 455 :url => '/tmp/test/bazaar',
Chris@245 456 :log_encoding => 'ISO-8859-1' )
Chris@441 457 assert r
Chris@441 458 c = Changeset.new(:repository => r,
Chris@441 459 :committed_on => Time.now,
Chris@441 460 :revision => '123',
Chris@441 461 :scmid => '12345',
Chris@441 462 :comments => s1)
Chris@441 463 assert( c.save )
Chris@441 464 assert_equal s4, c.comments
Chris@441 465 end
Chris@441 466
Chris@441 467 def test_invalid_utf8_sequences_in_paths_should_be_replaced
Chris@441 468 proj = Project.find(3)
Chris@441 469 str1 = "Texte encod\xe9 en ISO-8859-1"
Chris@441 470 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
Chris@441 471 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
Chris@441 472 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
Chris@441 473 r = Repository::Bazaar.create!(
Chris@441 474 :project => proj,
Chris@441 475 :url => '/tmp/test/bazaar',
Chris@441 476 :log_encoding => 'UTF-8' )
Chris@441 477 assert r
Chris@441 478 cs = Changeset.new(
Chris@441 479 :repository => r,
Chris@441 480 :committed_on => Time.now,
Chris@441 481 :revision => '123',
Chris@441 482 :scmid => '12345',
Chris@441 483 :comments => "test")
Chris@441 484 assert(cs.save)
Chris@441 485 ch = Change.new(
Chris@441 486 :changeset => cs,
Chris@441 487 :action => "A",
Chris@441 488 :path => str1,
Chris@441 489 :from_path => str2,
Chris@441 490 :from_revision => "345")
Chris@441 491 assert(ch.save)
Chris@441 492 assert_equal "Texte encod? en ISO-8859-1", ch.path
Chris@441 493 assert_equal "?a?b?c?d?e test", ch.from_path
Chris@441 494 end
Chris@441 495
Chris@441 496 def test_comments_nil
Chris@441 497 proj = Project.find(3)
Chris@441 498 r = Repository::Bazaar.create!(
Chris@441 499 :project => proj,
Chris@441 500 :url => '/tmp/test/bazaar',
Chris@441 501 :log_encoding => 'ISO-8859-1' )
Chris@441 502 assert r
Chris@441 503 c = Changeset.new(:repository => r,
Chris@441 504 :committed_on => Time.now,
Chris@441 505 :revision => '123',
Chris@441 506 :scmid => '12345',
Chris@441 507 :comments => nil,
Chris@441 508 :committer => nil)
Chris@441 509 assert( c.save )
Chris@441 510 assert_equal "", c.comments
Chris@441 511 assert_equal nil, c.committer
Chris@441 512 if c.comments.respond_to?(:force_encoding)
Chris@441 513 assert_equal "UTF-8", c.comments.encoding.to_s
Chris@441 514 end
Chris@441 515 end
Chris@441 516
Chris@441 517 def test_comments_empty
Chris@441 518 proj = Project.find(3)
Chris@441 519 r = Repository::Bazaar.create!(
Chris@441 520 :project => proj,
Chris@441 521 :url => '/tmp/test/bazaar',
Chris@441 522 :log_encoding => 'ISO-8859-1' )
Chris@441 523 assert r
Chris@441 524 c = Changeset.new(:repository => r,
Chris@441 525 :committed_on => Time.now,
Chris@441 526 :revision => '123',
Chris@441 527 :scmid => '12345',
Chris@441 528 :comments => "",
Chris@441 529 :committer => "")
Chris@441 530 assert( c.save )
Chris@441 531 assert_equal "", c.comments
Chris@441 532 assert_equal "", c.committer
Chris@441 533 if c.comments.respond_to?(:force_encoding)
Chris@441 534 assert_equal "UTF-8", c.comments.encoding.to_s
Chris@441 535 assert_equal "UTF-8", c.committer.encoding.to_s
Chris@441 536 end
Chris@0 537 end
Chris@119 538
Chris@1517 539 def test_comments_should_accept_more_than_64k
Chris@1517 540 c = Changeset.new(:repository => Repository.first,
Chris@1517 541 :committed_on => Time.now,
Chris@1517 542 :revision => '123',
Chris@1517 543 :scmid => '12345',
Chris@1517 544 :comments => "a" * 500.kilobyte)
Chris@1517 545 assert c.save
Chris@1517 546 c.reload
Chris@1517 547 assert_equal 500.kilobyte, c.comments.size
Chris@1517 548 end
Chris@1517 549
Chris@119 550 def test_identifier
Chris@119 551 c = Changeset.find_by_revision('1')
Chris@119 552 assert_equal c.revision, c.identifier
Chris@119 553 end
Chris@0 554 end