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