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