##// END OF EJS Templates
test: switch to Rails3 Active Record syntax at test_destroy of unit/repository_test.rb...
Toshi MARUYAMA -
r9440:bef28f7dabc4
parent child
Show More
@@ -1,330 +1,329
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 80 repository1 = Repository::Subversion.new(
81 81 :project => Project.find(3),
82 82 :identifier => 'svn1',
83 83 :url => 'file:///svn1'
84 84 )
85 85 assert repository1.save
86 86 assert repository1.is_default?
87 87
88 88 repository2 = Repository::Subversion.new(
89 89 :project => Project.find(3),
90 90 :identifier => 'svn2',
91 91 :url => 'file:///svn2'
92 92 )
93 93 assert repository2.save
94 94 assert !repository2.is_default?
95 95
96 96 assert_equal repository1, Project.find(3).repository
97 97 assert_equal [repository1, repository2], Project.find(3).repositories.sort
98 98 end
99 99
100 100 def test_destroy
101 changesets = Changeset.count(:all, :conditions => "repository_id = 10")
102 changes = Change.count(:all, :conditions => "repository_id = 10",
103 :joins => :changeset)
101 changesets = Changeset.where("repository_id = 10").all.count
102 changes = Changeset.joins([:changes]).where("repository_id = 10").all.count
104 103 assert_difference 'Changeset.count', -changesets do
105 104 assert_difference 'Change.count', -changes do
106 105 Repository.find(10).destroy
107 106 end
108 107 end
109 108 end
110 109
111 110 def test_destroy_should_delete_parents_associations
112 111 changeset = Changeset.find(102)
113 112 changeset.parents = Changeset.find_all_by_id([100, 101])
114 113
115 114 assert_difference 'Changeset.connection.select_all("select * from changeset_parents").size', -2 do
116 115 Repository.find(10).destroy
117 116 end
118 117 end
119 118
120 119 def test_destroy_should_delete_issues_associations
121 120 changeset = Changeset.find(102)
122 121 changeset.issues = Issue.find_all_by_id([1, 2])
123 122
124 123 assert_difference 'Changeset.connection.select_all("select * from changesets_issues").size', -2 do
125 124 Repository.find(10).destroy
126 125 end
127 126 end
128 127
129 128 def test_should_not_create_with_disabled_scm
130 129 # disable Subversion
131 130 with_settings :enabled_scm => ['Darcs', 'Git'] do
132 131 repository = Repository::Subversion.new(
133 132 :project => Project.find(3), :url => "svn://localhost")
134 133 assert !repository.save
135 134 assert_include I18n.translate('activerecord.errors.messages.invalid'),
136 135 repository.errors[:type]
137 136 end
138 137 end
139 138
140 139 def test_scan_changesets_for_issue_ids
141 140 Setting.default_language = 'en'
142 141 Setting.notified_events = ['issue_added','issue_updated']
143 142
144 143 # choosing a status to apply to fix issues
145 144 Setting.commit_fix_status_id = IssueStatus.find(
146 145 :first,
147 146 :conditions => ["is_closed = ?", true]).id
148 147 Setting.commit_fix_done_ratio = "90"
149 148 Setting.commit_ref_keywords = 'refs , references, IssueID'
150 149 Setting.commit_fix_keywords = 'fixes , closes'
151 150 Setting.default_language = 'en'
152 151 ActionMailer::Base.deliveries.clear
153 152
154 153 # make sure issue 1 is not already closed
155 154 fixed_issue = Issue.find(1)
156 155 assert !fixed_issue.status.is_closed?
157 156 old_status = fixed_issue.status
158 157
159 158 Repository.scan_changesets_for_issue_ids
160 159 assert_equal [101, 102], Issue.find(3).changeset_ids
161 160
162 161 # fixed issues
163 162 fixed_issue.reload
164 163 assert fixed_issue.status.is_closed?
165 164 assert_equal 90, fixed_issue.done_ratio
166 165 assert_equal [101], fixed_issue.changeset_ids
167 166
168 167 # issue change
169 168 journal = fixed_issue.journals.find(:first, :order => 'created_on desc')
170 169 assert_equal User.find_by_login('dlopper'), journal.user
171 170 assert_equal 'Applied in changeset r2.', journal.notes
172 171
173 172 # 2 email notifications
174 173 assert_equal 2, ActionMailer::Base.deliveries.size
175 174 mail = ActionMailer::Base.deliveries.first
176 175 assert_not_nil mail
177 176 assert mail.subject.starts_with?(
178 177 "[#{fixed_issue.project.name} - #{fixed_issue.tracker.name} ##{fixed_issue.id}]")
179 178 assert_mail_body_match(
180 179 "Status changed from #{old_status} to #{fixed_issue.status}", mail)
181 180
182 181 # ignoring commits referencing an issue of another project
183 182 assert_equal [], Issue.find(4).changesets
184 183 end
185 184
186 185 def test_for_changeset_comments_strip
187 186 repository = Repository::Mercurial.create(
188 187 :project => Project.find( 4 ),
189 188 :url => '/foo/bar/baz' )
190 189 comment = <<-COMMENT
191 190 This is a loooooooooooooooooooooooooooong comment
192 191
193 192
194 193 COMMENT
195 194 changeset = Changeset.new(
196 195 :comments => comment, :commit_date => Time.now,
197 196 :revision => 0, :scmid => 'f39b7922fb3c',
198 197 :committer => 'foo <foo@example.com>',
199 198 :committed_on => Time.now, :repository => repository )
200 199 assert( changeset.save )
201 200 assert_not_equal( comment, changeset.comments )
202 201 assert_equal( 'This is a loooooooooooooooooooooooooooong comment',
203 202 changeset.comments )
204 203 end
205 204
206 205 def test_for_urls_strip_cvs
207 206 repository = Repository::Cvs.create(
208 207 :project => Project.find(4),
209 208 :url => ' :pserver:login:password@host:/path/to/the/repository',
210 209 :root_url => 'foo ',
211 210 :log_encoding => 'UTF-8')
212 211 assert repository.save
213 212 repository.reload
214 213 assert_equal ':pserver:login:password@host:/path/to/the/repository',
215 214 repository.url
216 215 assert_equal 'foo', repository.root_url
217 216 end
218 217
219 218 def test_for_urls_strip_subversion
220 219 repository = Repository::Subversion.create(
221 220 :project => Project.find(4),
222 221 :url => ' file:///dummy ')
223 222 assert repository.save
224 223 repository.reload
225 224 assert_equal 'file:///dummy', repository.url
226 225 end
227 226
228 227 def test_for_urls_strip_git
229 228 repository = Repository::Git.create(
230 229 :project => Project.find(4),
231 230 :url => ' c:\dummy ')
232 231 assert repository.save
233 232 repository.reload
234 233 assert_equal 'c:\dummy', repository.url
235 234 end
236 235
237 236 def test_manual_user_mapping
238 237 assert_no_difference "Changeset.count(:conditions => 'user_id <> 2')" do
239 238 c = Changeset.create!(
240 239 :repository => @repository,
241 240 :committer => 'foo',
242 241 :committed_on => Time.now,
243 242 :revision => 100,
244 243 :comments => 'Committed by foo.'
245 244 )
246 245 assert_nil c.user
247 246 @repository.committer_ids = {'foo' => '2'}
248 247 assert_equal User.find(2), c.reload.user
249 248 # committer is now mapped
250 249 c = Changeset.create!(
251 250 :repository => @repository,
252 251 :committer => 'foo',
253 252 :committed_on => Time.now,
254 253 :revision => 101,
255 254 :comments => 'Another commit by foo.'
256 255 )
257 256 assert_equal User.find(2), c.user
258 257 end
259 258 end
260 259
261 260 def test_auto_user_mapping_by_username
262 261 c = Changeset.create!(
263 262 :repository => @repository,
264 263 :committer => 'jsmith',
265 264 :committed_on => Time.now,
266 265 :revision => 100,
267 266 :comments => 'Committed by john.'
268 267 )
269 268 assert_equal User.find(2), c.user
270 269 end
271 270
272 271 def test_auto_user_mapping_by_email
273 272 c = Changeset.create!(
274 273 :repository => @repository,
275 274 :committer => 'john <jsmith@somenet.foo>',
276 275 :committed_on => Time.now,
277 276 :revision => 100,
278 277 :comments => 'Committed by john.'
279 278 )
280 279 assert_equal User.find(2), c.user
281 280 end
282 281
283 282 def test_filesystem_avaialbe
284 283 klass = Repository::Filesystem
285 284 assert klass.scm_adapter_class
286 285 assert_equal true, klass.scm_available
287 286 end
288 287
289 288 def test_merge_extra_info
290 289 repo = Repository::Subversion.new(:project => Project.find(3))
291 290 assert !repo.save
292 291 repo.url = "svn://localhost"
293 292 assert repo.save
294 293 repo.reload
295 294 project = Project.find(3)
296 295 assert_equal repo, project.repository
297 296 assert_nil repo.extra_info
298 297 h1 = {"test_1" => {"test_11" => "test_value_11"}}
299 298 repo.merge_extra_info(h1)
300 299 assert_equal h1, repo.extra_info
301 300 h2 = {"test_2" => {
302 301 "test_21" => "test_value_21",
303 302 "test_22" => "test_value_22",
304 303 }}
305 304 repo.merge_extra_info(h2)
306 305 assert_equal (h = {"test_11" => "test_value_11"}),
307 306 repo.extra_info["test_1"]
308 307 assert_equal "test_value_21",
309 308 repo.extra_info["test_2"]["test_21"]
310 309 h3 = {"test_2" => {
311 310 "test_23" => "test_value_23",
312 311 "test_24" => "test_value_24",
313 312 }}
314 313 repo.merge_extra_info(h3)
315 314 assert_equal (h = {"test_11" => "test_value_11"}),
316 315 repo.extra_info["test_1"]
317 316 assert_nil repo.extra_info["test_2"]["test_21"]
318 317 assert_equal "test_value_23",
319 318 repo.extra_info["test_2"]["test_23"]
320 319 end
321 320
322 321 def test_sort_should_not_raise_an_error_with_nil_identifiers
323 322 r1 = Repository.new
324 323 r2 = Repository.new
325 324
326 325 assert_nothing_raised do
327 326 [r1, r2].sort
328 327 end
329 328 end
330 329 end
General Comments 0
You need to be logged in to leave comments. Login now