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