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