##// END OF EJS Templates
fix assertion order at RepositoryCvsTest#test_entries_rev3...
Toshi MARUYAMA -
r13525:403fb37d1c2d
parent child
Show More
@@ -1,270 +1,270
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2015 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 require 'pp'
20 20 class RepositoryCvsTest < ActiveSupport::TestCase
21 21 fixtures :projects
22 22
23 23 include Redmine::I18n
24 24
25 25 REPOSITORY_PATH = repository_path('cvs')
26 26 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
27 27 # CVS module
28 28 MODULE_NAME = 'test'
29 29 CHANGESETS_NUM = 7
30 30
31 31 def setup
32 32 @project = Project.find(3)
33 33 @repository = Repository::Cvs.create(:project => @project,
34 34 :root_url => REPOSITORY_PATH,
35 35 :url => MODULE_NAME,
36 36 :log_encoding => 'UTF-8')
37 37 assert @repository
38 38 end
39 39
40 40 def test_blank_module_error_message
41 41 set_language_if_valid 'en'
42 42 repo = Repository::Cvs.new(
43 43 :project => @project,
44 44 :identifier => 'test',
45 45 :log_encoding => 'UTF-8',
46 46 :root_url => REPOSITORY_PATH
47 47 )
48 48 assert !repo.save
49 49 assert_include "Module cannot be blank",
50 50 repo.errors.full_messages
51 51 end
52 52
53 53 def test_blank_module_error_message_fr
54 54 set_language_if_valid 'fr'
55 55 str = "Module doit \xc3\xaatre renseign\xc3\xa9(e)".force_encoding('UTF-8')
56 56 repo = Repository::Cvs.new(
57 57 :project => @project,
58 58 :identifier => 'test',
59 59 :log_encoding => 'UTF-8',
60 60 :path_encoding => '',
61 61 :url => '',
62 62 :root_url => REPOSITORY_PATH
63 63 )
64 64 assert !repo.save
65 65 assert_include str, repo.errors.full_messages
66 66 end
67 67
68 68 def test_blank_cvsroot_error_message
69 69 set_language_if_valid 'en'
70 70 repo = Repository::Cvs.new(
71 71 :project => @project,
72 72 :identifier => 'test',
73 73 :log_encoding => 'UTF-8',
74 74 :url => MODULE_NAME
75 75 )
76 76 assert !repo.save
77 77 assert_include "CVSROOT cannot be blank",
78 78 repo.errors.full_messages
79 79 end
80 80
81 81 def test_blank_cvsroot_error_message_fr
82 82 set_language_if_valid 'fr'
83 83 str = "CVSROOT doit \xc3\xaatre renseign\xc3\xa9(e)".force_encoding('UTF-8')
84 84 repo = Repository::Cvs.new(
85 85 :project => @project,
86 86 :identifier => 'test',
87 87 :log_encoding => 'UTF-8',
88 88 :path_encoding => '',
89 89 :url => MODULE_NAME,
90 90 :root_url => ''
91 91 )
92 92 assert !repo.save
93 93 assert_include str, repo.errors.full_messages
94 94 end
95 95
96 96 def test_root_url_should_be_validated_against_regexp_set_in_configuration
97 97 Redmine::Configuration.with 'scm_cvs_path_regexp' => '/cvspath/[a-z]+' do
98 98 repo = Repository::Cvs.new(
99 99 :project => @project,
100 100 :identifier => 'test',
101 101 :log_encoding => 'UTF-8',
102 102 :path_encoding => '',
103 103 :url => MODULE_NAME
104 104 )
105 105 repo.root_url = '/wrong_path'
106 106 assert !repo.valid?
107 107 assert repo.errors[:root_url].present?
108 108
109 109 repo.root_url = '/cvspath/foo'
110 110 assert repo.valid?
111 111 end
112 112 end
113 113
114 114 if File.directory?(REPOSITORY_PATH)
115 115 def test_fetch_changesets_from_scratch
116 116 assert_equal 0, @repository.changesets.count
117 117 @repository.fetch_changesets
118 118 @project.reload
119 119
120 120 assert_equal CHANGESETS_NUM, @repository.changesets.count
121 121 assert_equal 16, @repository.filechanges.count
122 122 assert_not_nil @repository.changesets.find_by_comments('Two files changed')
123 123
124 124 r2 = @repository.changesets.find_by_revision('2')
125 125 assert_equal 'v1-20071213-162510', r2.scmid
126 126 end
127 127
128 128 def test_fetch_changesets_incremental
129 129 assert_equal 0, @repository.changesets.count
130 130 @repository.fetch_changesets
131 131 @project.reload
132 132 assert_equal CHANGESETS_NUM, @repository.changesets.count
133 133
134 134 # Remove changesets with revision > 3
135 135 @repository.changesets.each {|c| c.destroy if c.revision.to_i > 3}
136 136 @project.reload
137 137 @repository.reload
138 138 assert_equal 3, @repository.changesets.count
139 139 assert_equal %w|3 2 1|, @repository.changesets.collect(&:revision)
140 140
141 141 rev3_commit = @repository.changesets.reorder('committed_on DESC').first
142 142 assert_equal '3', rev3_commit.revision
143 143 # 2007-12-14 01:27:22 +0900
144 144 rev3_committed_on = Time.gm(2007, 12, 13, 16, 27, 22)
145 145 assert_equal 'HEAD-20071213-162722', rev3_commit.scmid
146 146 assert_equal rev3_committed_on, rev3_commit.committed_on
147 147 latest_rev = @repository.latest_changeset
148 148 assert_equal rev3_committed_on, latest_rev.committed_on
149 149
150 150 @repository.fetch_changesets
151 151 @project.reload
152 152 @repository.reload
153 153 assert_equal CHANGESETS_NUM, @repository.changesets.count
154 154 assert_equal %w|7 6 5 4 3 2 1|, @repository.changesets.collect(&:revision)
155 155 rev5_commit = @repository.changesets.find_by_revision('5')
156 156 assert_equal 'HEAD-20071213-163001', rev5_commit.scmid
157 157 # 2007-12-14 01:30:01 +0900
158 158 rev5_committed_on = Time.gm(2007, 12, 13, 16, 30, 1)
159 159 assert_equal rev5_committed_on, rev5_commit.committed_on
160 160 end
161 161
162 162 def test_deleted_files_should_not_be_listed
163 163 assert_equal 0, @repository.changesets.count
164 164 @repository.fetch_changesets
165 165 @project.reload
166 166 assert_equal CHANGESETS_NUM, @repository.changesets.count
167 167
168 168 entries = @repository.entries('sources')
169 169 assert entries.detect {|e| e.name == 'watchers_controller.rb'}
170 170 assert_nil entries.detect {|e| e.name == 'welcome_controller.rb'}
171 171 end
172 172
173 173 def test_entries_rev3
174 174 assert_equal 0, @repository.changesets.count
175 175 @repository.fetch_changesets
176 176 @project.reload
177 177 assert_equal CHANGESETS_NUM, @repository.changesets.count
178 178
179 179 rev3_commit = @repository.changesets.find_by_revision('3')
180 180 assert_equal "3", rev3_commit.revision
181 181 assert_equal "LANG", rev3_commit.committer
182 182 assert_equal 2, rev3_commit.filechanges.length
183 183 assert_equal "1.2", rev3_commit.filechanges[0].revision
184 184 assert_equal "1.2", rev3_commit.filechanges[1].revision
185 185 assert_equal "/README", rev3_commit.filechanges[0].path
186 186 assert_equal "/sources/watchers_controller.rb", rev3_commit.filechanges[1].path
187 187
188 188 entries = @repository.entries('', '3')
189 189 assert_kind_of Redmine::Scm::Adapters::Entries, entries
190 190 assert_equal 3, entries.size
191 assert_equal entries[2].name, "README"
191 assert_equal "README", entries[2].name
192 192 assert_equal 'UTF-8', entries[2].path.encoding.to_s
193 assert_equal entries[2].lastrev.time, Time.gm(2007, 12, 13, 16, 27, 22)
194 assert_equal entries[2].lastrev.identifier, '3'
195 assert_equal entries[2].lastrev.revision, '3'
196 assert_equal entries[2].lastrev.author, 'LANG'
193 assert_equal Time.gm(2007, 12, 13, 16, 27, 22), entries[2].lastrev.time
194 assert_equal '3', entries[2].lastrev.identifier
195 assert_equal '3', entries[2].lastrev.revision
196 assert_equal 'LANG', entries[2].lastrev.author
197 197 end
198 198
199 199 def test_entries_invalid_path
200 200 assert_equal 0, @repository.changesets.count
201 201 @repository.fetch_changesets
202 202 @project.reload
203 203 assert_equal CHANGESETS_NUM, @repository.changesets.count
204 204 assert_nil @repository.entries('missing')
205 205 assert_nil @repository.entries('missing', '3')
206 206 end
207 207
208 208 def test_entries_invalid_revision
209 209 assert_equal 0, @repository.changesets.count
210 210 @repository.fetch_changesets
211 211 @project.reload
212 212 assert_equal CHANGESETS_NUM, @repository.changesets.count
213 213 assert_nil @repository.entries('', '123')
214 214 end
215 215
216 216 def test_cat
217 217 assert_equal 0, @repository.changesets.count
218 218 @repository.fetch_changesets
219 219 @project.reload
220 220 assert_equal CHANGESETS_NUM, @repository.changesets.count
221 221 buf = @repository.cat('README')
222 222 assert buf
223 223 lines = buf.split("\n")
224 224 assert_equal 3, lines.length
225 225 buf = lines[1].gsub(/\r$/, "")
226 226 assert_equal 'with one change', buf
227 227 buf = @repository.cat('README', '1')
228 228 assert buf
229 229 lines = buf.split("\n")
230 230 assert_equal 1, lines.length
231 231 buf = lines[0].gsub(/\r$/, "")
232 232 assert_equal 'CVS test repository', buf
233 233 assert_nil @repository.cat('missing.rb')
234 234
235 235 # sources/welcome_controller.rb is removed at revision 5.
236 236 assert @repository.cat('sources/welcome_controller.rb', '4')
237 237 assert @repository.cat('sources/welcome_controller.rb', '5').blank?
238 238
239 239 # invalid revision
240 240 assert @repository.cat('README', '123').blank?
241 241 end
242 242
243 243 def test_annotate
244 244 assert_equal 0, @repository.changesets.count
245 245 @repository.fetch_changesets
246 246 @project.reload
247 247 assert_equal CHANGESETS_NUM, @repository.changesets.count
248 248 ann = @repository.annotate('README')
249 249 assert ann
250 250 assert_equal 3, ann.revisions.length
251 251 assert_equal '1.2', ann.revisions[1].revision
252 252 assert_equal 'LANG', ann.revisions[1].author
253 253 assert_equal 'with one change', ann.lines[1]
254 254
255 255 ann = @repository.annotate('README', '1')
256 256 assert ann
257 257 assert_equal 1, ann.revisions.length
258 258 assert_equal '1.1', ann.revisions[0].revision
259 259 assert_equal 'LANG', ann.revisions[0].author
260 260 assert_equal 'CVS test repository', ann.lines[0]
261 261
262 262 # invalid revision
263 263 assert_nil @repository.annotate('README', '123')
264 264 end
265 265
266 266 else
267 267 puts "CVS test repository NOT FOUND. Skipping unit tests !!!"
268 268 def test_fake; assert true end
269 269 end
270 270 end
General Comments 0
You need to be logged in to leave comments. Login now