##// END OF EJS Templates
scm: code clean up unit repository test....
Toshi MARUYAMA -
r5589:a05a2e0c4d0d
parent child
Show More
@@ -1,192 +1,205
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_destroy
54 54 changesets = Changeset.count(:all, :conditions => "repository_id = 10")
55 changes = Change.count(:all, :conditions => "repository_id = 10", :include => :changeset)
55 changes = Change.count(:all, :conditions => "repository_id = 10",
56 :include => :changeset)
56 57 assert_difference 'Changeset.count', -changesets do
57 58 assert_difference 'Change.count', -changes do
58 59 Repository.find(10).destroy
59 60 end
60 61 end
61 62 end
62 63
63 64 def test_should_not_create_with_disabled_scm
64 65 # disable Subversion
65 66 with_settings :enabled_scm => ['Darcs', 'Git'] do
66 repository = Repository::Subversion.new(:project => Project.find(3), :url => "svn://localhost")
67 repository = Repository::Subversion.new(
68 :project => Project.find(3), :url => "svn://localhost")
67 69 assert !repository.save
68 assert_equal I18n.translate('activerecord.errors.messages.invalid'), repository.errors.on(:type)
70 assert_equal I18n.translate('activerecord.errors.messages.invalid'),
71 repository.errors.on(:type)
69 72 end
70 73 end
71 74
72 75 def test_scan_changesets_for_issue_ids
73 76 Setting.default_language = 'en'
74 77 Setting.notified_events = ['issue_added','issue_updated']
75 78
76 79 # choosing a status to apply to fix issues
77 Setting.commit_fix_status_id = IssueStatus.find(:first, :conditions => ["is_closed = ?", true]).id
80 Setting.commit_fix_status_id = IssueStatus.find(
81 :first,
82 :conditions => ["is_closed = ?", true]).id
78 83 Setting.commit_fix_done_ratio = "90"
79 84 Setting.commit_ref_keywords = 'refs , references, IssueID'
80 85 Setting.commit_fix_keywords = 'fixes , closes'
81 86 Setting.default_language = 'en'
82 87 ActionMailer::Base.deliveries.clear
83 88
84 89 # make sure issue 1 is not already closed
85 90 fixed_issue = Issue.find(1)
86 91 assert !fixed_issue.status.is_closed?
87 92 old_status = fixed_issue.status
88 93
89 94 Repository.scan_changesets_for_issue_ids
90 95 assert_equal [101, 102], Issue.find(3).changeset_ids
91 96
92 97 # fixed issues
93 98 fixed_issue.reload
94 99 assert fixed_issue.status.is_closed?
95 100 assert_equal 90, fixed_issue.done_ratio
96 101 assert_equal [101], fixed_issue.changeset_ids
97 102
98 103 # issue change
99 104 journal = fixed_issue.journals.find(:first, :order => 'created_on desc')
100 105 assert_equal User.find_by_login('dlopper'), journal.user
101 106 assert_equal 'Applied in changeset r2.', journal.notes
102 107
103 108 # 2 email notifications
104 109 assert_equal 2, ActionMailer::Base.deliveries.size
105 110 mail = ActionMailer::Base.deliveries.first
106 111 assert_kind_of TMail::Mail, mail
107 assert mail.subject.starts_with?("[#{fixed_issue.project.name} - #{fixed_issue.tracker.name} ##{fixed_issue.id}]")
108 assert mail.body.include?("Status changed from #{old_status} to #{fixed_issue.status}")
112 assert mail.subject.starts_with?(
113 "[#{fixed_issue.project.name} - #{fixed_issue.tracker.name} ##{fixed_issue.id}]")
114 assert mail.body.include?(
115 "Status changed from #{old_status} to #{fixed_issue.status}")
109 116
110 117 # ignoring commits referencing an issue of another project
111 118 assert_equal [], Issue.find(4).changesets
112 119 end
113 120
114 121 def test_for_changeset_comments_strip
115 repository = Repository::Mercurial.create( :project => Project.find( 4 ), :url => '/foo/bar/baz' )
122 repository = Repository::Mercurial.create(
123 :project => Project.find( 4 ),
124 :url => '/foo/bar/baz' )
116 125 comment = <<-COMMENT
117 126 This is a loooooooooooooooooooooooooooong comment
118 127
119 128
120 129 COMMENT
121 130 changeset = Changeset.new(
122 :comments => comment, :commit_date => Time.now, :revision => 0, :scmid => 'f39b7922fb3c',
123 :committer => 'foo <foo@example.com>', :committed_on => Time.now, :repository => repository )
131 :comments => comment, :commit_date => Time.now,
132 :revision => 0, :scmid => 'f39b7922fb3c',
133 :committer => 'foo <foo@example.com>',
134 :committed_on => Time.now, :repository => repository )
124 135 assert( changeset.save )
125 136 assert_not_equal( comment, changeset.comments )
126 assert_equal( 'This is a loooooooooooooooooooooooooooong comment', changeset.comments )
137 assert_equal( 'This is a loooooooooooooooooooooooooooong comment',
138 changeset.comments )
127 139 end
128 140
129 141 def test_for_urls_strip
130 142 repository = Repository::Cvs.create(
131 143 :project => Project.find(4),
132 144 :url => ' :pserver:login:password@host:/path/to/the/repository',
133 145 :root_url => 'foo ',
134 146 :log_encoding => 'UTF-8')
135 147 assert repository.save
136 148 repository.reload
137 assert_equal ':pserver:login:password@host:/path/to/the/repository', repository.url
149 assert_equal ':pserver:login:password@host:/path/to/the/repository',
150 repository.url
138 151 assert_equal 'foo', repository.root_url
139 152 end
140 153
141 154 def test_manual_user_mapping
142 155 assert_no_difference "Changeset.count(:conditions => 'user_id <> 2')" do
143 156 c = Changeset.create!(
144 157 :repository => @repository,
145 158 :committer => 'foo',
146 159 :committed_on => Time.now,
147 160 :revision => 100,
148 161 :comments => 'Committed by foo.'
149 162 )
150 163 assert_nil c.user
151 164 @repository.committer_ids = {'foo' => '2'}
152 165 assert_equal User.find(2), c.reload.user
153 166 # committer is now mapped
154 167 c = Changeset.create!(
155 168 :repository => @repository,
156 169 :committer => 'foo',
157 170 :committed_on => Time.now,
158 171 :revision => 101,
159 172 :comments => 'Another commit by foo.'
160 173 )
161 174 assert_equal User.find(2), c.user
162 175 end
163 176 end
164 177
165 178 def test_auto_user_mapping_by_username
166 179 c = Changeset.create!(
167 180 :repository => @repository,
168 181 :committer => 'jsmith',
169 182 :committed_on => Time.now,
170 183 :revision => 100,
171 184 :comments => 'Committed by john.'
172 185 )
173 186 assert_equal User.find(2), c.user
174 187 end
175 188
176 189 def test_auto_user_mapping_by_email
177 190 c = Changeset.create!(
178 191 :repository => @repository,
179 192 :committer => 'john <jsmith@somenet.foo>',
180 193 :committed_on => Time.now,
181 194 :revision => 100,
182 195 :comments => 'Committed by john.'
183 196 )
184 197 assert_equal User.find(2), c.user
185 198 end
186 199
187 200 def test_filesystem_avaialbe
188 201 klass = Repository::Filesystem
189 202 assert klass.scm_adapter_class
190 203 assert_equal true, klass.scm_available
191 204 end
192 205 end
General Comments 0
You need to be logged in to leave comments. Login now