annotate .svn/pristine/9d/9de0981c528be3c395629de4fb2f38d49f57b9ed.svn-base @ 1477:f2ad2199b49a bibplugin_integration

Close obsolete branch bibplugin_integration
author Chris Cannam
date Fri, 30 Nov 2012 14:41:31 +0000
parents cbb26bc654de
children
rev   line source
Chris@909 1 # encoding: utf-8
Chris@909 2 #
Chris@909 3 # Redmine - project management software
Chris@909 4 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@909 5 #
Chris@909 6 # This program is free software; you can redistribute it and/or
Chris@909 7 # modify it under the terms of the GNU General Public License
Chris@909 8 # as published by the Free Software Foundation; either version 2
Chris@909 9 # of the License, or (at your option) any later version.
Chris@909 10 #
Chris@909 11 # This program is distributed in the hope that it will be useful,
Chris@909 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@909 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@909 14 # GNU General Public License for more details.
Chris@909 15 #
Chris@909 16 # You should have received a copy of the GNU General Public License
Chris@909 17 # along with this program; if not, write to the Free Software
Chris@909 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@909 19
Chris@909 20 require File.expand_path('../../test_helper', __FILE__)
Chris@909 21
Chris@909 22 class ChangesetTest < ActiveSupport::TestCase
Chris@909 23 fixtures :projects, :repositories,
Chris@909 24 :issues, :issue_statuses, :issue_categories,
Chris@909 25 :changesets, :changes,
Chris@909 26 :enumerations,
Chris@909 27 :custom_fields, :custom_values,
Chris@909 28 :users, :members, :member_roles, :trackers,
Chris@909 29 :enabled_modules, :roles
Chris@909 30
Chris@909 31 def setup
Chris@909 32 end
Chris@909 33
Chris@909 34 def test_ref_keywords_any
Chris@909 35 ActionMailer::Base.deliveries.clear
Chris@909 36 Setting.commit_fix_status_id = IssueStatus.find(
Chris@909 37 :first, :conditions => ["is_closed = ?", true]).id
Chris@909 38 Setting.commit_fix_done_ratio = '90'
Chris@909 39 Setting.commit_ref_keywords = '*'
Chris@909 40 Setting.commit_fix_keywords = 'fixes , closes'
Chris@909 41
Chris@909 42 c = Changeset.new(:repository => Project.find(1).repository,
Chris@909 43 :committed_on => Time.now,
Chris@909 44 :comments => 'New commit (#2). Fixes #1',
Chris@909 45 :revision => '12345')
Chris@909 46 assert c.save
Chris@909 47 assert_equal [1, 2], c.issue_ids.sort
Chris@909 48 fixed = Issue.find(1)
Chris@909 49 assert fixed.closed?
Chris@909 50 assert_equal 90, fixed.done_ratio
Chris@909 51 assert_equal 1, ActionMailer::Base.deliveries.size
Chris@909 52 end
Chris@909 53
Chris@909 54 def test_ref_keywords
Chris@909 55 Setting.commit_ref_keywords = 'refs'
Chris@909 56 Setting.commit_fix_keywords = ''
Chris@909 57 c = Changeset.new(:repository => Project.find(1).repository,
Chris@909 58 :committed_on => Time.now,
Chris@909 59 :comments => 'Ignores #2. Refs #1',
Chris@909 60 :revision => '12345')
Chris@909 61 assert c.save
Chris@909 62 assert_equal [1], c.issue_ids.sort
Chris@909 63 end
Chris@909 64
Chris@909 65 def test_ref_keywords_any_only
Chris@909 66 Setting.commit_ref_keywords = '*'
Chris@909 67 Setting.commit_fix_keywords = ''
Chris@909 68 c = Changeset.new(:repository => Project.find(1).repository,
Chris@909 69 :committed_on => Time.now,
Chris@909 70 :comments => 'Ignores #2. Refs #1',
Chris@909 71 :revision => '12345')
Chris@909 72 assert c.save
Chris@909 73 assert_equal [1, 2], c.issue_ids.sort
Chris@909 74 end
Chris@909 75
Chris@909 76 def test_ref_keywords_any_with_timelog
Chris@909 77 Setting.commit_ref_keywords = '*'
Chris@909 78 Setting.commit_logtime_enabled = '1'
Chris@909 79
Chris@909 80 {
Chris@909 81 '2' => 2.0,
Chris@909 82 '2h' => 2.0,
Chris@909 83 '2hours' => 2.0,
Chris@909 84 '15m' => 0.25,
Chris@909 85 '15min' => 0.25,
Chris@909 86 '3h15' => 3.25,
Chris@909 87 '3h15m' => 3.25,
Chris@909 88 '3h15min' => 3.25,
Chris@909 89 '3:15' => 3.25,
Chris@909 90 '3.25' => 3.25,
Chris@909 91 '3.25h' => 3.25,
Chris@909 92 '3,25' => 3.25,
Chris@909 93 '3,25h' => 3.25,
Chris@909 94 }.each do |syntax, expected_hours|
Chris@909 95 c = Changeset.new(:repository => Project.find(1).repository,
Chris@909 96 :committed_on => 24.hours.ago,
Chris@909 97 :comments => "Worked on this issue #1 @#{syntax}",
Chris@909 98 :revision => '520',
Chris@909 99 :user => User.find(2))
Chris@909 100 assert_difference 'TimeEntry.count' do
Chris@909 101 c.scan_comment_for_issue_ids
Chris@909 102 end
Chris@909 103 assert_equal [1], c.issue_ids.sort
Chris@909 104
Chris@909 105 time = TimeEntry.first(:order => 'id desc')
Chris@909 106 assert_equal 1, time.issue_id
Chris@909 107 assert_equal 1, time.project_id
Chris@909 108 assert_equal 2, time.user_id
Chris@909 109 assert_equal expected_hours, time.hours,
Chris@909 110 "@#{syntax} should be logged as #{expected_hours} hours but was #{time.hours}"
Chris@909 111 assert_equal Date.yesterday, time.spent_on
Chris@909 112 assert time.activity.is_default?
Chris@909 113 assert time.comments.include?('r520'),
Chris@909 114 "r520 was expected in time_entry comments: #{time.comments}"
Chris@909 115 end
Chris@909 116 end
Chris@909 117
Chris@909 118 def test_ref_keywords_closing_with_timelog
Chris@909 119 Setting.commit_fix_status_id = IssueStatus.find(
Chris@909 120 :first, :conditions => ["is_closed = ?", true]).id
Chris@909 121 Setting.commit_ref_keywords = '*'
Chris@909 122 Setting.commit_fix_keywords = 'fixes , closes'
Chris@909 123 Setting.commit_logtime_enabled = '1'
Chris@909 124
Chris@909 125 c = Changeset.new(:repository => Project.find(1).repository,
Chris@909 126 :committed_on => Time.now,
Chris@909 127 :comments => 'This is a comment. Fixes #1 @4.5, #2 @1',
Chris@909 128 :user => User.find(2))
Chris@909 129 assert_difference 'TimeEntry.count', 2 do
Chris@909 130 c.scan_comment_for_issue_ids
Chris@909 131 end
Chris@909 132
Chris@909 133 assert_equal [1, 2], c.issue_ids.sort
Chris@909 134 assert Issue.find(1).closed?
Chris@909 135 assert Issue.find(2).closed?
Chris@909 136
Chris@909 137 times = TimeEntry.all(:order => 'id desc', :limit => 2)
Chris@909 138 assert_equal [1, 2], times.collect(&:issue_id).sort
Chris@909 139 end
Chris@909 140
Chris@909 141 def test_ref_keywords_any_line_start
Chris@909 142 Setting.commit_ref_keywords = '*'
Chris@909 143 c = Changeset.new(:repository => Project.find(1).repository,
Chris@909 144 :committed_on => Time.now,
Chris@909 145 :comments => '#1 is the reason of this commit',
Chris@909 146 :revision => '12345')
Chris@909 147 assert c.save
Chris@909 148 assert_equal [1], c.issue_ids.sort
Chris@909 149 end
Chris@909 150
Chris@909 151 def test_ref_keywords_allow_brackets_around_a_issue_number
Chris@909 152 Setting.commit_ref_keywords = '*'
Chris@909 153 c = Changeset.new(:repository => Project.find(1).repository,
Chris@909 154 :committed_on => Time.now,
Chris@909 155 :comments => '[#1] Worked on this issue',
Chris@909 156 :revision => '12345')
Chris@909 157 assert c.save
Chris@909 158 assert_equal [1], c.issue_ids.sort
Chris@909 159 end
Chris@909 160
Chris@909 161 def test_ref_keywords_allow_brackets_around_multiple_issue_numbers
Chris@909 162 Setting.commit_ref_keywords = '*'
Chris@909 163 c = Changeset.new(:repository => Project.find(1).repository,
Chris@909 164 :committed_on => Time.now,
Chris@909 165 :comments => '[#1 #2, #3] Worked on these',
Chris@909 166 :revision => '12345')
Chris@909 167 assert c.save
Chris@909 168 assert_equal [1,2,3], c.issue_ids.sort
Chris@909 169 end
Chris@909 170
Chris@909 171 def test_commit_referencing_a_subproject_issue
Chris@909 172 c = Changeset.new(:repository => Project.find(1).repository,
Chris@909 173 :committed_on => Time.now,
Chris@909 174 :comments => 'refs #5, a subproject issue',
Chris@909 175 :revision => '12345')
Chris@909 176 assert c.save
Chris@909 177 assert_equal [5], c.issue_ids.sort
Chris@909 178 assert c.issues.first.project != c.project
Chris@909 179 end
Chris@909 180
Chris@909 181 def test_commit_referencing_a_parent_project_issue
Chris@909 182 # repository of child project
Chris@909 183 r = Repository::Subversion.create!(
Chris@909 184 :project => Project.find(3),
Chris@909 185 :url => 'svn://localhost/test')
Chris@909 186 c = Changeset.new(:repository => r,
Chris@909 187 :committed_on => Time.now,
Chris@909 188 :comments => 'refs #2, an issue of a parent project',
Chris@909 189 :revision => '12345')
Chris@909 190 assert c.save
Chris@909 191 assert_equal [2], c.issue_ids.sort
Chris@909 192 assert c.issues.first.project != c.project
Chris@909 193 end
Chris@909 194
Chris@909 195 def test_text_tag_revision
Chris@909 196 c = Changeset.new(:revision => '520')
Chris@909 197 assert_equal 'r520', c.text_tag
Chris@909 198 end
Chris@909 199
Chris@909 200 def test_text_tag_hash
Chris@909 201 c = Changeset.new(
Chris@909 202 :scmid => '7234cb2750b63f47bff735edc50a1c0a433c2518',
Chris@909 203 :revision => '7234cb2750b63f47bff735edc50a1c0a433c2518')
Chris@909 204 assert_equal 'commit:7234cb2750b63f47bff735edc50a1c0a433c2518', c.text_tag
Chris@909 205 end
Chris@909 206
Chris@909 207 def test_text_tag_hash_all_number
Chris@909 208 c = Changeset.new(:scmid => '0123456789', :revision => '0123456789')
Chris@909 209 assert_equal 'commit:0123456789', c.text_tag
Chris@909 210 end
Chris@909 211
Chris@909 212 def test_previous
Chris@909 213 changeset = Changeset.find_by_revision('3')
Chris@909 214 assert_equal Changeset.find_by_revision('2'), changeset.previous
Chris@909 215 end
Chris@909 216
Chris@909 217 def test_previous_nil
Chris@909 218 changeset = Changeset.find_by_revision('1')
Chris@909 219 assert_nil changeset.previous
Chris@909 220 end
Chris@909 221
Chris@909 222 def test_next
Chris@909 223 changeset = Changeset.find_by_revision('2')
Chris@909 224 assert_equal Changeset.find_by_revision('3'), changeset.next
Chris@909 225 end
Chris@909 226
Chris@909 227 def test_next_nil
Chris@909 228 changeset = Changeset.find_by_revision('10')
Chris@909 229 assert_nil changeset.next
Chris@909 230 end
Chris@909 231
Chris@909 232 def test_comments_should_be_converted_to_utf8
Chris@909 233 proj = Project.find(3)
Chris@909 234 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
Chris@909 235 str = "Texte encod\xe9 en ISO-8859-1."
Chris@909 236 str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding)
Chris@909 237 r = Repository::Bazaar.create!(
Chris@909 238 :project => proj,
Chris@909 239 :url => '/tmp/test/bazaar',
Chris@909 240 :log_encoding => 'ISO-8859-1' )
Chris@909 241 assert r
Chris@909 242 c = Changeset.new(:repository => r,
Chris@909 243 :committed_on => Time.now,
Chris@909 244 :revision => '123',
Chris@909 245 :scmid => '12345',
Chris@909 246 :comments => str)
Chris@909 247 assert( c.save )
Chris@909 248 str_utf8 = "Texte encod\xc3\xa9 en ISO-8859-1."
Chris@909 249 str_utf8.force_encoding("UTF-8") if str_utf8.respond_to?(:force_encoding)
Chris@909 250 assert_equal str_utf8, c.comments
Chris@909 251 end
Chris@909 252
Chris@909 253 def test_invalid_utf8_sequences_in_comments_should_be_replaced_latin1
Chris@909 254 proj = Project.find(3)
Chris@909 255 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
Chris@909 256 str1 = "Texte encod\xe9 en ISO-8859-1."
Chris@909 257 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
Chris@909 258 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
Chris@909 259 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
Chris@909 260 r = Repository::Bazaar.create!(
Chris@909 261 :project => proj,
Chris@909 262 :url => '/tmp/test/bazaar',
Chris@909 263 :log_encoding => 'UTF-8' )
Chris@909 264 assert r
Chris@909 265 c = Changeset.new(:repository => r,
Chris@909 266 :committed_on => Time.now,
Chris@909 267 :revision => '123',
Chris@909 268 :scmid => '12345',
Chris@909 269 :comments => str1,
Chris@909 270 :committer => str2)
Chris@909 271 assert( c.save )
Chris@909 272 assert_equal "Texte encod? en ISO-8859-1.", c.comments
Chris@909 273 assert_equal "?a?b?c?d?e test", c.committer
Chris@909 274 end
Chris@909 275
Chris@909 276 def test_invalid_utf8_sequences_in_comments_should_be_replaced_ja_jis
Chris@909 277 proj = Project.find(3)
Chris@909 278 str = "test\xb5\xfetest\xb5\xfe"
Chris@909 279 if str.respond_to?(:force_encoding)
Chris@909 280 str.force_encoding('ASCII-8BIT')
Chris@909 281 end
Chris@909 282 r = Repository::Bazaar.create!(
Chris@909 283 :project => proj,
Chris@909 284 :url => '/tmp/test/bazaar',
Chris@909 285 :log_encoding => 'ISO-2022-JP' )
Chris@909 286 assert r
Chris@909 287 c = Changeset.new(:repository => r,
Chris@909 288 :committed_on => Time.now,
Chris@909 289 :revision => '123',
Chris@909 290 :scmid => '12345',
Chris@909 291 :comments => str)
Chris@909 292 assert( c.save )
Chris@909 293 assert_equal "test??test??", c.comments
Chris@909 294 end
Chris@909 295
Chris@909 296 def test_comments_should_be_converted_all_latin1_to_utf8
Chris@909 297 s1 = "\xC2\x80"
Chris@909 298 s2 = "\xc3\x82\xc2\x80"
Chris@909 299 s4 = s2.dup
Chris@909 300 if s1.respond_to?(:force_encoding)
Chris@909 301 s3 = s1.dup
Chris@909 302 s1.force_encoding('ASCII-8BIT')
Chris@909 303 s2.force_encoding('ASCII-8BIT')
Chris@909 304 s3.force_encoding('ISO-8859-1')
Chris@909 305 s4.force_encoding('UTF-8')
Chris@909 306 assert_equal s3.encode('UTF-8'), s4
Chris@909 307 end
Chris@909 308 proj = Project.find(3)
Chris@909 309 r = Repository::Bazaar.create!(
Chris@909 310 :project => proj,
Chris@909 311 :url => '/tmp/test/bazaar',
Chris@909 312 :log_encoding => 'ISO-8859-1' )
Chris@909 313 assert r
Chris@909 314 c = Changeset.new(:repository => r,
Chris@909 315 :committed_on => Time.now,
Chris@909 316 :revision => '123',
Chris@909 317 :scmid => '12345',
Chris@909 318 :comments => s1)
Chris@909 319 assert( c.save )
Chris@909 320 assert_equal s4, c.comments
Chris@909 321 end
Chris@909 322
Chris@909 323 def test_invalid_utf8_sequences_in_paths_should_be_replaced
Chris@909 324 proj = Project.find(3)
Chris@909 325 str1 = "Texte encod\xe9 en ISO-8859-1"
Chris@909 326 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
Chris@909 327 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
Chris@909 328 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
Chris@909 329 r = Repository::Bazaar.create!(
Chris@909 330 :project => proj,
Chris@909 331 :url => '/tmp/test/bazaar',
Chris@909 332 :log_encoding => 'UTF-8' )
Chris@909 333 assert r
Chris@909 334 cs = Changeset.new(
Chris@909 335 :repository => r,
Chris@909 336 :committed_on => Time.now,
Chris@909 337 :revision => '123',
Chris@909 338 :scmid => '12345',
Chris@909 339 :comments => "test")
Chris@909 340 assert(cs.save)
Chris@909 341 ch = Change.new(
Chris@909 342 :changeset => cs,
Chris@909 343 :action => "A",
Chris@909 344 :path => str1,
Chris@909 345 :from_path => str2,
Chris@909 346 :from_revision => "345")
Chris@909 347 assert(ch.save)
Chris@909 348 assert_equal "Texte encod? en ISO-8859-1", ch.path
Chris@909 349 assert_equal "?a?b?c?d?e test", ch.from_path
Chris@909 350 end
Chris@909 351
Chris@909 352 def test_comments_nil
Chris@909 353 proj = Project.find(3)
Chris@909 354 r = Repository::Bazaar.create!(
Chris@909 355 :project => proj,
Chris@909 356 :url => '/tmp/test/bazaar',
Chris@909 357 :log_encoding => 'ISO-8859-1' )
Chris@909 358 assert r
Chris@909 359 c = Changeset.new(:repository => r,
Chris@909 360 :committed_on => Time.now,
Chris@909 361 :revision => '123',
Chris@909 362 :scmid => '12345',
Chris@909 363 :comments => nil,
Chris@909 364 :committer => nil)
Chris@909 365 assert( c.save )
Chris@909 366 assert_equal "", c.comments
Chris@909 367 assert_equal nil, c.committer
Chris@909 368 if c.comments.respond_to?(:force_encoding)
Chris@909 369 assert_equal "UTF-8", c.comments.encoding.to_s
Chris@909 370 end
Chris@909 371 end
Chris@909 372
Chris@909 373 def test_comments_empty
Chris@909 374 proj = Project.find(3)
Chris@909 375 r = Repository::Bazaar.create!(
Chris@909 376 :project => proj,
Chris@909 377 :url => '/tmp/test/bazaar',
Chris@909 378 :log_encoding => 'ISO-8859-1' )
Chris@909 379 assert r
Chris@909 380 c = Changeset.new(:repository => r,
Chris@909 381 :committed_on => Time.now,
Chris@909 382 :revision => '123',
Chris@909 383 :scmid => '12345',
Chris@909 384 :comments => "",
Chris@909 385 :committer => "")
Chris@909 386 assert( c.save )
Chris@909 387 assert_equal "", c.comments
Chris@909 388 assert_equal "", c.committer
Chris@909 389 if c.comments.respond_to?(:force_encoding)
Chris@909 390 assert_equal "UTF-8", c.comments.encoding.to_s
Chris@909 391 assert_equal "UTF-8", c.committer.encoding.to_s
Chris@909 392 end
Chris@909 393 end
Chris@909 394
Chris@909 395 def test_identifier
Chris@909 396 c = Changeset.find_by_revision('1')
Chris@909 397 assert_equal c.revision, c.identifier
Chris@909 398 end
Chris@909 399 end