annotate test/unit/changeset_test.rb @ 1464:261b3d9a4903 redmine-2.4

Update to Redmine 2.4 branch rev 12663
author Chris Cannam
date Tue, 14 Jan 2014 14:37:42 +0000
parents 433d4f72a19b
children e248c7af89ec
rev   line source
Chris@0 1 # encoding: utf-8
Chris@0 2 #
Chris@0 3 # Redmine - project management software
Chris@1464 4 # Copyright (C) 2006-2013 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@0 348 def test_previous
Chris@0 349 changeset = Changeset.find_by_revision('3')
Chris@0 350 assert_equal Changeset.find_by_revision('2'), changeset.previous
Chris@0 351 end
Chris@0 352
Chris@0 353 def test_previous_nil
Chris@0 354 changeset = Changeset.find_by_revision('1')
Chris@0 355 assert_nil changeset.previous
Chris@0 356 end
Chris@0 357
Chris@0 358 def test_next
Chris@0 359 changeset = Changeset.find_by_revision('2')
Chris@0 360 assert_equal Changeset.find_by_revision('3'), changeset.next
Chris@0 361 end
Chris@0 362
Chris@0 363 def test_next_nil
Chris@0 364 changeset = Changeset.find_by_revision('10')
Chris@0 365 assert_nil changeset.next
Chris@0 366 end
Chris@245 367
Chris@0 368 def test_comments_should_be_converted_to_utf8
Chris@441 369 proj = Project.find(3)
Chris@441 370 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
Chris@441 371 str = "Texte encod\xe9 en ISO-8859-1."
Chris@441 372 str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding)
Chris@441 373 r = Repository::Bazaar.create!(
Chris@441 374 :project => proj,
Chris@441 375 :url => '/tmp/test/bazaar',
Chris@245 376 :log_encoding => 'ISO-8859-1' )
Chris@441 377 assert r
Chris@441 378 c = Changeset.new(:repository => r,
Chris@441 379 :committed_on => Time.now,
Chris@441 380 :revision => '123',
Chris@441 381 :scmid => '12345',
Chris@441 382 :comments => str)
Chris@441 383 assert( c.save )
Chris@441 384 str_utf8 = "Texte encod\xc3\xa9 en ISO-8859-1."
Chris@441 385 str_utf8.force_encoding("UTF-8") if str_utf8.respond_to?(:force_encoding)
Chris@441 386 assert_equal str_utf8, c.comments
Chris@0 387 end
Chris@245 388
Chris@441 389 def test_invalid_utf8_sequences_in_comments_should_be_replaced_latin1
Chris@441 390 proj = Project.find(3)
Chris@441 391 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
Chris@441 392 str1 = "Texte encod\xe9 en ISO-8859-1."
Chris@441 393 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
Chris@441 394 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
Chris@441 395 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
Chris@441 396 r = Repository::Bazaar.create!(
Chris@441 397 :project => proj,
Chris@441 398 :url => '/tmp/test/bazaar',
Chris@245 399 :log_encoding => 'UTF-8' )
Chris@441 400 assert r
Chris@441 401 c = Changeset.new(:repository => r,
Chris@441 402 :committed_on => Time.now,
Chris@441 403 :revision => '123',
Chris@441 404 :scmid => '12345',
Chris@441 405 :comments => str1,
Chris@441 406 :committer => str2)
Chris@441 407 assert( c.save )
Chris@441 408 assert_equal "Texte encod? en ISO-8859-1.", c.comments
Chris@441 409 assert_equal "?a?b?c?d?e test", c.committer
Chris@441 410 end
Chris@441 411
Chris@441 412 def test_invalid_utf8_sequences_in_comments_should_be_replaced_ja_jis
Chris@441 413 proj = Project.find(3)
Chris@441 414 str = "test\xb5\xfetest\xb5\xfe"
Chris@441 415 if str.respond_to?(:force_encoding)
Chris@441 416 str.force_encoding('ASCII-8BIT')
Chris@441 417 end
Chris@441 418 r = Repository::Bazaar.create!(
Chris@441 419 :project => proj,
Chris@441 420 :url => '/tmp/test/bazaar',
Chris@441 421 :log_encoding => 'ISO-2022-JP' )
Chris@441 422 assert r
Chris@441 423 c = Changeset.new(:repository => r,
Chris@441 424 :committed_on => Time.now,
Chris@441 425 :revision => '123',
Chris@441 426 :scmid => '12345',
Chris@441 427 :comments => str)
Chris@441 428 assert( c.save )
Chris@441 429 assert_equal "test??test??", c.comments
Chris@245 430 end
Chris@245 431
Chris@245 432 def test_comments_should_be_converted_all_latin1_to_utf8
Chris@441 433 s1 = "\xC2\x80"
Chris@441 434 s2 = "\xc3\x82\xc2\x80"
Chris@441 435 s4 = s2.dup
Chris@441 436 if s1.respond_to?(:force_encoding)
Chris@441 437 s3 = s1.dup
Chris@441 438 s1.force_encoding('ASCII-8BIT')
Chris@441 439 s2.force_encoding('ASCII-8BIT')
Chris@441 440 s3.force_encoding('ISO-8859-1')
Chris@441 441 s4.force_encoding('UTF-8')
Chris@441 442 assert_equal s3.encode('UTF-8'), s4
Chris@441 443 end
Chris@441 444 proj = Project.find(3)
Chris@441 445 r = Repository::Bazaar.create!(
Chris@441 446 :project => proj,
Chris@441 447 :url => '/tmp/test/bazaar',
Chris@245 448 :log_encoding => 'ISO-8859-1' )
Chris@441 449 assert r
Chris@441 450 c = Changeset.new(:repository => r,
Chris@441 451 :committed_on => Time.now,
Chris@441 452 :revision => '123',
Chris@441 453 :scmid => '12345',
Chris@441 454 :comments => s1)
Chris@441 455 assert( c.save )
Chris@441 456 assert_equal s4, c.comments
Chris@441 457 end
Chris@441 458
Chris@441 459 def test_invalid_utf8_sequences_in_paths_should_be_replaced
Chris@441 460 proj = Project.find(3)
Chris@441 461 str1 = "Texte encod\xe9 en ISO-8859-1"
Chris@441 462 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
Chris@441 463 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
Chris@441 464 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
Chris@441 465 r = Repository::Bazaar.create!(
Chris@441 466 :project => proj,
Chris@441 467 :url => '/tmp/test/bazaar',
Chris@441 468 :log_encoding => 'UTF-8' )
Chris@441 469 assert r
Chris@441 470 cs = Changeset.new(
Chris@441 471 :repository => r,
Chris@441 472 :committed_on => Time.now,
Chris@441 473 :revision => '123',
Chris@441 474 :scmid => '12345',
Chris@441 475 :comments => "test")
Chris@441 476 assert(cs.save)
Chris@441 477 ch = Change.new(
Chris@441 478 :changeset => cs,
Chris@441 479 :action => "A",
Chris@441 480 :path => str1,
Chris@441 481 :from_path => str2,
Chris@441 482 :from_revision => "345")
Chris@441 483 assert(ch.save)
Chris@441 484 assert_equal "Texte encod? en ISO-8859-1", ch.path
Chris@441 485 assert_equal "?a?b?c?d?e test", ch.from_path
Chris@441 486 end
Chris@441 487
Chris@441 488 def test_comments_nil
Chris@441 489 proj = Project.find(3)
Chris@441 490 r = Repository::Bazaar.create!(
Chris@441 491 :project => proj,
Chris@441 492 :url => '/tmp/test/bazaar',
Chris@441 493 :log_encoding => 'ISO-8859-1' )
Chris@441 494 assert r
Chris@441 495 c = Changeset.new(:repository => r,
Chris@441 496 :committed_on => Time.now,
Chris@441 497 :revision => '123',
Chris@441 498 :scmid => '12345',
Chris@441 499 :comments => nil,
Chris@441 500 :committer => nil)
Chris@441 501 assert( c.save )
Chris@441 502 assert_equal "", c.comments
Chris@441 503 assert_equal nil, c.committer
Chris@441 504 if c.comments.respond_to?(:force_encoding)
Chris@441 505 assert_equal "UTF-8", c.comments.encoding.to_s
Chris@441 506 end
Chris@441 507 end
Chris@441 508
Chris@441 509 def test_comments_empty
Chris@441 510 proj = Project.find(3)
Chris@441 511 r = Repository::Bazaar.create!(
Chris@441 512 :project => proj,
Chris@441 513 :url => '/tmp/test/bazaar',
Chris@441 514 :log_encoding => 'ISO-8859-1' )
Chris@441 515 assert r
Chris@441 516 c = Changeset.new(:repository => r,
Chris@441 517 :committed_on => Time.now,
Chris@441 518 :revision => '123',
Chris@441 519 :scmid => '12345',
Chris@441 520 :comments => "",
Chris@441 521 :committer => "")
Chris@441 522 assert( c.save )
Chris@441 523 assert_equal "", c.comments
Chris@441 524 assert_equal "", c.committer
Chris@441 525 if c.comments.respond_to?(:force_encoding)
Chris@441 526 assert_equal "UTF-8", c.comments.encoding.to_s
Chris@441 527 assert_equal "UTF-8", c.committer.encoding.to_s
Chris@441 528 end
Chris@0 529 end
Chris@119 530
Chris@119 531 def test_identifier
Chris@119 532 c = Changeset.find_by_revision('1')
Chris@119 533 assert_equal c.revision, c.identifier
Chris@119 534 end
Chris@0 535 end