Chris@441
|
1 # Redmine - project management software
|
Chris@441
|
2 # Copyright (C) 2006-2011 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@441
|
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@441
|
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@119
|
18 require File.expand_path('../../test_helper', __FILE__)
|
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@119
|
24 :enabled_modules,
|
Chris@0
|
25 :repositories,
|
Chris@0
|
26 :issues,
|
Chris@0
|
27 :issue_statuses,
|
Chris@119
|
28 :issue_categories,
|
Chris@0
|
29 :changesets,
|
Chris@0
|
30 :changes,
|
Chris@0
|
31 :users,
|
Chris@119
|
32 :members,
|
Chris@119
|
33 :member_roles,
|
Chris@119
|
34 :roles,
|
Chris@0
|
35 :enumerations
|
Chris@441
|
36
|
Chris@0
|
37 def setup
|
Chris@0
|
38 @repository = Project.find(1).repository
|
Chris@0
|
39 end
|
Chris@441
|
40
|
Chris@0
|
41 def test_create
|
Chris@0
|
42 repository = Repository::Subversion.new(:project => Project.find(3))
|
Chris@0
|
43 assert !repository.save
|
Chris@441
|
44
|
Chris@0
|
45 repository.url = "svn://localhost"
|
Chris@0
|
46 assert repository.save
|
Chris@0
|
47 repository.reload
|
Chris@441
|
48
|
Chris@0
|
49 project = Project.find(3)
|
Chris@0
|
50 assert_equal repository, project.repository
|
Chris@0
|
51 end
|
Chris@441
|
52
|
Chris@0
|
53 def test_destroy
|
Chris@0
|
54 changesets = Changeset.count(:all, :conditions => "repository_id = 10")
|
Chris@441
|
55 changes = Change.count(:all, :conditions => "repository_id = 10",
|
Chris@441
|
56 :include => :changeset)
|
Chris@0
|
57 assert_difference 'Changeset.count', -changesets do
|
Chris@0
|
58 assert_difference 'Change.count', -changes do
|
Chris@0
|
59 Repository.find(10).destroy
|
Chris@0
|
60 end
|
Chris@0
|
61 end
|
Chris@0
|
62 end
|
Chris@441
|
63
|
Chris@0
|
64 def test_should_not_create_with_disabled_scm
|
Chris@0
|
65 # disable Subversion
|
Chris@128
|
66 with_settings :enabled_scm => ['Darcs', 'Git'] do
|
Chris@441
|
67 repository = Repository::Subversion.new(
|
Chris@441
|
68 :project => Project.find(3), :url => "svn://localhost")
|
Chris@128
|
69 assert !repository.save
|
Chris@441
|
70 assert_equal I18n.translate('activerecord.errors.messages.invalid'),
|
Chris@441
|
71 repository.errors.on(:type)
|
Chris@128
|
72 end
|
Chris@0
|
73 end
|
Chris@441
|
74
|
Chris@0
|
75 def test_scan_changesets_for_issue_ids
|
Chris@0
|
76 Setting.default_language = 'en'
|
chris@37
|
77 Setting.notified_events = ['issue_added','issue_updated']
|
Chris@441
|
78
|
Chris@0
|
79 # choosing a status to apply to fix issues
|
Chris@441
|
80 Setting.commit_fix_status_id = IssueStatus.find(
|
Chris@441
|
81 :first,
|
Chris@441
|
82 :conditions => ["is_closed = ?", true]).id
|
Chris@0
|
83 Setting.commit_fix_done_ratio = "90"
|
Chris@0
|
84 Setting.commit_ref_keywords = 'refs , references, IssueID'
|
Chris@0
|
85 Setting.commit_fix_keywords = 'fixes , closes'
|
Chris@0
|
86 Setting.default_language = 'en'
|
Chris@0
|
87 ActionMailer::Base.deliveries.clear
|
Chris@441
|
88
|
Chris@0
|
89 # make sure issue 1 is not already closed
|
Chris@0
|
90 fixed_issue = Issue.find(1)
|
Chris@0
|
91 assert !fixed_issue.status.is_closed?
|
Chris@0
|
92 old_status = fixed_issue.status
|
Chris@441
|
93
|
Chris@0
|
94 Repository.scan_changesets_for_issue_ids
|
Chris@0
|
95 assert_equal [101, 102], Issue.find(3).changeset_ids
|
Chris@441
|
96
|
Chris@0
|
97 # fixed issues
|
Chris@0
|
98 fixed_issue.reload
|
Chris@0
|
99 assert fixed_issue.status.is_closed?
|
Chris@0
|
100 assert_equal 90, fixed_issue.done_ratio
|
Chris@0
|
101 assert_equal [101], fixed_issue.changeset_ids
|
Chris@441
|
102
|
Chris@0
|
103 # issue change
|
Chris@0
|
104 journal = fixed_issue.journals.find(:first, :order => 'created_on desc')
|
Chris@0
|
105 assert_equal User.find_by_login('dlopper'), journal.user
|
Chris@0
|
106 assert_equal 'Applied in changeset r2.', journal.notes
|
Chris@441
|
107
|
Chris@0
|
108 # 2 email notifications
|
Chris@0
|
109 assert_equal 2, ActionMailer::Base.deliveries.size
|
Chris@0
|
110 mail = ActionMailer::Base.deliveries.first
|
Chris@0
|
111 assert_kind_of TMail::Mail, mail
|
Chris@441
|
112 assert mail.subject.starts_with?(
|
Chris@441
|
113 "[#{fixed_issue.project.name} - #{fixed_issue.tracker.name} ##{fixed_issue.id}]")
|
Chris@441
|
114 assert mail.body.include?(
|
Chris@441
|
115 "Status changed from #{old_status} to #{fixed_issue.status}")
|
Chris@441
|
116
|
Chris@0
|
117 # ignoring commits referencing an issue of another project
|
Chris@0
|
118 assert_equal [], Issue.find(4).changesets
|
Chris@0
|
119 end
|
Chris@441
|
120
|
Chris@0
|
121 def test_for_changeset_comments_strip
|
Chris@441
|
122 repository = Repository::Mercurial.create(
|
Chris@441
|
123 :project => Project.find( 4 ),
|
Chris@441
|
124 :url => '/foo/bar/baz' )
|
Chris@0
|
125 comment = <<-COMMENT
|
Chris@0
|
126 This is a loooooooooooooooooooooooooooong comment
|
Chris@0
|
127
|
Chris@0
|
128
|
Chris@0
|
129 COMMENT
|
Chris@0
|
130 changeset = Changeset.new(
|
Chris@441
|
131 :comments => comment, :commit_date => Time.now,
|
Chris@441
|
132 :revision => 0, :scmid => 'f39b7922fb3c',
|
Chris@441
|
133 :committer => 'foo <foo@example.com>',
|
Chris@441
|
134 :committed_on => Time.now, :repository => repository )
|
Chris@0
|
135 assert( changeset.save )
|
Chris@0
|
136 assert_not_equal( comment, changeset.comments )
|
Chris@441
|
137 assert_equal( 'This is a loooooooooooooooooooooooooooong comment',
|
Chris@441
|
138 changeset.comments )
|
Chris@0
|
139 end
|
Chris@245
|
140
|
Chris@0
|
141 def test_for_urls_strip
|
Chris@245
|
142 repository = Repository::Cvs.create(
|
Chris@245
|
143 :project => Project.find(4),
|
Chris@245
|
144 :url => ' :pserver:login:password@host:/path/to/the/repository',
|
Chris@245
|
145 :root_url => 'foo ',
|
Chris@245
|
146 :log_encoding => 'UTF-8')
|
Chris@0
|
147 assert repository.save
|
Chris@0
|
148 repository.reload
|
Chris@441
|
149 assert_equal ':pserver:login:password@host:/path/to/the/repository',
|
Chris@441
|
150 repository.url
|
Chris@0
|
151 assert_equal 'foo', repository.root_url
|
Chris@0
|
152 end
|
Chris@245
|
153
|
Chris@0
|
154 def test_manual_user_mapping
|
Chris@0
|
155 assert_no_difference "Changeset.count(:conditions => 'user_id <> 2')" do
|
Chris@441
|
156 c = Changeset.create!(
|
Chris@441
|
157 :repository => @repository,
|
Chris@441
|
158 :committer => 'foo',
|
Chris@441
|
159 :committed_on => Time.now,
|
Chris@441
|
160 :revision => 100,
|
Chris@441
|
161 :comments => 'Committed by foo.'
|
Chris@441
|
162 )
|
Chris@0
|
163 assert_nil c.user
|
Chris@0
|
164 @repository.committer_ids = {'foo' => '2'}
|
Chris@0
|
165 assert_equal User.find(2), c.reload.user
|
Chris@0
|
166 # committer is now mapped
|
Chris@441
|
167 c = Changeset.create!(
|
Chris@441
|
168 :repository => @repository,
|
Chris@441
|
169 :committer => 'foo',
|
Chris@441
|
170 :committed_on => Time.now,
|
Chris@441
|
171 :revision => 101,
|
Chris@441
|
172 :comments => 'Another commit by foo.'
|
Chris@441
|
173 )
|
Chris@0
|
174 assert_equal User.find(2), c.user
|
Chris@0
|
175 end
|
Chris@0
|
176 end
|
Chris@441
|
177
|
Chris@0
|
178 def test_auto_user_mapping_by_username
|
Chris@441
|
179 c = Changeset.create!(
|
Chris@441
|
180 :repository => @repository,
|
Chris@441
|
181 :committer => 'jsmith',
|
Chris@441
|
182 :committed_on => Time.now,
|
Chris@441
|
183 :revision => 100,
|
Chris@441
|
184 :comments => 'Committed by john.'
|
Chris@441
|
185 )
|
Chris@0
|
186 assert_equal User.find(2), c.user
|
Chris@0
|
187 end
|
Chris@441
|
188
|
Chris@0
|
189 def test_auto_user_mapping_by_email
|
Chris@441
|
190 c = Changeset.create!(
|
Chris@441
|
191 :repository => @repository,
|
Chris@441
|
192 :committer => 'john <jsmith@somenet.foo>',
|
Chris@441
|
193 :committed_on => Time.now,
|
Chris@441
|
194 :revision => 100,
|
Chris@441
|
195 :comments => 'Committed by john.'
|
Chris@441
|
196 )
|
Chris@0
|
197 assert_equal User.find(2), c.user
|
Chris@0
|
198 end
|
Chris@441
|
199
|
Chris@441
|
200 def test_filesystem_avaialbe
|
Chris@441
|
201 klass = Repository::Filesystem
|
Chris@441
|
202 assert klass.scm_adapter_class
|
Chris@441
|
203 assert_equal true, klass.scm_available
|
Chris@441
|
204 end
|
Chris@441
|
205
|
Chris@441
|
206 def test_merge_extra_info
|
Chris@441
|
207 repo = Repository::Subversion.new(:project => Project.find(3))
|
Chris@441
|
208 assert !repo.save
|
Chris@441
|
209 repo.url = "svn://localhost"
|
Chris@441
|
210 assert repo.save
|
Chris@441
|
211 repo.reload
|
Chris@441
|
212 project = Project.find(3)
|
Chris@441
|
213 assert_equal repo, project.repository
|
Chris@441
|
214 assert_nil repo.extra_info
|
Chris@441
|
215 h1 = {"test_1" => {"test_11" => "test_value_11"}}
|
Chris@441
|
216 repo.merge_extra_info(h1)
|
Chris@441
|
217 assert_equal h1, repo.extra_info
|
Chris@441
|
218 h2 = {"test_2" => {
|
Chris@441
|
219 "test_21" => "test_value_21",
|
Chris@441
|
220 "test_22" => "test_value_22",
|
Chris@441
|
221 }}
|
Chris@441
|
222 repo.merge_extra_info(h2)
|
Chris@441
|
223 assert_equal (h = {"test_11" => "test_value_11"}),
|
Chris@441
|
224 repo.extra_info["test_1"]
|
Chris@441
|
225 assert_equal "test_value_21",
|
Chris@441
|
226 repo.extra_info["test_2"]["test_21"]
|
Chris@441
|
227 h3 = {"test_2" => {
|
Chris@441
|
228 "test_23" => "test_value_23",
|
Chris@441
|
229 "test_24" => "test_value_24",
|
Chris@441
|
230 }}
|
Chris@441
|
231 repo.merge_extra_info(h3)
|
Chris@441
|
232 assert_equal (h = {"test_11" => "test_value_11"}),
|
Chris@441
|
233 repo.extra_info["test_1"]
|
Chris@441
|
234 assert_nil repo.extra_info["test_2"]["test_21"]
|
Chris@441
|
235 assert_equal "test_value_23",
|
Chris@441
|
236 repo.extra_info["test_2"]["test_23"]
|
Chris@441
|
237 end
|
Chris@0
|
238 end
|