annotate test/unit/changeset_test.rb @ 877:e97cef3bd5d0 bug_70

Close obsolete branch bug_70
author Chris Cannam
date Wed, 30 Mar 2011 10:48:32 +0100
parents 513646585e45
children af80e5618e9b
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@0 20 require File.dirname(__FILE__) + '/../test_helper'
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@0 47 def test_ref_keywords_any_line_start
Chris@0 48 Setting.commit_ref_keywords = '*'
Chris@0 49
Chris@0 50 c = Changeset.new(:repository => Project.find(1).repository,
Chris@0 51 :committed_on => Time.now,
Chris@0 52 :comments => '#1 is the reason of this commit')
Chris@0 53 c.scan_comment_for_issue_ids
Chris@0 54
Chris@0 55 assert_equal [1], c.issue_ids.sort
Chris@0 56 end
Chris@0 57
Chris@0 58 def test_ref_keywords_allow_brackets_around_a_issue_number
Chris@0 59 Setting.commit_ref_keywords = '*'
Chris@0 60
Chris@0 61 c = Changeset.new(:repository => Project.find(1).repository,
Chris@0 62 :committed_on => Time.now,
Chris@0 63 :comments => '[#1] Worked on this issue')
Chris@0 64 c.scan_comment_for_issue_ids
Chris@0 65
Chris@0 66 assert_equal [1], c.issue_ids.sort
Chris@0 67 end
Chris@0 68
Chris@0 69 def test_ref_keywords_allow_brackets_around_multiple_issue_numbers
Chris@0 70 Setting.commit_ref_keywords = '*'
Chris@0 71
Chris@0 72 c = Changeset.new(:repository => Project.find(1).repository,
Chris@0 73 :committed_on => Time.now,
Chris@0 74 :comments => '[#1 #2, #3] Worked on these')
Chris@0 75 c.scan_comment_for_issue_ids
Chris@0 76
Chris@0 77 assert_equal [1,2,3], c.issue_ids.sort
Chris@0 78 end
Chris@0 79
Chris@0 80 def test_commit_referencing_a_subproject_issue
Chris@0 81 c = Changeset.new(:repository => Project.find(1).repository,
Chris@0 82 :committed_on => Time.now,
Chris@0 83 :comments => 'refs #5, a subproject issue')
Chris@0 84 c.scan_comment_for_issue_ids
Chris@0 85
Chris@0 86 assert_equal [5], c.issue_ids.sort
Chris@0 87 assert c.issues.first.project != c.project
Chris@0 88 end
Chris@0 89
Chris@0 90 def test_commit_referencing_a_parent_project_issue
Chris@0 91 # repository of child project
Chris@0 92 r = Repository::Subversion.create!(:project => Project.find(3), :url => 'svn://localhost/test')
Chris@0 93
Chris@0 94 c = Changeset.new(:repository => r,
Chris@0 95 :committed_on => Time.now,
Chris@0 96 :comments => 'refs #2, an issue of a parent project')
Chris@0 97 c.scan_comment_for_issue_ids
Chris@0 98
Chris@0 99 assert_equal [2], c.issue_ids.sort
Chris@0 100 assert c.issues.first.project != c.project
Chris@0 101 end
Chris@0 102
Chris@0 103 def test_previous
Chris@0 104 changeset = Changeset.find_by_revision('3')
Chris@0 105 assert_equal Changeset.find_by_revision('2'), changeset.previous
Chris@0 106 end
Chris@0 107
Chris@0 108 def test_previous_nil
Chris@0 109 changeset = Changeset.find_by_revision('1')
Chris@0 110 assert_nil changeset.previous
Chris@0 111 end
Chris@0 112
Chris@0 113 def test_next
Chris@0 114 changeset = Changeset.find_by_revision('2')
Chris@0 115 assert_equal Changeset.find_by_revision('3'), changeset.next
Chris@0 116 end
Chris@0 117
Chris@0 118 def test_next_nil
Chris@0 119 changeset = Changeset.find_by_revision('10')
Chris@0 120 assert_nil changeset.next
Chris@0 121 end
Chris@0 122
Chris@0 123 def test_comments_should_be_converted_to_utf8
Chris@0 124 with_settings :commit_logs_encoding => 'ISO-8859-1' do
Chris@0 125 c = Changeset.new
Chris@0 126 c.comments = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
Chris@0 127 assert_equal "Texte encodé en ISO-8859-1.", c.comments
Chris@0 128 end
Chris@0 129 end
Chris@0 130
Chris@0 131 def test_invalid_utf8_sequences_in_comments_should_be_stripped
Chris@0 132 c = Changeset.new
Chris@0 133 c.comments = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
Chris@0 134 assert_equal "Texte encod en ISO-8859-1.", c.comments
Chris@0 135 end
Chris@0 136 end