annotate test/unit/changeset_test.rb @ 904:0a8317a50fa0 redmine-1.1

Close obsolete branch redmine-1.1
author Chris Cannam
date Fri, 14 Jan 2011 12:53:21 +0000
parents af80e5618e9b
children 051f544170fe
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@117 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@117 47 def test_ref_keywords
Chris@117 48 Setting.commit_ref_keywords = 'refs'
Chris@117 49 Setting.commit_fix_keywords = ''
Chris@117 50
Chris@117 51 c = Changeset.new(:repository => Project.find(1).repository,
Chris@117 52 :committed_on => Time.now,
Chris@117 53 :comments => 'Ignores #2. Refs #1')
Chris@117 54 c.scan_comment_for_issue_ids
Chris@117 55
Chris@117 56 assert_equal [1], c.issue_ids.sort
Chris@117 57 end
Chris@117 58
Chris@117 59 def test_ref_keywords_any_only
Chris@117 60 Setting.commit_ref_keywords = '*'
Chris@117 61 Setting.commit_fix_keywords = ''
Chris@117 62
Chris@117 63 c = Changeset.new(:repository => Project.find(1).repository,
Chris@117 64 :committed_on => Time.now,
Chris@117 65 :comments => 'Ignores #2. Refs #1')
Chris@117 66 c.scan_comment_for_issue_ids
Chris@117 67
Chris@117 68 assert_equal [1, 2], c.issue_ids.sort
Chris@117 69 end
Chris@117 70
Chris@117 71 def test_ref_keywords_any_with_timelog
Chris@117 72 Setting.commit_ref_keywords = '*'
Chris@117 73 Setting.commit_logtime_enabled = '1'
Chris@117 74
Chris@117 75 c = Changeset.new(:repository => Project.find(1).repository,
Chris@117 76 :committed_on => 24.hours.ago,
Chris@117 77 :comments => 'Worked on this issue #1 @2h',
Chris@117 78 :revision => '520',
Chris@117 79 :user => User.find(2))
Chris@117 80 assert_difference 'TimeEntry.count' do
Chris@117 81 c.scan_comment_for_issue_ids
Chris@117 82 end
Chris@117 83 assert_equal [1], c.issue_ids.sort
Chris@117 84
Chris@117 85 time = TimeEntry.first(:order => 'id desc')
Chris@117 86 assert_equal 1, time.issue_id
Chris@117 87 assert_equal 1, time.project_id
Chris@117 88 assert_equal 2, time.user_id
Chris@117 89 assert_equal 2.0, time.hours
Chris@117 90 assert_equal Date.yesterday, time.spent_on
Chris@117 91 assert time.activity.is_default?
Chris@117 92 assert time.comments.include?('r520'), "r520 was expected in time_entry comments: #{time.comments}"
Chris@117 93 end
Chris@117 94
Chris@117 95 def test_ref_keywords_closing_with_timelog
Chris@117 96 Setting.commit_fix_status_id = IssueStatus.find(:first, :conditions => ["is_closed = ?", true]).id
Chris@117 97 Setting.commit_ref_keywords = '*'
Chris@117 98 Setting.commit_fix_keywords = 'fixes , closes'
Chris@117 99 Setting.commit_logtime_enabled = '1'
Chris@117 100
Chris@117 101 c = Changeset.new(:repository => Project.find(1).repository,
Chris@117 102 :committed_on => Time.now,
Chris@117 103 :comments => 'This is a comment. Fixes #1 @2.5, #2 @1',
Chris@117 104 :user => User.find(2))
Chris@117 105 assert_difference 'TimeEntry.count', 2 do
Chris@117 106 c.scan_comment_for_issue_ids
Chris@117 107 end
Chris@117 108
Chris@117 109 assert_equal [1, 2], c.issue_ids.sort
Chris@117 110 assert Issue.find(1).closed?
Chris@117 111 assert Issue.find(2).closed?
Chris@117 112
Chris@117 113 times = TimeEntry.all(:order => 'id desc', :limit => 2)
Chris@117 114 assert_equal [1, 2], times.collect(&:issue_id).sort
Chris@117 115 end
Chris@117 116
Chris@0 117 def test_ref_keywords_any_line_start
Chris@0 118 Setting.commit_ref_keywords = '*'
Chris@0 119
Chris@0 120 c = Changeset.new(:repository => Project.find(1).repository,
Chris@0 121 :committed_on => Time.now,
Chris@0 122 :comments => '#1 is the reason of this commit')
Chris@0 123 c.scan_comment_for_issue_ids
Chris@0 124
Chris@0 125 assert_equal [1], c.issue_ids.sort
Chris@0 126 end
Chris@0 127
Chris@0 128 def test_ref_keywords_allow_brackets_around_a_issue_number
Chris@0 129 Setting.commit_ref_keywords = '*'
Chris@0 130
Chris@0 131 c = Changeset.new(:repository => Project.find(1).repository,
Chris@0 132 :committed_on => Time.now,
Chris@0 133 :comments => '[#1] Worked on this issue')
Chris@0 134 c.scan_comment_for_issue_ids
Chris@0 135
Chris@0 136 assert_equal [1], c.issue_ids.sort
Chris@0 137 end
Chris@0 138
Chris@0 139 def test_ref_keywords_allow_brackets_around_multiple_issue_numbers
Chris@0 140 Setting.commit_ref_keywords = '*'
Chris@0 141
Chris@0 142 c = Changeset.new(:repository => Project.find(1).repository,
Chris@0 143 :committed_on => Time.now,
Chris@0 144 :comments => '[#1 #2, #3] Worked on these')
Chris@0 145 c.scan_comment_for_issue_ids
Chris@0 146
Chris@0 147 assert_equal [1,2,3], c.issue_ids.sort
Chris@0 148 end
Chris@0 149
Chris@0 150 def test_commit_referencing_a_subproject_issue
Chris@0 151 c = Changeset.new(:repository => Project.find(1).repository,
Chris@0 152 :committed_on => Time.now,
Chris@0 153 :comments => 'refs #5, a subproject issue')
Chris@0 154 c.scan_comment_for_issue_ids
Chris@0 155
Chris@0 156 assert_equal [5], c.issue_ids.sort
Chris@0 157 assert c.issues.first.project != c.project
Chris@0 158 end
Chris@0 159
Chris@0 160 def test_commit_referencing_a_parent_project_issue
Chris@0 161 # repository of child project
Chris@0 162 r = Repository::Subversion.create!(:project => Project.find(3), :url => 'svn://localhost/test')
Chris@0 163
Chris@0 164 c = Changeset.new(:repository => r,
Chris@0 165 :committed_on => Time.now,
Chris@0 166 :comments => 'refs #2, an issue of a parent project')
Chris@0 167 c.scan_comment_for_issue_ids
Chris@0 168
Chris@0 169 assert_equal [2], c.issue_ids.sort
Chris@0 170 assert c.issues.first.project != c.project
Chris@0 171 end
Chris@117 172
Chris@117 173 def test_text_tag_revision
Chris@117 174 c = Changeset.new(:revision => '520')
Chris@117 175 assert_equal 'r520', c.text_tag
Chris@117 176 end
Chris@117 177
Chris@117 178 def test_text_tag_hash
Chris@117 179 c = Changeset.new(:scmid => '7234cb2750b63f47bff735edc50a1c0a433c2518', :revision => '7234cb2750b63f47bff735edc50a1c0a433c2518')
Chris@117 180 assert_equal 'commit:7234cb2750b63f47bff735edc50a1c0a433c2518', c.text_tag
Chris@117 181 end
Chris@117 182
Chris@117 183 def test_text_tag_hash_all_number
Chris@117 184 c = Changeset.new(:scmid => '0123456789', :revision => '0123456789')
Chris@117 185 assert_equal 'commit:0123456789', c.text_tag
Chris@117 186 end
Chris@0 187
Chris@0 188 def test_previous
Chris@0 189 changeset = Changeset.find_by_revision('3')
Chris@0 190 assert_equal Changeset.find_by_revision('2'), changeset.previous
Chris@0 191 end
Chris@0 192
Chris@0 193 def test_previous_nil
Chris@0 194 changeset = Changeset.find_by_revision('1')
Chris@0 195 assert_nil changeset.previous
Chris@0 196 end
Chris@0 197
Chris@0 198 def test_next
Chris@0 199 changeset = Changeset.find_by_revision('2')
Chris@0 200 assert_equal Changeset.find_by_revision('3'), changeset.next
Chris@0 201 end
Chris@0 202
Chris@0 203 def test_next_nil
Chris@0 204 changeset = Changeset.find_by_revision('10')
Chris@0 205 assert_nil changeset.next
Chris@0 206 end
Chris@0 207
Chris@0 208 def test_comments_should_be_converted_to_utf8
Chris@0 209 with_settings :commit_logs_encoding => 'ISO-8859-1' do
Chris@0 210 c = Changeset.new
Chris@0 211 c.comments = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
Chris@0 212 assert_equal "Texte encodé en ISO-8859-1.", c.comments
Chris@0 213 end
Chris@0 214 end
Chris@0 215
Chris@0 216 def test_invalid_utf8_sequences_in_comments_should_be_stripped
Chris@0 217 c = Changeset.new
Chris@0 218 c.comments = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
Chris@0 219 assert_equal "Texte encod en ISO-8859-1.", c.comments
Chris@0 220 end
Chris@117 221
Chris@117 222 def test_identifier
Chris@117 223 c = Changeset.find_by_revision('1')
Chris@117 224 assert_equal c.revision, c.identifier
Chris@117 225 end
Chris@0 226 end