annotate test/unit/changeset_test.rb @ 245:051f544170fe

* Update to SVN trunk revision 4993
author Chris Cannam
date Thu, 03 Mar 2011 11:42:28 +0000
parents 8661b858af72
children cbce1fd3b1b7
rev   line source
Chris@0 1 # encoding: utf-8
Chris@0 2 #
Chris@0 3 # Redmine - project management software
Chris@0 4 # Copyright (C) 2006-2010 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@0 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@0 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@0 23 fixtures :projects, :repositories, :issues, :issue_statuses, :changesets, :changes, :issue_categories, :enumerations, :custom_fields, :custom_values, :users, :members, :member_roles, :trackers
Chris@0 24
Chris@0 25 def setup
Chris@0 26 end
Chris@0 27
Chris@0 28 def test_ref_keywords_any
Chris@0 29 ActionMailer::Base.deliveries.clear
Chris@0 30 Setting.commit_fix_status_id = IssueStatus.find(:first, :conditions => ["is_closed = ?", true]).id
Chris@0 31 Setting.commit_fix_done_ratio = '90'
Chris@0 32 Setting.commit_ref_keywords = '*'
Chris@0 33 Setting.commit_fix_keywords = 'fixes , closes'
Chris@0 34
Chris@0 35 c = Changeset.new(:repository => Project.find(1).repository,
Chris@0 36 :committed_on => Time.now,
Chris@0 37 :comments => 'New commit (#2). Fixes #1')
Chris@0 38 c.scan_comment_for_issue_ids
Chris@0 39
Chris@0 40 assert_equal [1, 2], c.issue_ids.sort
Chris@0 41 fixed = Issue.find(1)
Chris@0 42 assert fixed.closed?
Chris@0 43 assert_equal 90, fixed.done_ratio
Chris@0 44 assert_equal 1, ActionMailer::Base.deliveries.size
Chris@0 45 end
Chris@0 46
Chris@119 47 def test_ref_keywords
Chris@119 48 Setting.commit_ref_keywords = 'refs'
Chris@119 49 Setting.commit_fix_keywords = ''
Chris@119 50
Chris@119 51 c = Changeset.new(:repository => Project.find(1).repository,
Chris@119 52 :committed_on => Time.now,
Chris@119 53 :comments => 'Ignores #2. Refs #1')
Chris@119 54 c.scan_comment_for_issue_ids
Chris@119 55
Chris@119 56 assert_equal [1], c.issue_ids.sort
Chris@119 57 end
Chris@119 58
Chris@119 59 def test_ref_keywords_any_only
Chris@119 60 Setting.commit_ref_keywords = '*'
Chris@119 61 Setting.commit_fix_keywords = ''
Chris@119 62
Chris@119 63 c = Changeset.new(:repository => Project.find(1).repository,
Chris@119 64 :committed_on => Time.now,
Chris@119 65 :comments => 'Ignores #2. Refs #1')
Chris@119 66 c.scan_comment_for_issue_ids
Chris@119 67
Chris@119 68 assert_equal [1, 2], c.issue_ids.sort
Chris@119 69 end
Chris@119 70
Chris@119 71 def test_ref_keywords_any_with_timelog
Chris@119 72 Setting.commit_ref_keywords = '*'
Chris@119 73 Setting.commit_logtime_enabled = '1'
Chris@119 74
Chris@245 75 {
Chris@245 76 '2' => 2.0,
Chris@245 77 '2h' => 2.0,
Chris@245 78 '2hours' => 2.0,
Chris@245 79 '15m' => 0.25,
Chris@245 80 '15min' => 0.25,
Chris@245 81 '3h15' => 3.25,
Chris@245 82 '3h15m' => 3.25,
Chris@245 83 '3h15min' => 3.25,
Chris@245 84 '3:15' => 3.25,
Chris@245 85 '3.25' => 3.25,
Chris@245 86 '3.25h' => 3.25,
Chris@245 87 '3,25' => 3.25,
Chris@245 88 '3,25h' => 3.25,
Chris@245 89 }.each do |syntax, expected_hours|
Chris@245 90 c = Changeset.new(:repository => Project.find(1).repository,
Chris@245 91 :committed_on => 24.hours.ago,
Chris@245 92 :comments => "Worked on this issue #1 @#{syntax}",
Chris@245 93 :revision => '520',
Chris@245 94 :user => User.find(2))
Chris@245 95 assert_difference 'TimeEntry.count' do
Chris@245 96 c.scan_comment_for_issue_ids
Chris@245 97 end
Chris@245 98 assert_equal [1], c.issue_ids.sort
Chris@245 99
Chris@245 100 time = TimeEntry.first(:order => 'id desc')
Chris@245 101 assert_equal 1, time.issue_id
Chris@245 102 assert_equal 1, time.project_id
Chris@245 103 assert_equal 2, time.user_id
Chris@245 104 assert_equal expected_hours, time.hours, "@#{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@245 107 assert time.comments.include?('r520'), "r520 was expected in time_entry comments: #{time.comments}"
Chris@119 108 end
Chris@119 109 end
Chris@119 110
Chris@119 111 def test_ref_keywords_closing_with_timelog
Chris@119 112 Setting.commit_fix_status_id = IssueStatus.find(:first, :conditions => ["is_closed = ?", true]).id
Chris@119 113 Setting.commit_ref_keywords = '*'
Chris@119 114 Setting.commit_fix_keywords = 'fixes , closes'
Chris@119 115 Setting.commit_logtime_enabled = '1'
Chris@119 116
Chris@119 117 c = Changeset.new(:repository => Project.find(1).repository,
Chris@119 118 :committed_on => Time.now,
Chris@245 119 :comments => 'This is a comment. Fixes #1 @4.5, #2 @1',
Chris@119 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@119 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@119 132
Chris@0 133 def test_ref_keywords_any_line_start
Chris@0 134 Setting.commit_ref_keywords = '*'
Chris@0 135
Chris@0 136 c = Changeset.new(:repository => Project.find(1).repository,
Chris@0 137 :committed_on => Time.now,
Chris@0 138 :comments => '#1 is the reason of this commit')
Chris@0 139 c.scan_comment_for_issue_ids
Chris@0 140
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@0 146
Chris@0 147 c = Changeset.new(:repository => Project.find(1).repository,
Chris@0 148 :committed_on => Time.now,
Chris@0 149 :comments => '[#1] Worked on this issue')
Chris@0 150 c.scan_comment_for_issue_ids
Chris@0 151
Chris@0 152 assert_equal [1], c.issue_ids.sort
Chris@0 153 end
Chris@0 154
Chris@0 155 def test_ref_keywords_allow_brackets_around_multiple_issue_numbers
Chris@0 156 Setting.commit_ref_keywords = '*'
Chris@0 157
Chris@0 158 c = Changeset.new(:repository => Project.find(1).repository,
Chris@0 159 :committed_on => Time.now,
Chris@0 160 :comments => '[#1 #2, #3] Worked on these')
Chris@0 161 c.scan_comment_for_issue_ids
Chris@0 162
Chris@0 163 assert_equal [1,2,3], c.issue_ids.sort
Chris@0 164 end
Chris@0 165
Chris@0 166 def test_commit_referencing_a_subproject_issue
Chris@0 167 c = Changeset.new(:repository => Project.find(1).repository,
Chris@0 168 :committed_on => Time.now,
Chris@0 169 :comments => 'refs #5, a subproject issue')
Chris@0 170 c.scan_comment_for_issue_ids
Chris@0 171
Chris@0 172 assert_equal [5], c.issue_ids.sort
Chris@0 173 assert c.issues.first.project != c.project
Chris@0 174 end
Chris@0 175
Chris@0 176 def test_commit_referencing_a_parent_project_issue
Chris@0 177 # repository of child project
Chris@0 178 r = Repository::Subversion.create!(:project => Project.find(3), :url => 'svn://localhost/test')
Chris@0 179
Chris@0 180 c = Changeset.new(:repository => r,
Chris@0 181 :committed_on => Time.now,
Chris@0 182 :comments => 'refs #2, an issue of a parent project')
Chris@0 183 c.scan_comment_for_issue_ids
Chris@0 184
Chris@0 185 assert_equal [2], c.issue_ids.sort
Chris@0 186 assert c.issues.first.project != c.project
Chris@0 187 end
Chris@245 188
Chris@119 189 def test_text_tag_revision
Chris@119 190 c = Changeset.new(:revision => '520')
Chris@119 191 assert_equal 'r520', c.text_tag
Chris@119 192 end
Chris@245 193
Chris@119 194 def test_text_tag_hash
Chris@119 195 c = Changeset.new(:scmid => '7234cb2750b63f47bff735edc50a1c0a433c2518', :revision => '7234cb2750b63f47bff735edc50a1c0a433c2518')
Chris@119 196 assert_equal 'commit:7234cb2750b63f47bff735edc50a1c0a433c2518', c.text_tag
Chris@119 197 end
Chris@119 198
Chris@119 199 def test_text_tag_hash_all_number
Chris@119 200 c = Changeset.new(:scmid => '0123456789', :revision => '0123456789')
Chris@119 201 assert_equal 'commit:0123456789', c.text_tag
Chris@119 202 end
Chris@0 203
Chris@0 204 def test_previous
Chris@0 205 changeset = Changeset.find_by_revision('3')
Chris@0 206 assert_equal Changeset.find_by_revision('2'), changeset.previous
Chris@0 207 end
Chris@0 208
Chris@0 209 def test_previous_nil
Chris@0 210 changeset = Changeset.find_by_revision('1')
Chris@0 211 assert_nil changeset.previous
Chris@0 212 end
Chris@0 213
Chris@0 214 def test_next
Chris@0 215 changeset = Changeset.find_by_revision('2')
Chris@0 216 assert_equal Changeset.find_by_revision('3'), changeset.next
Chris@0 217 end
Chris@0 218
Chris@0 219 def test_next_nil
Chris@0 220 changeset = Changeset.find_by_revision('10')
Chris@0 221 assert_nil changeset.next
Chris@0 222 end
Chris@245 223
Chris@0 224 def test_comments_should_be_converted_to_utf8
Chris@245 225 proj = Project.find(3)
Chris@245 226 str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
Chris@245 227 r = Repository::Bazaar.create!(
Chris@245 228 :project => proj, :url => '/tmp/test/bazaar',
Chris@245 229 :log_encoding => 'ISO-8859-1' )
Chris@245 230 assert r
Chris@245 231 c = Changeset.new(:repository => r,
Chris@245 232 :committed_on => Time.now,
Chris@245 233 :revision => '123',
Chris@245 234 :scmid => '12345',
Chris@245 235 :comments => str)
Chris@245 236 assert( c.save )
Chris@0 237 assert_equal "Texte encodé en ISO-8859-1.", c.comments
Chris@0 238 end
Chris@245 239
Chris@0 240 def test_invalid_utf8_sequences_in_comments_should_be_stripped
Chris@245 241 proj = Project.find(3)
Chris@245 242 str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
Chris@245 243 r = Repository::Bazaar.create!(
Chris@245 244 :project => proj, :url => '/tmp/test/bazaar',
Chris@245 245 :log_encoding => 'UTF-8' )
Chris@245 246 assert r
Chris@245 247 c = Changeset.new(:repository => r,
Chris@245 248 :committed_on => Time.now,
Chris@245 249 :revision => '123',
Chris@245 250 :scmid => '12345',
Chris@245 251 :comments => str)
Chris@245 252 assert( c.save )
Chris@245 253 if str.respond_to?(:force_encoding)
Chris@245 254 assert_equal "Texte encod? en ISO-8859-1.", c.comments
Chris@245 255 else
Chris@245 256 assert_equal "Texte encod en ISO-8859-1.", c.comments
Chris@245 257 end
Chris@245 258 end
Chris@245 259
Chris@245 260 def test_comments_should_be_converted_all_latin1_to_utf8
Chris@245 261 s1 = "\xC2\x80"
Chris@245 262 s2 = "\xc3\x82\xc2\x80"
Chris@245 263 if s1.respond_to?(:force_encoding)
Chris@245 264 s3 = s1
Chris@245 265 s4 = s2
Chris@245 266 s1.force_encoding('ASCII-8BIT')
Chris@245 267 s2.force_encoding('ASCII-8BIT')
Chris@245 268 s3.force_encoding('ISO-8859-1')
Chris@245 269 s4.force_encoding('UTF-8')
Chris@245 270 assert_equal s3.encode('UTF-8'), s4
Chris@245 271 end
Chris@245 272 proj = Project.find(3)
Chris@245 273 r = Repository::Bazaar.create!(
Chris@245 274 :project => proj, :url => '/tmp/test/bazaar',
Chris@245 275 :log_encoding => 'ISO-8859-1' )
Chris@245 276 assert r
Chris@245 277 c = Changeset.new(:repository => r,
Chris@245 278 :committed_on => Time.now,
Chris@245 279 :revision => '123',
Chris@245 280 :scmid => '12345',
Chris@245 281 :comments => s1)
Chris@245 282 assert( c.save )
Chris@245 283 assert_equal s2, c.comments
Chris@0 284 end
Chris@119 285
Chris@119 286 def test_identifier
Chris@119 287 c = Changeset.find_by_revision('1')
Chris@119 288 assert_equal c.revision, c.identifier
Chris@119 289 end
Chris@0 290 end