##// END OF EJS Templates
Adds a test for changeset/issue relations deletion....
Jean-Philippe Lang -
r8728:b5fabd052bc5
parent child
Show More
@@ -1,278 +1,287
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 def setup
38 38 @repository = Project.find(1).repository
39 39 end
40 40
41 41 def test_create
42 42 repository = Repository::Subversion.new(:project => Project.find(3))
43 43 assert !repository.save
44 44
45 45 repository.url = "svn://localhost"
46 46 assert repository.save
47 47 repository.reload
48 48
49 49 project = Project.find(3)
50 50 assert_equal repository, project.repository
51 51 end
52 52
53 53 def test_first_repository_should_be_set_as_default
54 54 repository1 = Repository::Subversion.new(:project => Project.find(3), :identifier => 'svn1', :url => 'file:///svn1')
55 55 assert repository1.save
56 56 assert repository1.is_default?
57 57
58 58 repository2 = Repository::Subversion.new(:project => Project.find(3), :identifier => 'svn2', :url => 'file:///svn2')
59 59 assert repository2.save
60 60 assert !repository2.is_default?
61 61
62 62 assert_equal repository1, Project.find(3).repository
63 63 assert_equal [repository1, repository2], Project.find(3).repositories.sort
64 64 end
65 65
66 66 def test_destroy
67 67 changesets = Changeset.count(:all, :conditions => "repository_id = 10")
68 68 changes = Change.count(:all, :conditions => "repository_id = 10",
69 69 :include => :changeset)
70 70 assert_difference 'Changeset.count', -changesets do
71 71 assert_difference 'Change.count', -changes do
72 72 Repository.find(10).destroy
73 73 end
74 74 end
75 75 end
76 76
77 77 def test_destroy_should_delete_parents_associations
78 78 changeset = Changeset.find(102)
79 79 changeset.parents = Changeset.find_all_by_id([100, 101])
80 80
81 81 assert_difference 'Changeset.connection.select_all("select * from changeset_parents").size', -2 do
82 82 Repository.find(10).destroy
83 83 end
84 84 end
85 85
86 def test_destroy_should_delete_issues_associations
87 changeset = Changeset.find(102)
88 changeset.issues = Issue.find_all_by_id([1, 2])
89
90 assert_difference 'Changeset.connection.select_all("select * from changesets_issues").size', -2 do
91 Repository.find(10).destroy
92 end
93 end
94
86 95 def test_should_not_create_with_disabled_scm
87 96 # disable Subversion
88 97 with_settings :enabled_scm => ['Darcs', 'Git'] do
89 98 repository = Repository::Subversion.new(
90 99 :project => Project.find(3), :url => "svn://localhost")
91 100 assert !repository.save
92 101 assert_equal I18n.translate('activerecord.errors.messages.invalid'),
93 102 repository.errors[:type].to_s
94 103 end
95 104 end
96 105
97 106 def test_scan_changesets_for_issue_ids
98 107 Setting.default_language = 'en'
99 108 Setting.notified_events = ['issue_added','issue_updated']
100 109
101 110 # choosing a status to apply to fix issues
102 111 Setting.commit_fix_status_id = IssueStatus.find(
103 112 :first,
104 113 :conditions => ["is_closed = ?", true]).id
105 114 Setting.commit_fix_done_ratio = "90"
106 115 Setting.commit_ref_keywords = 'refs , references, IssueID'
107 116 Setting.commit_fix_keywords = 'fixes , closes'
108 117 Setting.default_language = 'en'
109 118 ActionMailer::Base.deliveries.clear
110 119
111 120 # make sure issue 1 is not already closed
112 121 fixed_issue = Issue.find(1)
113 122 assert !fixed_issue.status.is_closed?
114 123 old_status = fixed_issue.status
115 124
116 125 Repository.scan_changesets_for_issue_ids
117 126 assert_equal [101, 102], Issue.find(3).changeset_ids
118 127
119 128 # fixed issues
120 129 fixed_issue.reload
121 130 assert fixed_issue.status.is_closed?
122 131 assert_equal 90, fixed_issue.done_ratio
123 132 assert_equal [101], fixed_issue.changeset_ids
124 133
125 134 # issue change
126 135 journal = fixed_issue.journals.find(:first, :order => 'created_on desc')
127 136 assert_equal User.find_by_login('dlopper'), journal.user
128 137 assert_equal 'Applied in changeset r2.', journal.notes
129 138
130 139 # 2 email notifications
131 140 assert_equal 2, ActionMailer::Base.deliveries.size
132 141 mail = ActionMailer::Base.deliveries.first
133 142 assert_kind_of TMail::Mail, mail
134 143 assert mail.subject.starts_with?(
135 144 "[#{fixed_issue.project.name} - #{fixed_issue.tracker.name} ##{fixed_issue.id}]")
136 145 assert mail.body.include?(
137 146 "Status changed from #{old_status} to #{fixed_issue.status}")
138 147
139 148 # ignoring commits referencing an issue of another project
140 149 assert_equal [], Issue.find(4).changesets
141 150 end
142 151
143 152 def test_for_changeset_comments_strip
144 153 repository = Repository::Mercurial.create(
145 154 :project => Project.find( 4 ),
146 155 :url => '/foo/bar/baz' )
147 156 comment = <<-COMMENT
148 157 This is a loooooooooooooooooooooooooooong comment
149 158
150 159
151 160 COMMENT
152 161 changeset = Changeset.new(
153 162 :comments => comment, :commit_date => Time.now,
154 163 :revision => 0, :scmid => 'f39b7922fb3c',
155 164 :committer => 'foo <foo@example.com>',
156 165 :committed_on => Time.now, :repository => repository )
157 166 assert( changeset.save )
158 167 assert_not_equal( comment, changeset.comments )
159 168 assert_equal( 'This is a loooooooooooooooooooooooooooong comment',
160 169 changeset.comments )
161 170 end
162 171
163 172 def test_for_urls_strip_cvs
164 173 repository = Repository::Cvs.create(
165 174 :project => Project.find(4),
166 175 :url => ' :pserver:login:password@host:/path/to/the/repository',
167 176 :root_url => 'foo ',
168 177 :log_encoding => 'UTF-8')
169 178 assert repository.save
170 179 repository.reload
171 180 assert_equal ':pserver:login:password@host:/path/to/the/repository',
172 181 repository.url
173 182 assert_equal 'foo', repository.root_url
174 183 end
175 184
176 185 def test_for_urls_strip_subversion
177 186 repository = Repository::Subversion.create(
178 187 :project => Project.find(4),
179 188 :url => ' file:///dummy ')
180 189 assert repository.save
181 190 repository.reload
182 191 assert_equal 'file:///dummy', repository.url
183 192 end
184 193
185 194 def test_for_urls_strip_git
186 195 repository = Repository::Git.create(
187 196 :project => Project.find(4),
188 197 :url => ' c:\dummy ')
189 198 assert repository.save
190 199 repository.reload
191 200 assert_equal 'c:\dummy', repository.url
192 201 end
193 202
194 203 def test_manual_user_mapping
195 204 assert_no_difference "Changeset.count(:conditions => 'user_id <> 2')" do
196 205 c = Changeset.create!(
197 206 :repository => @repository,
198 207 :committer => 'foo',
199 208 :committed_on => Time.now,
200 209 :revision => 100,
201 210 :comments => 'Committed by foo.'
202 211 )
203 212 assert_nil c.user
204 213 @repository.committer_ids = {'foo' => '2'}
205 214 assert_equal User.find(2), c.reload.user
206 215 # committer is now mapped
207 216 c = Changeset.create!(
208 217 :repository => @repository,
209 218 :committer => 'foo',
210 219 :committed_on => Time.now,
211 220 :revision => 101,
212 221 :comments => 'Another commit by foo.'
213 222 )
214 223 assert_equal User.find(2), c.user
215 224 end
216 225 end
217 226
218 227 def test_auto_user_mapping_by_username
219 228 c = Changeset.create!(
220 229 :repository => @repository,
221 230 :committer => 'jsmith',
222 231 :committed_on => Time.now,
223 232 :revision => 100,
224 233 :comments => 'Committed by john.'
225 234 )
226 235 assert_equal User.find(2), c.user
227 236 end
228 237
229 238 def test_auto_user_mapping_by_email
230 239 c = Changeset.create!(
231 240 :repository => @repository,
232 241 :committer => 'john <jsmith@somenet.foo>',
233 242 :committed_on => Time.now,
234 243 :revision => 100,
235 244 :comments => 'Committed by john.'
236 245 )
237 246 assert_equal User.find(2), c.user
238 247 end
239 248
240 249 def test_filesystem_avaialbe
241 250 klass = Repository::Filesystem
242 251 assert klass.scm_adapter_class
243 252 assert_equal true, klass.scm_available
244 253 end
245 254
246 255 def test_merge_extra_info
247 256 repo = Repository::Subversion.new(:project => Project.find(3))
248 257 assert !repo.save
249 258 repo.url = "svn://localhost"
250 259 assert repo.save
251 260 repo.reload
252 261 project = Project.find(3)
253 262 assert_equal repo, project.repository
254 263 assert_nil repo.extra_info
255 264 h1 = {"test_1" => {"test_11" => "test_value_11"}}
256 265 repo.merge_extra_info(h1)
257 266 assert_equal h1, repo.extra_info
258 267 h2 = {"test_2" => {
259 268 "test_21" => "test_value_21",
260 269 "test_22" => "test_value_22",
261 270 }}
262 271 repo.merge_extra_info(h2)
263 272 assert_equal (h = {"test_11" => "test_value_11"}),
264 273 repo.extra_info["test_1"]
265 274 assert_equal "test_value_21",
266 275 repo.extra_info["test_2"]["test_21"]
267 276 h3 = {"test_2" => {
268 277 "test_23" => "test_value_23",
269 278 "test_24" => "test_value_24",
270 279 }}
271 280 repo.merge_extra_info(h3)
272 281 assert_equal (h = {"test_11" => "test_value_11"}),
273 282 repo.extra_info["test_1"]
274 283 assert_nil repo.extra_info["test_2"]["test_21"]
275 284 assert_equal "test_value_23",
276 285 repo.extra_info["test_2"]["test_23"]
277 286 end
278 287 end
General Comments 0
You need to be logged in to leave comments. Login now