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