##// END OF EJS Templates
Rails3: scm: cvs: fix error of test_fetch_changesets_incremental at unit model test...
Toshi MARUYAMA -
r8896:9c264a7e66cb
parent child
Show More
@@ -1,238 +1,240
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 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 = Rails.root.join('tmp/test/cvs_repository').to_s
25 REPOSITORY_PATH = Rails.root.join('tmp/test/cvs_repository').to_s
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 can't be blank",
49 assert_include "Module can't 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)"
55 str = "Module doit \xc3\xaatre renseign\xc3\xa9(e)"
56 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
56 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
57 repo = Repository::Cvs.new(
57 repo = Repository::Cvs.new(
58 :project => @project,
58 :project => @project,
59 :identifier => 'test',
59 :identifier => 'test',
60 :log_encoding => 'UTF-8',
60 :log_encoding => 'UTF-8',
61 :path_encoding => '',
61 :path_encoding => '',
62 :url => '',
62 :url => '',
63 :root_url => REPOSITORY_PATH
63 :root_url => REPOSITORY_PATH
64 )
64 )
65 assert !repo.save
65 assert !repo.save
66 assert_include str, repo.errors.full_messages
66 assert_include str, repo.errors.full_messages
67 end
67 end
68
68
69 def test_blank_cvsroot_error_message
69 def test_blank_cvsroot_error_message
70 set_language_if_valid 'en'
70 set_language_if_valid 'en'
71 repo = Repository::Cvs.new(
71 repo = Repository::Cvs.new(
72 :project => @project,
72 :project => @project,
73 :identifier => 'test',
73 :identifier => 'test',
74 :log_encoding => 'UTF-8',
74 :log_encoding => 'UTF-8',
75 :url => MODULE_NAME
75 :url => MODULE_NAME
76 )
76 )
77 assert !repo.save
77 assert !repo.save
78 assert_include "CVSROOT can't be blank",
78 assert_include "CVSROOT can't be blank",
79 repo.errors.full_messages
79 repo.errors.full_messages
80 end
80 end
81
81
82 def test_blank_cvsroot_error_message_fr
82 def test_blank_cvsroot_error_message_fr
83 set_language_if_valid 'fr'
83 set_language_if_valid 'fr'
84 str = "CVSROOT doit \xc3\xaatre renseign\xc3\xa9(e)"
84 str = "CVSROOT doit \xc3\xaatre renseign\xc3\xa9(e)"
85 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
85 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
86 repo = Repository::Cvs.new(
86 repo = Repository::Cvs.new(
87 :project => @project,
87 :project => @project,
88 :identifier => 'test',
88 :identifier => 'test',
89 :log_encoding => 'UTF-8',
89 :log_encoding => 'UTF-8',
90 :path_encoding => '',
90 :path_encoding => '',
91 :url => MODULE_NAME,
91 :url => MODULE_NAME,
92 :root_url => ''
92 :root_url => ''
93 )
93 )
94 assert !repo.save
94 assert !repo.save
95 assert_include str, repo.errors.full_messages
95 assert_include str, repo.errors.full_messages
96 end
96 end
97
97
98 if File.directory?(REPOSITORY_PATH)
98 if File.directory?(REPOSITORY_PATH)
99 def test_fetch_changesets_from_scratch
99 def test_fetch_changesets_from_scratch
100 assert_equal 0, @repository.changesets.count
100 assert_equal 0, @repository.changesets.count
101 @repository.fetch_changesets
101 @repository.fetch_changesets
102 @project.reload
102 @project.reload
103
103
104 assert_equal CHANGESETS_NUM, @repository.changesets.count
104 assert_equal CHANGESETS_NUM, @repository.changesets.count
105 assert_equal 16, @repository.changes.count
105 assert_equal 16, @repository.changes.count
106 assert_not_nil @repository.changesets.find_by_comments('Two files changed')
106 assert_not_nil @repository.changesets.find_by_comments('Two files changed')
107
107
108 r2 = @repository.changesets.find_by_revision('2')
108 r2 = @repository.changesets.find_by_revision('2')
109 assert_equal 'v1-20071213-162510', r2.scmid
109 assert_equal 'v1-20071213-162510', r2.scmid
110 end
110 end
111
111
112 def test_fetch_changesets_incremental
112 def test_fetch_changesets_incremental
113 assert_equal 0, @repository.changesets.count
113 assert_equal 0, @repository.changesets.count
114 @repository.fetch_changesets
114 @repository.fetch_changesets
115 @project.reload
116 assert_equal CHANGESETS_NUM, @repository.changesets.count
117
115 # Remove changesets with revision > 3
118 # Remove changesets with revision > 3
116 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 3}
119 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 3}
117 @repository.reload
120 @project.reload
118 assert_equal 3, @repository.changesets.count
121 assert_equal 3, @repository.changesets.count
119 assert_equal %w|3 2 1|, @repository.changesets.collect(&:revision)
122 assert_equal %w|3 2 1|, @repository.changesets.all.collect(&:revision)
120
123
121 rev3_commit = @repository.changesets.find(:first, :order => 'committed_on DESC')
124 rev3_commit = @repository.changesets.find(:first, :order => 'committed_on DESC')
122 assert_equal '3', rev3_commit.revision
125 assert_equal '3', rev3_commit.revision
123 # 2007-12-14 01:27:22 +0900
126 # 2007-12-14 01:27:22 +0900
124 rev3_committed_on = Time.gm(2007, 12, 13, 16, 27, 22)
127 rev3_committed_on = Time.gm(2007, 12, 13, 16, 27, 22)
125 assert_equal 'HEAD-20071213-162722', rev3_commit.scmid
128 assert_equal 'HEAD-20071213-162722', rev3_commit.scmid
126 assert_equal rev3_committed_on, rev3_commit.committed_on
129 assert_equal rev3_committed_on, rev3_commit.committed_on
127 latest_rev = @repository.latest_changeset
130 latest_rev = @repository.latest_changeset
128 assert_equal rev3_committed_on, latest_rev.committed_on
131 assert_equal rev3_committed_on, latest_rev.committed_on
129
132
130 @repository.fetch_changesets
133 @repository.fetch_changesets
131 @repository.reload
134 @project.reload
132 assert_equal CHANGESETS_NUM, @repository.changesets.count
135 assert_equal CHANGESETS_NUM, @repository.changesets.count
133
136 assert_equal %w|7 6 5 4 3 2 1|, @repository.changesets.all.collect(&:revision)
134 assert_equal %w|7 6 5 4 3 2 1|, @repository.changesets.collect(&:revision)
135 rev5_commit = @repository.changesets.find_by_revision('5')
137 rev5_commit = @repository.changesets.find_by_revision('5')
136 assert_equal 'HEAD-20071213-163001', rev5_commit.scmid
138 assert_equal 'HEAD-20071213-163001', rev5_commit.scmid
137 # 2007-12-14 01:30:01 +0900
139 # 2007-12-14 01:30:01 +0900
138 rev5_committed_on = Time.gm(2007, 12, 13, 16, 30, 1)
140 rev5_committed_on = Time.gm(2007, 12, 13, 16, 30, 1)
139 assert_equal rev5_committed_on, rev5_commit.committed_on
141 assert_equal rev5_committed_on, rev5_commit.committed_on
140 end
142 end
141
143
142 def test_deleted_files_should_not_be_listed
144 def test_deleted_files_should_not_be_listed
143 assert_equal 0, @repository.changesets.count
145 assert_equal 0, @repository.changesets.count
144 @repository.fetch_changesets
146 @repository.fetch_changesets
145 @project.reload
147 @project.reload
146 assert_equal CHANGESETS_NUM, @repository.changesets.count
148 assert_equal CHANGESETS_NUM, @repository.changesets.count
147
149
148 entries = @repository.entries('sources')
150 entries = @repository.entries('sources')
149 assert entries.detect {|e| e.name == 'watchers_controller.rb'}
151 assert entries.detect {|e| e.name == 'watchers_controller.rb'}
150 assert_nil entries.detect {|e| e.name == 'welcome_controller.rb'}
152 assert_nil entries.detect {|e| e.name == 'welcome_controller.rb'}
151 end
153 end
152
154
153 def test_entries_rev3
155 def test_entries_rev3
154 assert_equal 0, @repository.changesets.count
156 assert_equal 0, @repository.changesets.count
155 @repository.fetch_changesets
157 @repository.fetch_changesets
156 @project.reload
158 @project.reload
157 assert_equal CHANGESETS_NUM, @repository.changesets.count
159 assert_equal CHANGESETS_NUM, @repository.changesets.count
158 entries = @repository.entries('', '3')
160 entries = @repository.entries('', '3')
159 assert_equal 3, entries.size
161 assert_equal 3, entries.size
160 assert_equal entries[2].name, "README"
162 assert_equal entries[2].name, "README"
161 assert_equal entries[2].lastrev.time, Time.gm(2007, 12, 13, 16, 27, 22)
163 assert_equal entries[2].lastrev.time, Time.gm(2007, 12, 13, 16, 27, 22)
162 assert_equal entries[2].lastrev.identifier, '3'
164 assert_equal entries[2].lastrev.identifier, '3'
163 assert_equal entries[2].lastrev.revision, '3'
165 assert_equal entries[2].lastrev.revision, '3'
164 assert_equal entries[2].lastrev.author, 'LANG'
166 assert_equal entries[2].lastrev.author, 'LANG'
165 end
167 end
166
168
167 def test_entries_invalid_path
169 def test_entries_invalid_path
168 assert_equal 0, @repository.changesets.count
170 assert_equal 0, @repository.changesets.count
169 @repository.fetch_changesets
171 @repository.fetch_changesets
170 @project.reload
172 @project.reload
171 assert_equal CHANGESETS_NUM, @repository.changesets.count
173 assert_equal CHANGESETS_NUM, @repository.changesets.count
172 assert_nil @repository.entries('missing')
174 assert_nil @repository.entries('missing')
173 assert_nil @repository.entries('missing', '3')
175 assert_nil @repository.entries('missing', '3')
174 end
176 end
175
177
176 def test_entries_invalid_revision
178 def test_entries_invalid_revision
177 assert_equal 0, @repository.changesets.count
179 assert_equal 0, @repository.changesets.count
178 @repository.fetch_changesets
180 @repository.fetch_changesets
179 @project.reload
181 @project.reload
180 assert_equal CHANGESETS_NUM, @repository.changesets.count
182 assert_equal CHANGESETS_NUM, @repository.changesets.count
181 assert_nil @repository.entries('', '123')
183 assert_nil @repository.entries('', '123')
182 end
184 end
183
185
184 def test_cat
186 def test_cat
185 assert_equal 0, @repository.changesets.count
187 assert_equal 0, @repository.changesets.count
186 @repository.fetch_changesets
188 @repository.fetch_changesets
187 @project.reload
189 @project.reload
188 assert_equal CHANGESETS_NUM, @repository.changesets.count
190 assert_equal CHANGESETS_NUM, @repository.changesets.count
189 buf = @repository.cat('README')
191 buf = @repository.cat('README')
190 assert buf
192 assert buf
191 lines = buf.split("\n")
193 lines = buf.split("\n")
192 assert_equal 3, lines.length
194 assert_equal 3, lines.length
193 buf = lines[1].gsub(/\r$/, "")
195 buf = lines[1].gsub(/\r$/, "")
194 assert_equal 'with one change', buf
196 assert_equal 'with one change', buf
195 buf = @repository.cat('README', '1')
197 buf = @repository.cat('README', '1')
196 assert buf
198 assert buf
197 lines = buf.split("\n")
199 lines = buf.split("\n")
198 assert_equal 1, lines.length
200 assert_equal 1, lines.length
199 buf = lines[0].gsub(/\r$/, "")
201 buf = lines[0].gsub(/\r$/, "")
200 assert_equal 'CVS test repository', buf
202 assert_equal 'CVS test repository', buf
201 assert_nil @repository.cat('missing.rb')
203 assert_nil @repository.cat('missing.rb')
202
204
203 # sources/welcome_controller.rb is removed at revision 5.
205 # sources/welcome_controller.rb is removed at revision 5.
204 assert @repository.cat('sources/welcome_controller.rb', '4')
206 assert @repository.cat('sources/welcome_controller.rb', '4')
205 assert @repository.cat('sources/welcome_controller.rb', '5').blank?
207 assert @repository.cat('sources/welcome_controller.rb', '5').blank?
206
208
207 # invalid revision
209 # invalid revision
208 assert @repository.cat('README', '123').blank?
210 assert @repository.cat('README', '123').blank?
209 end
211 end
210
212
211 def test_annotate
213 def test_annotate
212 assert_equal 0, @repository.changesets.count
214 assert_equal 0, @repository.changesets.count
213 @repository.fetch_changesets
215 @repository.fetch_changesets
214 @project.reload
216 @project.reload
215 assert_equal CHANGESETS_NUM, @repository.changesets.count
217 assert_equal CHANGESETS_NUM, @repository.changesets.count
216 ann = @repository.annotate('README')
218 ann = @repository.annotate('README')
217 assert ann
219 assert ann
218 assert_equal 3, ann.revisions.length
220 assert_equal 3, ann.revisions.length
219 assert_equal '1.2', ann.revisions[1].revision
221 assert_equal '1.2', ann.revisions[1].revision
220 assert_equal 'LANG', ann.revisions[1].author
222 assert_equal 'LANG', ann.revisions[1].author
221 assert_equal 'with one change', ann.lines[1]
223 assert_equal 'with one change', ann.lines[1]
222
224
223 ann = @repository.annotate('README', '1')
225 ann = @repository.annotate('README', '1')
224 assert ann
226 assert ann
225 assert_equal 1, ann.revisions.length
227 assert_equal 1, ann.revisions.length
226 assert_equal '1.1', ann.revisions[0].revision
228 assert_equal '1.1', ann.revisions[0].revision
227 assert_equal 'LANG', ann.revisions[0].author
229 assert_equal 'LANG', ann.revisions[0].author
228 assert_equal 'CVS test repository', ann.lines[0]
230 assert_equal 'CVS test repository', ann.lines[0]
229
231
230 # invalid revision
232 # invalid revision
231 assert_nil @repository.annotate('README', '123')
233 assert_nil @repository.annotate('README', '123')
232 end
234 end
233
235
234 else
236 else
235 puts "CVS test repository NOT FOUND. Skipping unit tests !!!"
237 puts "CVS test repository NOT FOUND. Skipping unit tests !!!"
236 def test_fake; assert true end
238 def test_fake; assert true end
237 end
239 end
238 end
240 end
General Comments 0
You need to be logged in to leave comments. Login now