1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 require File.dirname(__FILE__) + '/../test_helper'
20 class RepositoryTest < ActiveSupport::TestCase
33 @repository = Project.find(1).repository
37 repository = Repository::Subversion.new(:project => Project.find(3))
38 assert !repository.save
40 repository.url = "svn://localhost"
41 assert repository.save
44 project = Project.find(3)
45 assert_equal repository, project.repository
49 changesets = Changeset.count(:all, :conditions => "repository_id = 10")
50 changes = Change.count(:all, :conditions => "repository_id = 10", :include => :changeset)
51 assert_difference 'Changeset.count', -changesets do
52 assert_difference 'Change.count', -changes do
53 Repository.find(10).destroy
58 def test_should_not_create_with_disabled_scm
60 Setting.enabled_scm = ['Darcs', 'Git']
61 repository = Repository::Subversion.new(:project => Project.find(3), :url => "svn://localhost")
62 assert !repository.save
63 assert_equal I18n.translate('activerecord.errors.messages.invalid'), repository.errors.on(:type)
64 # re-enable Subversion for following tests
68 def test_scan_changesets_for_issue_ids
69 Setting.default_language = 'en'
71 # choosing a status to apply to fix issues
72 Setting.commit_fix_status_id = IssueStatus.find(:first, :conditions => ["is_closed = ?", true]).id
73 Setting.commit_fix_done_ratio = "90"
74 Setting.commit_ref_keywords = 'refs , references, IssueID'
75 Setting.commit_fix_keywords = 'fixes , closes'
76 Setting.default_language = 'en'
77 ActionMailer::Base.deliveries.clear
79 # make sure issue 1 is not already closed
80 fixed_issue = Issue.find(1)
81 assert !fixed_issue.status.is_closed?
82 old_status = fixed_issue.status
84 Repository.scan_changesets_for_issue_ids
85 assert_equal [101, 102], Issue.find(3).changeset_ids
89 assert fixed_issue.status.is_closed?
90 assert_equal 90, fixed_issue.done_ratio
91 assert_equal [101], fixed_issue.changeset_ids
94 journal = fixed_issue.journals.find(:first, :order => 'created_on desc')
95 assert_equal User.find_by_login('dlopper'), journal.user
96 assert_equal 'Applied in changeset r2.', journal.notes
98 # 2 email notifications
99 assert_equal 2, ActionMailer::Base.deliveries.size
100 mail = ActionMailer::Base.deliveries.first
101 assert_kind_of TMail::Mail, mail
102 assert mail.subject.starts_with?("[#{fixed_issue.project.name} - #{fixed_issue.tracker.name} ##{fixed_issue.id}]")
103 assert mail.body.include?("Status changed from #{old_status} to #{fixed_issue.status}")
105 # ignoring commits referencing an issue of another project
106 assert_equal [], Issue.find(4).changesets
109 def test_for_changeset_comments_strip
110 repository = Repository::Mercurial.create( :project => Project.find( 4 ), :url => '/foo/bar/baz' )
112 This is a loooooooooooooooooooooooooooong comment
116 changeset = Changeset.new(
117 :comments => comment, :commit_date => Time.now, :revision => 0, :scmid => 'f39b7922fb3c',
118 :committer => 'foo <foo@example.com>', :committed_on => Time.now, :repository => repository )
119 assert( changeset.save )
120 assert_not_equal( comment, changeset.comments )
121 assert_equal( 'This is a loooooooooooooooooooooooooooong comment', changeset.comments )
124 def test_for_urls_strip
125 repository = Repository::Cvs.create(:project => Project.find(4), :url => ' :pserver:login:password@host:/path/to/the/repository',
127 assert repository.save
129 assert_equal ':pserver:login:password@host:/path/to/the/repository', repository.url
130 assert_equal 'foo', repository.root_url
133 def test_manual_user_mapping
134 assert_no_difference "Changeset.count(:conditions => 'user_id <> 2')" do
135 c = Changeset.create!(:repository => @repository, :committer => 'foo', :committed_on => Time.now, :revision => 100, :comments => 'Committed by foo.')
137 @repository.committer_ids = {'foo' => '2'}
138 assert_equal User.find(2), c.reload.user
139 # committer is now mapped
140 c = Changeset.create!(:repository => @repository, :committer => 'foo', :committed_on => Time.now, :revision => 101, :comments => 'Another commit by foo.')
141 assert_equal User.find(2), c.user
145 def test_auto_user_mapping_by_username
146 c = Changeset.create!(:repository => @repository, :committer => 'jsmith', :committed_on => Time.now, :revision => 100, :comments => 'Committed by john.')
147 assert_equal User.find(2), c.user
150 def test_auto_user_mapping_by_email
151 c = Changeset.create!(:repository => @repository, :committer => 'john <jsmith@somenet.foo>', :committed_on => Time.now, :revision => 100, :comments => 'Committed by john.')
152 assert_equal User.find(2), c.user