annotate .svn/pristine/5d/5d77150ffce84de102397cf62ea517a3fc5da2e0.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

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