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