##// END OF EJS Templates
code layout cleanup test/unit/repository_test.rb...
Toshi MARUYAMA -
r8838:873e57dc8661
parent child
Show More
@@ -1,313 +1,321
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19
20 20 class RepositoryTest < ActiveSupport::TestCase
21 21 fixtures :projects,
22 22 :trackers,
23 23 :projects_trackers,
24 24 :enabled_modules,
25 25 :repositories,
26 26 :issues,
27 27 :issue_statuses,
28 28 :issue_categories,
29 29 :changesets,
30 30 :changes,
31 31 :users,
32 32 :members,
33 33 :member_roles,
34 34 :roles,
35 35 :enumerations
36 36
37 37 include Redmine::I18n
38 38
39 39 def setup
40 40 @repository = Project.find(1).repository
41 41 end
42 42
43 43 def test_blank_log_encoding_error_message
44 44 set_language_if_valid 'en'
45 45 repo = Repository::Bazaar.new(
46 46 :project => Project.find(3),
47 47 :url => "/test",
48 48 :log_encoding => ''
49 49 )
50 50 assert !repo.save
51 51 assert_include "Commit messages encoding can't be blank",
52 52 repo.errors.full_messages
53 53 end
54 54
55 55 def test_blank_log_encoding_error_message_fr
56 56 set_language_if_valid 'fr'
57 57 str = "Encodage des messages de commit doit \xc3\xaatre renseign\xc3\xa9(e)"
58 58 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
59 59 repo = Repository::Bazaar.new(
60 60 :project => Project.find(3),
61 61 :url => "/test"
62 62 )
63 63 assert !repo.save
64 64 assert_include str, repo.errors.full_messages
65 65 end
66 66
67 67 def test_create
68 68 repository = Repository::Subversion.new(:project => Project.find(3))
69 69 assert !repository.save
70 70
71 71 repository.url = "svn://localhost"
72 72 assert repository.save
73 73 repository.reload
74 74
75 75 project = Project.find(3)
76 76 assert_equal repository, project.repository
77 77 end
78 78
79 79 def test_first_repository_should_be_set_as_default
80 repository1 = Repository::Subversion.new(:project => Project.find(3), :identifier => 'svn1', :url => 'file:///svn1')
80 repository1 = Repository::Subversion.new(
81 :project => Project.find(3),
82 :identifier => 'svn1',
83 :url => 'file:///svn1'
84 )
81 85 assert repository1.save
82 86 assert repository1.is_default?
83 87
84 repository2 = Repository::Subversion.new(:project => Project.find(3), :identifier => 'svn2', :url => 'file:///svn2')
88 repository2 = Repository::Subversion.new(
89 :project => Project.find(3),
90 :identifier => 'svn2',
91 :url => 'file:///svn2'
92 )
85 93 assert repository2.save
86 94 assert !repository2.is_default?
87 95
88 96 assert_equal repository1, Project.find(3).repository
89 97 assert_equal [repository1, repository2], Project.find(3).repositories.sort
90 98 end
91 99
92 100 def test_destroy
93 101 changesets = Changeset.count(:all, :conditions => "repository_id = 10")
94 102 changes = Change.count(:all, :conditions => "repository_id = 10",
95 103 :include => :changeset)
96 104 assert_difference 'Changeset.count', -changesets do
97 105 assert_difference 'Change.count', -changes do
98 106 Repository.find(10).destroy
99 107 end
100 108 end
101 109 end
102 110
103 111 def test_destroy_should_delete_parents_associations
104 112 changeset = Changeset.find(102)
105 113 changeset.parents = Changeset.find_all_by_id([100, 101])
106 114
107 115 assert_difference 'Changeset.connection.select_all("select * from changeset_parents").size', -2 do
108 116 Repository.find(10).destroy
109 117 end
110 118 end
111 119
112 120 def test_destroy_should_delete_issues_associations
113 121 changeset = Changeset.find(102)
114 122 changeset.issues = Issue.find_all_by_id([1, 2])
115 123
116 124 assert_difference 'Changeset.connection.select_all("select * from changesets_issues").size', -2 do
117 125 Repository.find(10).destroy
118 126 end
119 127 end
120 128
121 129 def test_should_not_create_with_disabled_scm
122 130 # disable Subversion
123 131 with_settings :enabled_scm => ['Darcs', 'Git'] do
124 132 repository = Repository::Subversion.new(
125 133 :project => Project.find(3), :url => "svn://localhost")
126 134 assert !repository.save
127 135 assert_equal I18n.translate('activerecord.errors.messages.invalid'),
128 136 repository.errors[:type].to_s
129 137 end
130 138 end
131 139
132 140 def test_scan_changesets_for_issue_ids
133 141 Setting.default_language = 'en'
134 142 Setting.notified_events = ['issue_added','issue_updated']
135 143
136 144 # choosing a status to apply to fix issues
137 145 Setting.commit_fix_status_id = IssueStatus.find(
138 146 :first,
139 147 :conditions => ["is_closed = ?", true]).id
140 148 Setting.commit_fix_done_ratio = "90"
141 149 Setting.commit_ref_keywords = 'refs , references, IssueID'
142 150 Setting.commit_fix_keywords = 'fixes , closes'
143 151 Setting.default_language = 'en'
144 152 ActionMailer::Base.deliveries.clear
145 153
146 154 # make sure issue 1 is not already closed
147 155 fixed_issue = Issue.find(1)
148 156 assert !fixed_issue.status.is_closed?
149 157 old_status = fixed_issue.status
150 158
151 159 Repository.scan_changesets_for_issue_ids
152 160 assert_equal [101, 102], Issue.find(3).changeset_ids
153 161
154 162 # fixed issues
155 163 fixed_issue.reload
156 164 assert fixed_issue.status.is_closed?
157 165 assert_equal 90, fixed_issue.done_ratio
158 166 assert_equal [101], fixed_issue.changeset_ids
159 167
160 168 # issue change
161 169 journal = fixed_issue.journals.find(:first, :order => 'created_on desc')
162 170 assert_equal User.find_by_login('dlopper'), journal.user
163 171 assert_equal 'Applied in changeset r2.', journal.notes
164 172
165 173 # 2 email notifications
166 174 assert_equal 2, ActionMailer::Base.deliveries.size
167 175 mail = ActionMailer::Base.deliveries.first
168 176 assert_kind_of TMail::Mail, mail
169 177 assert mail.subject.starts_with?(
170 178 "[#{fixed_issue.project.name} - #{fixed_issue.tracker.name} ##{fixed_issue.id}]")
171 179 assert mail.body.include?(
172 180 "Status changed from #{old_status} to #{fixed_issue.status}")
173 181
174 182 # ignoring commits referencing an issue of another project
175 183 assert_equal [], Issue.find(4).changesets
176 184 end
177 185
178 186 def test_for_changeset_comments_strip
179 187 repository = Repository::Mercurial.create(
180 188 :project => Project.find( 4 ),
181 189 :url => '/foo/bar/baz' )
182 190 comment = <<-COMMENT
183 191 This is a loooooooooooooooooooooooooooong comment
184 192
185 193
186 194 COMMENT
187 195 changeset = Changeset.new(
188 196 :comments => comment, :commit_date => Time.now,
189 197 :revision => 0, :scmid => 'f39b7922fb3c',
190 198 :committer => 'foo <foo@example.com>',
191 199 :committed_on => Time.now, :repository => repository )
192 200 assert( changeset.save )
193 201 assert_not_equal( comment, changeset.comments )
194 202 assert_equal( 'This is a loooooooooooooooooooooooooooong comment',
195 203 changeset.comments )
196 204 end
197 205
198 206 def test_for_urls_strip_cvs
199 207 repository = Repository::Cvs.create(
200 208 :project => Project.find(4),
201 209 :url => ' :pserver:login:password@host:/path/to/the/repository',
202 210 :root_url => 'foo ',
203 211 :log_encoding => 'UTF-8')
204 212 assert repository.save
205 213 repository.reload
206 214 assert_equal ':pserver:login:password@host:/path/to/the/repository',
207 215 repository.url
208 216 assert_equal 'foo', repository.root_url
209 217 end
210 218
211 219 def test_for_urls_strip_subversion
212 220 repository = Repository::Subversion.create(
213 221 :project => Project.find(4),
214 222 :url => ' file:///dummy ')
215 223 assert repository.save
216 224 repository.reload
217 225 assert_equal 'file:///dummy', repository.url
218 226 end
219 227
220 228 def test_for_urls_strip_git
221 229 repository = Repository::Git.create(
222 230 :project => Project.find(4),
223 231 :url => ' c:\dummy ')
224 232 assert repository.save
225 233 repository.reload
226 234 assert_equal 'c:\dummy', repository.url
227 235 end
228 236
229 237 def test_manual_user_mapping
230 238 assert_no_difference "Changeset.count(:conditions => 'user_id <> 2')" do
231 239 c = Changeset.create!(
232 240 :repository => @repository,
233 241 :committer => 'foo',
234 242 :committed_on => Time.now,
235 243 :revision => 100,
236 244 :comments => 'Committed by foo.'
237 245 )
238 246 assert_nil c.user
239 247 @repository.committer_ids = {'foo' => '2'}
240 248 assert_equal User.find(2), c.reload.user
241 249 # committer is now mapped
242 250 c = Changeset.create!(
243 251 :repository => @repository,
244 252 :committer => 'foo',
245 253 :committed_on => Time.now,
246 254 :revision => 101,
247 255 :comments => 'Another commit by foo.'
248 256 )
249 257 assert_equal User.find(2), c.user
250 258 end
251 259 end
252 260
253 261 def test_auto_user_mapping_by_username
254 262 c = Changeset.create!(
255 263 :repository => @repository,
256 264 :committer => 'jsmith',
257 265 :committed_on => Time.now,
258 266 :revision => 100,
259 267 :comments => 'Committed by john.'
260 268 )
261 269 assert_equal User.find(2), c.user
262 270 end
263 271
264 272 def test_auto_user_mapping_by_email
265 273 c = Changeset.create!(
266 274 :repository => @repository,
267 275 :committer => 'john <jsmith@somenet.foo>',
268 276 :committed_on => Time.now,
269 277 :revision => 100,
270 278 :comments => 'Committed by john.'
271 279 )
272 280 assert_equal User.find(2), c.user
273 281 end
274 282
275 283 def test_filesystem_avaialbe
276 284 klass = Repository::Filesystem
277 285 assert klass.scm_adapter_class
278 286 assert_equal true, klass.scm_available
279 287 end
280 288
281 289 def test_merge_extra_info
282 290 repo = Repository::Subversion.new(:project => Project.find(3))
283 291 assert !repo.save
284 292 repo.url = "svn://localhost"
285 293 assert repo.save
286 294 repo.reload
287 295 project = Project.find(3)
288 296 assert_equal repo, project.repository
289 297 assert_nil repo.extra_info
290 298 h1 = {"test_1" => {"test_11" => "test_value_11"}}
291 299 repo.merge_extra_info(h1)
292 300 assert_equal h1, repo.extra_info
293 301 h2 = {"test_2" => {
294 302 "test_21" => "test_value_21",
295 303 "test_22" => "test_value_22",
296 304 }}
297 305 repo.merge_extra_info(h2)
298 306 assert_equal (h = {"test_11" => "test_value_11"}),
299 307 repo.extra_info["test_1"]
300 308 assert_equal "test_value_21",
301 309 repo.extra_info["test_2"]["test_21"]
302 310 h3 = {"test_2" => {
303 311 "test_23" => "test_value_23",
304 312 "test_24" => "test_value_24",
305 313 }}
306 314 repo.merge_extra_info(h3)
307 315 assert_equal (h = {"test_11" => "test_value_11"}),
308 316 repo.extra_info["test_1"]
309 317 assert_nil repo.extra_info["test_2"]["test_21"]
310 318 assert_equal "test_value_23",
311 319 repo.extra_info["test_2"]["test_23"]
312 320 end
313 321 end
General Comments 0
You need to be logged in to leave comments. Login now