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