##// END OF EJS Templates
Rails4: scm: reload repository after destroying changesets in incremental fetch test...
Toshi MARUYAMA -
r12197:9cefc90b0be4
parent child
Show More
@@ -1,306 +1,307
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
2 # Copyright (C) 2006-2013 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
19
20 class RepositoryBazaarTest < ActiveSupport::TestCase
20 class RepositoryBazaarTest < 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/bazaar_repository').to_s
25 REPOSITORY_PATH = Rails.root.join('tmp/test/bazaar_repository').to_s
26 REPOSITORY_PATH_TRUNK = File.join(REPOSITORY_PATH, "trunk")
26 REPOSITORY_PATH_TRUNK = File.join(REPOSITORY_PATH, "trunk")
27 NUM_REV = 4
27 NUM_REV = 4
28
28
29 REPOSITORY_PATH_NON_ASCII = Rails.root.join(REPOSITORY_PATH + '/' + 'non_ascii').to_s
29 REPOSITORY_PATH_NON_ASCII = Rails.root.join(REPOSITORY_PATH + '/' + 'non_ascii').to_s
30
30
31 # Bazaar core does not support xml output such as Subversion and Mercurial.
31 # Bazaar core does not support xml output such as Subversion and Mercurial.
32 # "bzr" command output and command line parameter depend on locale.
32 # "bzr" command output and command line parameter depend on locale.
33 # So, non ASCII path tests cannot run independent locale.
33 # So, non ASCII path tests cannot run independent locale.
34 #
34 #
35 # If you want to run Bazaar non ASCII path tests on Linux *Ruby 1.9*,
35 # If you want to run Bazaar non ASCII path tests on Linux *Ruby 1.9*,
36 # you need to set locale character set "ISO-8859-1".
36 # you need to set locale character set "ISO-8859-1".
37 # E.g. "LANG=en_US.ISO-8859-1".
37 # E.g. "LANG=en_US.ISO-8859-1".
38 # On Linux other platforms (e.g. Ruby 1.8, JRuby),
38 # On Linux other platforms (e.g. Ruby 1.8, JRuby),
39 # you need to set "RUN_LATIN1_OUTPUT_TEST = true" manually.
39 # you need to set "RUN_LATIN1_OUTPUT_TEST = true" manually.
40 #
40 #
41 # On Windows, because it is too hard to change system locale,
41 # On Windows, because it is too hard to change system locale,
42 # you cannot run Bazaar non ASCII path tests.
42 # you cannot run Bazaar non ASCII path tests.
43 #
43 #
44 RUN_LATIN1_OUTPUT_TEST = (RUBY_PLATFORM != 'java' &&
44 RUN_LATIN1_OUTPUT_TEST = (RUBY_PLATFORM != 'java' &&
45 REPOSITORY_PATH.respond_to?(:force_encoding) &&
45 REPOSITORY_PATH.respond_to?(:force_encoding) &&
46 Encoding.locale_charmap == "ISO-8859-1")
46 Encoding.locale_charmap == "ISO-8859-1")
47
47
48 CHAR_1_UTF8_HEX = "\xc3\x9c"
48 CHAR_1_UTF8_HEX = "\xc3\x9c"
49 CHAR_1_LATIN1_HEX = "\xdc"
49 CHAR_1_LATIN1_HEX = "\xdc"
50
50
51 def setup
51 def setup
52 @project = Project.find(3)
52 @project = Project.find(3)
53 @repository = Repository::Bazaar.create(
53 @repository = Repository::Bazaar.create(
54 :project => @project, :url => REPOSITORY_PATH_TRUNK,
54 :project => @project, :url => REPOSITORY_PATH_TRUNK,
55 :log_encoding => 'UTF-8')
55 :log_encoding => 'UTF-8')
56 assert @repository
56 assert @repository
57 @char_1_utf8 = CHAR_1_UTF8_HEX.dup
57 @char_1_utf8 = CHAR_1_UTF8_HEX.dup
58 @char_1_ascii8bit = CHAR_1_LATIN1_HEX.dup
58 @char_1_ascii8bit = CHAR_1_LATIN1_HEX.dup
59 if @char_1_utf8.respond_to?(:force_encoding)
59 if @char_1_utf8.respond_to?(:force_encoding)
60 @char_1_utf8.force_encoding('UTF-8')
60 @char_1_utf8.force_encoding('UTF-8')
61 @char_1_ascii8bit.force_encoding('ASCII-8BIT')
61 @char_1_ascii8bit.force_encoding('ASCII-8BIT')
62 end
62 end
63 end
63 end
64
64
65 def test_blank_path_to_repository_error_message
65 def test_blank_path_to_repository_error_message
66 set_language_if_valid 'en'
66 set_language_if_valid 'en'
67 repo = Repository::Bazaar.new(
67 repo = Repository::Bazaar.new(
68 :project => @project,
68 :project => @project,
69 :identifier => 'test',
69 :identifier => 'test',
70 :log_encoding => 'UTF-8'
70 :log_encoding => 'UTF-8'
71 )
71 )
72 assert !repo.save
72 assert !repo.save
73 assert_include "Path to repository can't be blank",
73 assert_include "Path to repository can't be blank",
74 repo.errors.full_messages
74 repo.errors.full_messages
75 end
75 end
76
76
77 def test_blank_path_to_repository_error_message_fr
77 def test_blank_path_to_repository_error_message_fr
78 set_language_if_valid 'fr'
78 set_language_if_valid 'fr'
79 str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)"
79 str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)"
80 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
80 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
81 repo = Repository::Bazaar.new(
81 repo = Repository::Bazaar.new(
82 :project => @project,
82 :project => @project,
83 :url => "",
83 :url => "",
84 :identifier => 'test',
84 :identifier => 'test',
85 :log_encoding => 'UTF-8'
85 :log_encoding => 'UTF-8'
86 )
86 )
87 assert !repo.save
87 assert !repo.save
88 assert_include str, repo.errors.full_messages
88 assert_include str, repo.errors.full_messages
89 end
89 end
90
90
91 if File.directory?(REPOSITORY_PATH_TRUNK)
91 if File.directory?(REPOSITORY_PATH_TRUNK)
92 def test_fetch_changesets_from_scratch
92 def test_fetch_changesets_from_scratch
93 assert_equal 0, @repository.changesets.count
93 assert_equal 0, @repository.changesets.count
94 @repository.fetch_changesets
94 @repository.fetch_changesets
95 @project.reload
95 @project.reload
96
96
97 assert_equal NUM_REV, @repository.changesets.count
97 assert_equal NUM_REV, @repository.changesets.count
98 assert_equal 9, @repository.filechanges.count
98 assert_equal 9, @repository.filechanges.count
99 assert_equal 'Initial import', @repository.changesets.find_by_revision('1').comments
99 assert_equal 'Initial import', @repository.changesets.find_by_revision('1').comments
100 end
100 end
101
101
102 def test_fetch_changesets_incremental
102 def test_fetch_changesets_incremental
103 assert_equal 0, @repository.changesets.count
103 assert_equal 0, @repository.changesets.count
104 @repository.fetch_changesets
104 @repository.fetch_changesets
105 @project.reload
105 @project.reload
106 assert_equal NUM_REV, @repository.changesets.count
106 assert_equal NUM_REV, @repository.changesets.count
107 # Remove changesets with revision > 5
107 # Remove changesets with revision > 5
108 @repository.changesets.all.each {|c| c.destroy if c.revision.to_i > 2}
108 @repository.changesets.all.each {|c| c.destroy if c.revision.to_i > 2}
109 @project.reload
109 @project.reload
110 @repository.reload
110 assert_equal 2, @repository.changesets.count
111 assert_equal 2, @repository.changesets.count
111
112
112 @repository.fetch_changesets
113 @repository.fetch_changesets
113 @project.reload
114 @project.reload
114 assert_equal NUM_REV, @repository.changesets.count
115 assert_equal NUM_REV, @repository.changesets.count
115 end
116 end
116
117
117 def test_entries
118 def test_entries
118 entries = @repository.entries
119 entries = @repository.entries
119 assert_kind_of Redmine::Scm::Adapters::Entries, entries
120 assert_kind_of Redmine::Scm::Adapters::Entries, entries
120 assert_equal 2, entries.size
121 assert_equal 2, entries.size
121
122
122 assert_equal 'dir', entries[0].kind
123 assert_equal 'dir', entries[0].kind
123 assert_equal 'directory', entries[0].name
124 assert_equal 'directory', entries[0].name
124 assert_equal 'directory', entries[0].path
125 assert_equal 'directory', entries[0].path
125
126
126 assert_equal 'file', entries[1].kind
127 assert_equal 'file', entries[1].kind
127 assert_equal 'doc-mkdir.txt', entries[1].name
128 assert_equal 'doc-mkdir.txt', entries[1].name
128 assert_equal 'doc-mkdir.txt', entries[1].path
129 assert_equal 'doc-mkdir.txt', entries[1].path
129 end
130 end
130
131
131 def test_entries_in_subdirectory
132 def test_entries_in_subdirectory
132 entries = @repository.entries('directory')
133 entries = @repository.entries('directory')
133 assert_equal 3, entries.size
134 assert_equal 3, entries.size
134
135
135 assert_equal 'file', entries.last.kind
136 assert_equal 'file', entries.last.kind
136 assert_equal 'edit.png', entries.last.name
137 assert_equal 'edit.png', entries.last.name
137 assert_equal 'directory/edit.png', entries.last.path
138 assert_equal 'directory/edit.png', entries.last.path
138 end
139 end
139
140
140 def test_previous
141 def test_previous
141 assert_equal 0, @repository.changesets.count
142 assert_equal 0, @repository.changesets.count
142 @repository.fetch_changesets
143 @repository.fetch_changesets
143 @project.reload
144 @project.reload
144 assert_equal NUM_REV, @repository.changesets.count
145 assert_equal NUM_REV, @repository.changesets.count
145 changeset = @repository.find_changeset_by_name('3')
146 changeset = @repository.find_changeset_by_name('3')
146 assert_equal @repository.find_changeset_by_name('2'), changeset.previous
147 assert_equal @repository.find_changeset_by_name('2'), changeset.previous
147 end
148 end
148
149
149 def test_previous_nil
150 def test_previous_nil
150 assert_equal 0, @repository.changesets.count
151 assert_equal 0, @repository.changesets.count
151 @repository.fetch_changesets
152 @repository.fetch_changesets
152 @project.reload
153 @project.reload
153 assert_equal NUM_REV, @repository.changesets.count
154 assert_equal NUM_REV, @repository.changesets.count
154 changeset = @repository.find_changeset_by_name('1')
155 changeset = @repository.find_changeset_by_name('1')
155 assert_nil changeset.previous
156 assert_nil changeset.previous
156 end
157 end
157
158
158 def test_next
159 def test_next
159 assert_equal 0, @repository.changesets.count
160 assert_equal 0, @repository.changesets.count
160 @repository.fetch_changesets
161 @repository.fetch_changesets
161 @project.reload
162 @project.reload
162 assert_equal NUM_REV, @repository.changesets.count
163 assert_equal NUM_REV, @repository.changesets.count
163 changeset = @repository.find_changeset_by_name('2')
164 changeset = @repository.find_changeset_by_name('2')
164 assert_equal @repository.find_changeset_by_name('3'), changeset.next
165 assert_equal @repository.find_changeset_by_name('3'), changeset.next
165 end
166 end
166
167
167 def test_next_nil
168 def test_next_nil
168 assert_equal 0, @repository.changesets.count
169 assert_equal 0, @repository.changesets.count
169 @repository.fetch_changesets
170 @repository.fetch_changesets
170 @project.reload
171 @project.reload
171 assert_equal NUM_REV, @repository.changesets.count
172 assert_equal NUM_REV, @repository.changesets.count
172 changeset = @repository.find_changeset_by_name('4')
173 changeset = @repository.find_changeset_by_name('4')
173 assert_nil changeset.next
174 assert_nil changeset.next
174 end
175 end
175
176
176 if File.directory?(REPOSITORY_PATH_NON_ASCII) && RUN_LATIN1_OUTPUT_TEST
177 if File.directory?(REPOSITORY_PATH_NON_ASCII) && RUN_LATIN1_OUTPUT_TEST
177 def test_cat_latin1_path
178 def test_cat_latin1_path
178 latin1_repo = create_latin1_repo
179 latin1_repo = create_latin1_repo
179 buf = latin1_repo.cat(
180 buf = latin1_repo.cat(
180 "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-2.txt", 2)
181 "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-2.txt", 2)
181 assert buf
182 assert buf
182 lines = buf.split("\n")
183 lines = buf.split("\n")
183 assert_equal 2, lines.length
184 assert_equal 2, lines.length
184 assert_equal 'It is written in Python.', lines[1]
185 assert_equal 'It is written in Python.', lines[1]
185
186
186 buf = latin1_repo.cat(
187 buf = latin1_repo.cat(
187 "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt", 2)
188 "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt", 2)
188 assert buf
189 assert buf
189 lines = buf.split("\n")
190 lines = buf.split("\n")
190 assert_equal 1, lines.length
191 assert_equal 1, lines.length
191 assert_equal "test-#{@char_1_ascii8bit}.txt", lines[0]
192 assert_equal "test-#{@char_1_ascii8bit}.txt", lines[0]
192 end
193 end
193
194
194 def test_annotate_latin1_path
195 def test_annotate_latin1_path
195 latin1_repo = create_latin1_repo
196 latin1_repo = create_latin1_repo
196 ann1 = latin1_repo.annotate(
197 ann1 = latin1_repo.annotate(
197 "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-2.txt", 2)
198 "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-2.txt", 2)
198 assert_equal 2, ann1.lines.size
199 assert_equal 2, ann1.lines.size
199 assert_equal '2', ann1.revisions[0].identifier
200 assert_equal '2', ann1.revisions[0].identifier
200 assert_equal 'test00@', ann1.revisions[0].author
201 assert_equal 'test00@', ann1.revisions[0].author
201 assert_equal 'It is written in Python.', ann1.lines[1]
202 assert_equal 'It is written in Python.', ann1.lines[1]
202 ann2 = latin1_repo.annotate(
203 ann2 = latin1_repo.annotate(
203 "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt", 2)
204 "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt", 2)
204 assert_equal 1, ann2.lines.size
205 assert_equal 1, ann2.lines.size
205 assert_equal '2', ann2.revisions[0].identifier
206 assert_equal '2', ann2.revisions[0].identifier
206 assert_equal 'test00@', ann2.revisions[0].author
207 assert_equal 'test00@', ann2.revisions[0].author
207 assert_equal "test-#{@char_1_ascii8bit}.txt", ann2.lines[0]
208 assert_equal "test-#{@char_1_ascii8bit}.txt", ann2.lines[0]
208 end
209 end
209
210
210 def test_diff_latin1_path
211 def test_diff_latin1_path
211 latin1_repo = create_latin1_repo
212 latin1_repo = create_latin1_repo
212 diff1 = latin1_repo.diff(
213 diff1 = latin1_repo.diff(
213 "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt", 2, 1)
214 "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt", 2, 1)
214 assert_equal 7, diff1.size
215 assert_equal 7, diff1.size
215 buf = diff1[5].gsub(/\r\n|\r|\n/, "")
216 buf = diff1[5].gsub(/\r\n|\r|\n/, "")
216 assert_equal "+test-#{@char_1_ascii8bit}.txt", buf
217 assert_equal "+test-#{@char_1_ascii8bit}.txt", buf
217 end
218 end
218
219
219 def test_entries_latin1_path
220 def test_entries_latin1_path
220 latin1_repo = create_latin1_repo
221 latin1_repo = create_latin1_repo
221 entries = latin1_repo.entries("test-#{@char_1_utf8}-dir", 2)
222 entries = latin1_repo.entries("test-#{@char_1_utf8}-dir", 2)
222 assert_kind_of Redmine::Scm::Adapters::Entries, entries
223 assert_kind_of Redmine::Scm::Adapters::Entries, entries
223 assert_equal 3, entries.size
224 assert_equal 3, entries.size
224 assert_equal 'file', entries[1].kind
225 assert_equal 'file', entries[1].kind
225 assert_equal "test-#{@char_1_utf8}-1.txt", entries[0].name
226 assert_equal "test-#{@char_1_utf8}-1.txt", entries[0].name
226 assert_equal "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt", entries[0].path
227 assert_equal "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt", entries[0].path
227 end
228 end
228
229
229 def test_entry_latin1_path
230 def test_entry_latin1_path
230 latin1_repo = create_latin1_repo
231 latin1_repo = create_latin1_repo
231 ["test-#{@char_1_utf8}-dir",
232 ["test-#{@char_1_utf8}-dir",
232 "/test-#{@char_1_utf8}-dir",
233 "/test-#{@char_1_utf8}-dir",
233 "/test-#{@char_1_utf8}-dir/"
234 "/test-#{@char_1_utf8}-dir/"
234 ].each do |path|
235 ].each do |path|
235 entry = latin1_repo.entry(path, 2)
236 entry = latin1_repo.entry(path, 2)
236 assert_equal "test-#{@char_1_utf8}-dir", entry.path
237 assert_equal "test-#{@char_1_utf8}-dir", entry.path
237 assert_equal "dir", entry.kind
238 assert_equal "dir", entry.kind
238 end
239 end
239 ["test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt",
240 ["test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt",
240 "/test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt"
241 "/test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt"
241 ].each do |path|
242 ].each do |path|
242 entry = latin1_repo.entry(path, 2)
243 entry = latin1_repo.entry(path, 2)
243 assert_equal "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt",
244 assert_equal "test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt",
244 entry.path
245 entry.path
245 assert_equal "file", entry.kind
246 assert_equal "file", entry.kind
246 end
247 end
247 end
248 end
248
249
249 def test_changeset_latin1_path
250 def test_changeset_latin1_path
250 latin1_repo = create_latin1_repo
251 latin1_repo = create_latin1_repo
251 assert_equal 0, latin1_repo.changesets.count
252 assert_equal 0, latin1_repo.changesets.count
252 latin1_repo.fetch_changesets
253 latin1_repo.fetch_changesets
253 @project.reload
254 @project.reload
254 assert_equal 3, latin1_repo.changesets.count
255 assert_equal 3, latin1_repo.changesets.count
255
256
256 cs2 = latin1_repo.changesets.find_by_revision('2')
257 cs2 = latin1_repo.changesets.find_by_revision('2')
257 assert_not_nil cs2
258 assert_not_nil cs2
258 assert_equal "test-#{@char_1_utf8}", cs2.comments
259 assert_equal "test-#{@char_1_utf8}", cs2.comments
259 c2 = cs2.filechanges.sort_by(&:path)
260 c2 = cs2.filechanges.sort_by(&:path)
260 assert_equal 4, c2.size
261 assert_equal 4, c2.size
261 assert_equal 'A', c2[0].action
262 assert_equal 'A', c2[0].action
262 assert_equal "/test-#{@char_1_utf8}-dir/", c2[0].path
263 assert_equal "/test-#{@char_1_utf8}-dir/", c2[0].path
263 assert_equal 'A', c2[1].action
264 assert_equal 'A', c2[1].action
264 assert_equal "/test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt", c2[1].path
265 assert_equal "/test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-1.txt", c2[1].path
265 assert_equal 'A', c2[2].action
266 assert_equal 'A', c2[2].action
266 assert_equal "/test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-2.txt", c2[2].path
267 assert_equal "/test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-2.txt", c2[2].path
267 assert_equal 'A', c2[3].action
268 assert_equal 'A', c2[3].action
268 assert_equal "/test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}.txt", c2[3].path
269 assert_equal "/test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}.txt", c2[3].path
269
270
270 cs3 = latin1_repo.changesets.find_by_revision('3')
271 cs3 = latin1_repo.changesets.find_by_revision('3')
271 assert_not_nil cs3
272 assert_not_nil cs3
272 assert_equal "modify, move and delete #{@char_1_utf8} files", cs3.comments
273 assert_equal "modify, move and delete #{@char_1_utf8} files", cs3.comments
273 c3 = cs3.filechanges.sort_by(&:path)
274 c3 = cs3.filechanges.sort_by(&:path)
274 assert_equal 3, c3.size
275 assert_equal 3, c3.size
275 assert_equal 'M', c3[0].action
276 assert_equal 'M', c3[0].action
276 assert_equal "/test-#{@char_1_utf8}-1.txt", c3[0].path
277 assert_equal "/test-#{@char_1_utf8}-1.txt", c3[0].path
277 assert_equal 'D', c3[1].action
278 assert_equal 'D', c3[1].action
278 assert_equal "/test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-2.txt", c3[1].path
279 assert_equal "/test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}-2.txt", c3[1].path
279 assert_equal 'M', c3[2].action
280 assert_equal 'M', c3[2].action
280 assert_equal "/test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}.txt", c3[2].path
281 assert_equal "/test-#{@char_1_utf8}-dir/test-#{@char_1_utf8}.txt", c3[2].path
281 end
282 end
282 else
283 else
283 msg = "Bazaar non ASCII output test cannot run this environment." + "\n"
284 msg = "Bazaar non ASCII output test cannot run this environment." + "\n"
284 if msg.respond_to?(:force_encoding)
285 if msg.respond_to?(:force_encoding)
285 msg += "Encoding.locale_charmap: " + Encoding.locale_charmap + "\n"
286 msg += "Encoding.locale_charmap: " + Encoding.locale_charmap + "\n"
286 end
287 end
287 puts msg
288 puts msg
288 end
289 end
289
290
290 private
291 private
291
292
292 def create_latin1_repo
293 def create_latin1_repo
293 repo = Repository::Bazaar.create(
294 repo = Repository::Bazaar.create(
294 :project => @project,
295 :project => @project,
295 :identifier => 'latin1',
296 :identifier => 'latin1',
296 :url => REPOSITORY_PATH_NON_ASCII,
297 :url => REPOSITORY_PATH_NON_ASCII,
297 :log_encoding => 'ISO-8859-1'
298 :log_encoding => 'ISO-8859-1'
298 )
299 )
299 assert repo
300 assert repo
300 repo
301 repo
301 end
302 end
302 else
303 else
303 puts "Bazaar test repository NOT FOUND. Skipping unit tests !!!"
304 puts "Bazaar test repository NOT FOUND. Skipping unit tests !!!"
304 def test_fake; assert true end
305 def test_fake; assert true end
305 end
306 end
306 end
307 end
@@ -1,241 +1,242
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
2 # Copyright (C) 2006-2013 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.filechanges.count
105 assert_equal 16, @repository.filechanges.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
115 @project.reload
116 assert_equal CHANGESETS_NUM, @repository.changesets.count
116 assert_equal CHANGESETS_NUM, @repository.changesets.count
117
117
118 # Remove changesets with revision > 3
118 # Remove changesets with revision > 3
119 @repository.changesets.all.each {|c| c.destroy if c.revision.to_i > 3}
119 @repository.changesets.all.each {|c| c.destroy if c.revision.to_i > 3}
120 @project.reload
120 @project.reload
121 @repository.reload
121 assert_equal 3, @repository.changesets.count
122 assert_equal 3, @repository.changesets.count
122 assert_equal %w|3 2 1|, @repository.changesets.all.collect(&:revision)
123 assert_equal %w|3 2 1|, @repository.changesets.all.collect(&:revision)
123
124
124 rev3_commit = @repository.changesets.reorder('committed_on DESC').first
125 rev3_commit = @repository.changesets.reorder('committed_on DESC').first
125 assert_equal '3', rev3_commit.revision
126 assert_equal '3', rev3_commit.revision
126 # 2007-12-14 01:27:22 +0900
127 # 2007-12-14 01:27:22 +0900
127 rev3_committed_on = Time.gm(2007, 12, 13, 16, 27, 22)
128 rev3_committed_on = Time.gm(2007, 12, 13, 16, 27, 22)
128 assert_equal 'HEAD-20071213-162722', rev3_commit.scmid
129 assert_equal 'HEAD-20071213-162722', rev3_commit.scmid
129 assert_equal rev3_committed_on, rev3_commit.committed_on
130 assert_equal rev3_committed_on, rev3_commit.committed_on
130 latest_rev = @repository.latest_changeset
131 latest_rev = @repository.latest_changeset
131 assert_equal rev3_committed_on, latest_rev.committed_on
132 assert_equal rev3_committed_on, latest_rev.committed_on
132
133
133 @repository.fetch_changesets
134 @repository.fetch_changesets
134 @project.reload
135 @project.reload
135 assert_equal CHANGESETS_NUM, @repository.changesets.count
136 assert_equal CHANGESETS_NUM, @repository.changesets.count
136 assert_equal %w|7 6 5 4 3 2 1|, @repository.changesets.all.collect(&:revision)
137 assert_equal %w|7 6 5 4 3 2 1|, @repository.changesets.all.collect(&:revision)
137 rev5_commit = @repository.changesets.find_by_revision('5')
138 rev5_commit = @repository.changesets.find_by_revision('5')
138 assert_equal 'HEAD-20071213-163001', rev5_commit.scmid
139 assert_equal 'HEAD-20071213-163001', rev5_commit.scmid
139 # 2007-12-14 01:30:01 +0900
140 # 2007-12-14 01:30:01 +0900
140 rev5_committed_on = Time.gm(2007, 12, 13, 16, 30, 1)
141 rev5_committed_on = Time.gm(2007, 12, 13, 16, 30, 1)
141 assert_equal rev5_committed_on, rev5_commit.committed_on
142 assert_equal rev5_committed_on, rev5_commit.committed_on
142 end
143 end
143
144
144 def test_deleted_files_should_not_be_listed
145 def test_deleted_files_should_not_be_listed
145 assert_equal 0, @repository.changesets.count
146 assert_equal 0, @repository.changesets.count
146 @repository.fetch_changesets
147 @repository.fetch_changesets
147 @project.reload
148 @project.reload
148 assert_equal CHANGESETS_NUM, @repository.changesets.count
149 assert_equal CHANGESETS_NUM, @repository.changesets.count
149
150
150 entries = @repository.entries('sources')
151 entries = @repository.entries('sources')
151 assert entries.detect {|e| e.name == 'watchers_controller.rb'}
152 assert entries.detect {|e| e.name == 'watchers_controller.rb'}
152 assert_nil entries.detect {|e| e.name == 'welcome_controller.rb'}
153 assert_nil entries.detect {|e| e.name == 'welcome_controller.rb'}
153 end
154 end
154
155
155 def test_entries_rev3
156 def test_entries_rev3
156 assert_equal 0, @repository.changesets.count
157 assert_equal 0, @repository.changesets.count
157 @repository.fetch_changesets
158 @repository.fetch_changesets
158 @project.reload
159 @project.reload
159 assert_equal CHANGESETS_NUM, @repository.changesets.count
160 assert_equal CHANGESETS_NUM, @repository.changesets.count
160 entries = @repository.entries('', '3')
161 entries = @repository.entries('', '3')
161 assert_kind_of Redmine::Scm::Adapters::Entries, entries
162 assert_kind_of Redmine::Scm::Adapters::Entries, entries
162 assert_equal 3, entries.size
163 assert_equal 3, entries.size
163 assert_equal entries[2].name, "README"
164 assert_equal entries[2].name, "README"
164 assert_equal entries[2].lastrev.time, Time.gm(2007, 12, 13, 16, 27, 22)
165 assert_equal entries[2].lastrev.time, Time.gm(2007, 12, 13, 16, 27, 22)
165 assert_equal entries[2].lastrev.identifier, '3'
166 assert_equal entries[2].lastrev.identifier, '3'
166 assert_equal entries[2].lastrev.revision, '3'
167 assert_equal entries[2].lastrev.revision, '3'
167 assert_equal entries[2].lastrev.author, 'LANG'
168 assert_equal entries[2].lastrev.author, 'LANG'
168 end
169 end
169
170
170 def test_entries_invalid_path
171 def test_entries_invalid_path
171 assert_equal 0, @repository.changesets.count
172 assert_equal 0, @repository.changesets.count
172 @repository.fetch_changesets
173 @repository.fetch_changesets
173 @project.reload
174 @project.reload
174 assert_equal CHANGESETS_NUM, @repository.changesets.count
175 assert_equal CHANGESETS_NUM, @repository.changesets.count
175 assert_nil @repository.entries('missing')
176 assert_nil @repository.entries('missing')
176 assert_nil @repository.entries('missing', '3')
177 assert_nil @repository.entries('missing', '3')
177 end
178 end
178
179
179 def test_entries_invalid_revision
180 def test_entries_invalid_revision
180 assert_equal 0, @repository.changesets.count
181 assert_equal 0, @repository.changesets.count
181 @repository.fetch_changesets
182 @repository.fetch_changesets
182 @project.reload
183 @project.reload
183 assert_equal CHANGESETS_NUM, @repository.changesets.count
184 assert_equal CHANGESETS_NUM, @repository.changesets.count
184 assert_nil @repository.entries('', '123')
185 assert_nil @repository.entries('', '123')
185 end
186 end
186
187
187 def test_cat
188 def test_cat
188 assert_equal 0, @repository.changesets.count
189 assert_equal 0, @repository.changesets.count
189 @repository.fetch_changesets
190 @repository.fetch_changesets
190 @project.reload
191 @project.reload
191 assert_equal CHANGESETS_NUM, @repository.changesets.count
192 assert_equal CHANGESETS_NUM, @repository.changesets.count
192 buf = @repository.cat('README')
193 buf = @repository.cat('README')
193 assert buf
194 assert buf
194 lines = buf.split("\n")
195 lines = buf.split("\n")
195 assert_equal 3, lines.length
196 assert_equal 3, lines.length
196 buf = lines[1].gsub(/\r$/, "")
197 buf = lines[1].gsub(/\r$/, "")
197 assert_equal 'with one change', buf
198 assert_equal 'with one change', buf
198 buf = @repository.cat('README', '1')
199 buf = @repository.cat('README', '1')
199 assert buf
200 assert buf
200 lines = buf.split("\n")
201 lines = buf.split("\n")
201 assert_equal 1, lines.length
202 assert_equal 1, lines.length
202 buf = lines[0].gsub(/\r$/, "")
203 buf = lines[0].gsub(/\r$/, "")
203 assert_equal 'CVS test repository', buf
204 assert_equal 'CVS test repository', buf
204 assert_nil @repository.cat('missing.rb')
205 assert_nil @repository.cat('missing.rb')
205
206
206 # sources/welcome_controller.rb is removed at revision 5.
207 # sources/welcome_controller.rb is removed at revision 5.
207 assert @repository.cat('sources/welcome_controller.rb', '4')
208 assert @repository.cat('sources/welcome_controller.rb', '4')
208 assert @repository.cat('sources/welcome_controller.rb', '5').blank?
209 assert @repository.cat('sources/welcome_controller.rb', '5').blank?
209
210
210 # invalid revision
211 # invalid revision
211 assert @repository.cat('README', '123').blank?
212 assert @repository.cat('README', '123').blank?
212 end
213 end
213
214
214 def test_annotate
215 def test_annotate
215 assert_equal 0, @repository.changesets.count
216 assert_equal 0, @repository.changesets.count
216 @repository.fetch_changesets
217 @repository.fetch_changesets
217 @project.reload
218 @project.reload
218 assert_equal CHANGESETS_NUM, @repository.changesets.count
219 assert_equal CHANGESETS_NUM, @repository.changesets.count
219 ann = @repository.annotate('README')
220 ann = @repository.annotate('README')
220 assert ann
221 assert ann
221 assert_equal 3, ann.revisions.length
222 assert_equal 3, ann.revisions.length
222 assert_equal '1.2', ann.revisions[1].revision
223 assert_equal '1.2', ann.revisions[1].revision
223 assert_equal 'LANG', ann.revisions[1].author
224 assert_equal 'LANG', ann.revisions[1].author
224 assert_equal 'with one change', ann.lines[1]
225 assert_equal 'with one change', ann.lines[1]
225
226
226 ann = @repository.annotate('README', '1')
227 ann = @repository.annotate('README', '1')
227 assert ann
228 assert ann
228 assert_equal 1, ann.revisions.length
229 assert_equal 1, ann.revisions.length
229 assert_equal '1.1', ann.revisions[0].revision
230 assert_equal '1.1', ann.revisions[0].revision
230 assert_equal 'LANG', ann.revisions[0].author
231 assert_equal 'LANG', ann.revisions[0].author
231 assert_equal 'CVS test repository', ann.lines[0]
232 assert_equal 'CVS test repository', ann.lines[0]
232
233
233 # invalid revision
234 # invalid revision
234 assert_nil @repository.annotate('README', '123')
235 assert_nil @repository.annotate('README', '123')
235 end
236 end
236
237
237 else
238 else
238 puts "CVS test repository NOT FOUND. Skipping unit tests !!!"
239 puts "CVS test repository NOT FOUND. Skipping unit tests !!!"
239 def test_fake; assert true end
240 def test_fake; assert true end
240 end
241 end
241 end
242 end
@@ -1,129 +1,130
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
2 # Copyright (C) 2006-2013 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
19
20 class RepositoryDarcsTest < ActiveSupport::TestCase
20 class RepositoryDarcsTest < 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/darcs_repository').to_s
25 REPOSITORY_PATH = Rails.root.join('tmp/test/darcs_repository').to_s
26 NUM_REV = 6
26 NUM_REV = 6
27
27
28 def setup
28 def setup
29 @project = Project.find(3)
29 @project = Project.find(3)
30 @repository = Repository::Darcs.create(
30 @repository = Repository::Darcs.create(
31 :project => @project,
31 :project => @project,
32 :url => REPOSITORY_PATH,
32 :url => REPOSITORY_PATH,
33 :log_encoding => 'UTF-8'
33 :log_encoding => 'UTF-8'
34 )
34 )
35 assert @repository
35 assert @repository
36 end
36 end
37
37
38 def test_blank_path_to_repository_error_message
38 def test_blank_path_to_repository_error_message
39 set_language_if_valid 'en'
39 set_language_if_valid 'en'
40 repo = Repository::Darcs.new(
40 repo = Repository::Darcs.new(
41 :project => @project,
41 :project => @project,
42 :identifier => 'test',
42 :identifier => 'test',
43 :log_encoding => 'UTF-8'
43 :log_encoding => 'UTF-8'
44 )
44 )
45 assert !repo.save
45 assert !repo.save
46 assert_include "Path to repository can't be blank",
46 assert_include "Path to repository can't be blank",
47 repo.errors.full_messages
47 repo.errors.full_messages
48 end
48 end
49
49
50 def test_blank_path_to_repository_error_message_fr
50 def test_blank_path_to_repository_error_message_fr
51 set_language_if_valid 'fr'
51 set_language_if_valid 'fr'
52 str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)"
52 str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)"
53 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
53 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
54 repo = Repository::Darcs.new(
54 repo = Repository::Darcs.new(
55 :project => @project,
55 :project => @project,
56 :url => "",
56 :url => "",
57 :identifier => 'test',
57 :identifier => 'test',
58 :log_encoding => 'UTF-8'
58 :log_encoding => 'UTF-8'
59 )
59 )
60 assert !repo.save
60 assert !repo.save
61 assert_include str, repo.errors.full_messages
61 assert_include str, repo.errors.full_messages
62 end
62 end
63
63
64 if File.directory?(REPOSITORY_PATH)
64 if File.directory?(REPOSITORY_PATH)
65 def test_fetch_changesets_from_scratch
65 def test_fetch_changesets_from_scratch
66 assert_equal 0, @repository.changesets.count
66 assert_equal 0, @repository.changesets.count
67 @repository.fetch_changesets
67 @repository.fetch_changesets
68 @project.reload
68 @project.reload
69
69
70 assert_equal NUM_REV, @repository.changesets.count
70 assert_equal NUM_REV, @repository.changesets.count
71 assert_equal 13, @repository.filechanges.count
71 assert_equal 13, @repository.filechanges.count
72 assert_equal "Initial commit.", @repository.changesets.find_by_revision('1').comments
72 assert_equal "Initial commit.", @repository.changesets.find_by_revision('1').comments
73 end
73 end
74
74
75 def test_fetch_changesets_incremental
75 def test_fetch_changesets_incremental
76 assert_equal 0, @repository.changesets.count
76 assert_equal 0, @repository.changesets.count
77 @repository.fetch_changesets
77 @repository.fetch_changesets
78 @project.reload
78 @project.reload
79 assert_equal NUM_REV, @repository.changesets.count
79 assert_equal NUM_REV, @repository.changesets.count
80
80
81 # Remove changesets with revision > 3
81 # Remove changesets with revision > 3
82 @repository.changesets.all.each {|c| c.destroy if c.revision.to_i > 3}
82 @repository.changesets.all.each {|c| c.destroy if c.revision.to_i > 3}
83 @project.reload
83 @project.reload
84 @repository.reload
84 assert_equal 3, @repository.changesets.count
85 assert_equal 3, @repository.changesets.count
85
86
86 @repository.fetch_changesets
87 @repository.fetch_changesets
87 @project.reload
88 @project.reload
88 assert_equal NUM_REV, @repository.changesets.count
89 assert_equal NUM_REV, @repository.changesets.count
89 end
90 end
90
91
91 def test_entries
92 def test_entries
92 entries = @repository.entries
93 entries = @repository.entries
93 assert_kind_of Redmine::Scm::Adapters::Entries, entries
94 assert_kind_of Redmine::Scm::Adapters::Entries, entries
94 end
95 end
95
96
96 def test_entries_invalid_revision
97 def test_entries_invalid_revision
97 assert_equal 0, @repository.changesets.count
98 assert_equal 0, @repository.changesets.count
98 @repository.fetch_changesets
99 @repository.fetch_changesets
99 @project.reload
100 @project.reload
100 assert_equal NUM_REV, @repository.changesets.count
101 assert_equal NUM_REV, @repository.changesets.count
101 assert_nil @repository.entries('', '123')
102 assert_nil @repository.entries('', '123')
102 end
103 end
103
104
104 def test_deleted_files_should_not_be_listed
105 def test_deleted_files_should_not_be_listed
105 assert_equal 0, @repository.changesets.count
106 assert_equal 0, @repository.changesets.count
106 @repository.fetch_changesets
107 @repository.fetch_changesets
107 @project.reload
108 @project.reload
108 assert_equal NUM_REV, @repository.changesets.count
109 assert_equal NUM_REV, @repository.changesets.count
109 entries = @repository.entries('sources')
110 entries = @repository.entries('sources')
110 assert entries.detect {|e| e.name == 'watchers_controller.rb'}
111 assert entries.detect {|e| e.name == 'watchers_controller.rb'}
111 assert_nil entries.detect {|e| e.name == 'welcome_controller.rb'}
112 assert_nil entries.detect {|e| e.name == 'welcome_controller.rb'}
112 end
113 end
113
114
114 def test_cat
115 def test_cat
115 if @repository.scm.supports_cat?
116 if @repository.scm.supports_cat?
116 assert_equal 0, @repository.changesets.count
117 assert_equal 0, @repository.changesets.count
117 @repository.fetch_changesets
118 @repository.fetch_changesets
118 @project.reload
119 @project.reload
119 assert_equal NUM_REV, @repository.changesets.count
120 assert_equal NUM_REV, @repository.changesets.count
120 cat = @repository.cat("sources/welcome_controller.rb", 2)
121 cat = @repository.cat("sources/welcome_controller.rb", 2)
121 assert_not_nil cat
122 assert_not_nil cat
122 assert cat.include?('class WelcomeController < ApplicationController')
123 assert cat.include?('class WelcomeController < ApplicationController')
123 end
124 end
124 end
125 end
125 else
126 else
126 puts "Darcs test repository NOT FOUND. Skipping unit tests !!!"
127 puts "Darcs test repository NOT FOUND. Skipping unit tests !!!"
127 def test_fake; assert true end
128 def test_fake; assert true end
128 end
129 end
129 end
130 end
@@ -1,377 +1,378
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
2 # Copyright (C) 2006-2013 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
19
20 class RepositoryMercurialTest < ActiveSupport::TestCase
20 class RepositoryMercurialTest < 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/mercurial_repository').to_s
25 REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s
26 NUM_REV = 32
26 NUM_REV = 32
27 CHAR_1_HEX = "\xc3\x9c"
27 CHAR_1_HEX = "\xc3\x9c"
28
28
29 def setup
29 def setup
30 @project = Project.find(3)
30 @project = Project.find(3)
31 @repository = Repository::Mercurial.create(
31 @repository = Repository::Mercurial.create(
32 :project => @project,
32 :project => @project,
33 :url => REPOSITORY_PATH,
33 :url => REPOSITORY_PATH,
34 :path_encoding => 'ISO-8859-1'
34 :path_encoding => 'ISO-8859-1'
35 )
35 )
36 assert @repository
36 assert @repository
37 @char_1 = CHAR_1_HEX.dup
37 @char_1 = CHAR_1_HEX.dup
38 @tag_char_1 = "tag-#{CHAR_1_HEX}-00"
38 @tag_char_1 = "tag-#{CHAR_1_HEX}-00"
39 @branch_char_0 = "branch-#{CHAR_1_HEX}-00"
39 @branch_char_0 = "branch-#{CHAR_1_HEX}-00"
40 @branch_char_1 = "branch-#{CHAR_1_HEX}-01"
40 @branch_char_1 = "branch-#{CHAR_1_HEX}-01"
41 if @char_1.respond_to?(:force_encoding)
41 if @char_1.respond_to?(:force_encoding)
42 @char_1.force_encoding('UTF-8')
42 @char_1.force_encoding('UTF-8')
43 @tag_char_1.force_encoding('UTF-8')
43 @tag_char_1.force_encoding('UTF-8')
44 @branch_char_0.force_encoding('UTF-8')
44 @branch_char_0.force_encoding('UTF-8')
45 @branch_char_1.force_encoding('UTF-8')
45 @branch_char_1.force_encoding('UTF-8')
46 end
46 end
47 end
47 end
48
48
49
49
50 def test_blank_path_to_repository_error_message
50 def test_blank_path_to_repository_error_message
51 set_language_if_valid 'en'
51 set_language_if_valid 'en'
52 repo = Repository::Mercurial.new(
52 repo = Repository::Mercurial.new(
53 :project => @project,
53 :project => @project,
54 :identifier => 'test'
54 :identifier => 'test'
55 )
55 )
56 assert !repo.save
56 assert !repo.save
57 assert_include "Path to repository can't be blank",
57 assert_include "Path to repository can't be blank",
58 repo.errors.full_messages
58 repo.errors.full_messages
59 end
59 end
60
60
61 def test_blank_path_to_repository_error_message_fr
61 def test_blank_path_to_repository_error_message_fr
62 set_language_if_valid 'fr'
62 set_language_if_valid 'fr'
63 str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)"
63 str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)"
64 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
64 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
65 repo = Repository::Mercurial.new(
65 repo = Repository::Mercurial.new(
66 :project => @project,
66 :project => @project,
67 :url => "",
67 :url => "",
68 :identifier => 'test',
68 :identifier => 'test',
69 :path_encoding => ''
69 :path_encoding => ''
70 )
70 )
71 assert !repo.save
71 assert !repo.save
72 assert_include str, repo.errors.full_messages
72 assert_include str, repo.errors.full_messages
73 end
73 end
74
74
75 if File.directory?(REPOSITORY_PATH)
75 if File.directory?(REPOSITORY_PATH)
76 def test_scm_available
76 def test_scm_available
77 klass = Repository::Mercurial
77 klass = Repository::Mercurial
78 assert_equal "Mercurial", klass.scm_name
78 assert_equal "Mercurial", klass.scm_name
79 assert klass.scm_adapter_class
79 assert klass.scm_adapter_class
80 assert_not_equal "", klass.scm_command
80 assert_not_equal "", klass.scm_command
81 assert_equal true, klass.scm_available
81 assert_equal true, klass.scm_available
82 end
82 end
83
83
84 def test_entries
84 def test_entries
85 entries = @repository.entries
85 entries = @repository.entries
86 assert_kind_of Redmine::Scm::Adapters::Entries, entries
86 assert_kind_of Redmine::Scm::Adapters::Entries, entries
87 end
87 end
88
88
89 def test_fetch_changesets_from_scratch
89 def test_fetch_changesets_from_scratch
90 assert_equal 0, @repository.changesets.count
90 assert_equal 0, @repository.changesets.count
91 @repository.fetch_changesets
91 @repository.fetch_changesets
92 @project.reload
92 @project.reload
93 assert_equal NUM_REV, @repository.changesets.count
93 assert_equal NUM_REV, @repository.changesets.count
94 assert_equal 46, @repository.filechanges.count
94 assert_equal 46, @repository.filechanges.count
95 assert_equal "Initial import.\nThe repository contains 3 files.",
95 assert_equal "Initial import.\nThe repository contains 3 files.",
96 @repository.changesets.find_by_revision('0').comments
96 @repository.changesets.find_by_revision('0').comments
97 end
97 end
98
98
99 def test_fetch_changesets_incremental
99 def test_fetch_changesets_incremental
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 assert_equal NUM_REV, @repository.changesets.count
103 assert_equal NUM_REV, @repository.changesets.count
104 # Remove changesets with revision > 2
104 # Remove changesets with revision > 2
105 @repository.changesets.all.each {|c| c.destroy if c.revision.to_i > 2}
105 @repository.changesets.all.each {|c| c.destroy if c.revision.to_i > 2}
106 @project.reload
106 @project.reload
107 @repository.reload
107 assert_equal 3, @repository.changesets.count
108 assert_equal 3, @repository.changesets.count
108
109
109 @repository.fetch_changesets
110 @repository.fetch_changesets
110 @project.reload
111 @project.reload
111 assert_equal NUM_REV, @repository.changesets.count
112 assert_equal NUM_REV, @repository.changesets.count
112 end
113 end
113
114
114 def test_isodatesec
115 def test_isodatesec
115 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher
116 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher
116 if @repository.scm.class.client_version_above?([1, 0])
117 if @repository.scm.class.client_version_above?([1, 0])
117 assert_equal 0, @repository.changesets.count
118 assert_equal 0, @repository.changesets.count
118 @repository.fetch_changesets
119 @repository.fetch_changesets
119 @project.reload
120 @project.reload
120 assert_equal NUM_REV, @repository.changesets.count
121 assert_equal NUM_REV, @repository.changesets.count
121 rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52)
122 rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52)
122 assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on
123 assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on
123 end
124 end
124 end
125 end
125
126
126 def test_changeset_order_by_revision
127 def test_changeset_order_by_revision
127 assert_equal 0, @repository.changesets.count
128 assert_equal 0, @repository.changesets.count
128 @repository.fetch_changesets
129 @repository.fetch_changesets
129 @project.reload
130 @project.reload
130 assert_equal NUM_REV, @repository.changesets.count
131 assert_equal NUM_REV, @repository.changesets.count
131
132
132 c0 = @repository.latest_changeset
133 c0 = @repository.latest_changeset
133 c1 = @repository.changesets.find_by_revision('0')
134 c1 = @repository.changesets.find_by_revision('0')
134 # sorted by revision (id), not by date
135 # sorted by revision (id), not by date
135 assert c0.revision.to_i > c1.revision.to_i
136 assert c0.revision.to_i > c1.revision.to_i
136 assert c0.committed_on < c1.committed_on
137 assert c0.committed_on < c1.committed_on
137 end
138 end
138
139
139 def test_latest_changesets
140 def test_latest_changesets
140 assert_equal 0, @repository.changesets.count
141 assert_equal 0, @repository.changesets.count
141 @repository.fetch_changesets
142 @repository.fetch_changesets
142 @project.reload
143 @project.reload
143 assert_equal NUM_REV, @repository.changesets.count
144 assert_equal NUM_REV, @repository.changesets.count
144
145
145 # with_limit
146 # with_limit
146 changesets = @repository.latest_changesets('', nil, 2)
147 changesets = @repository.latest_changesets('', nil, 2)
147 assert_equal %w|31 30|, changesets.collect(&:revision)
148 assert_equal %w|31 30|, changesets.collect(&:revision)
148
149
149 # with_filepath
150 # with_filepath
150 changesets = @repository.latest_changesets(
151 changesets = @repository.latest_changesets(
151 '/sql_escape/percent%dir/percent%file1.txt', nil)
152 '/sql_escape/percent%dir/percent%file1.txt', nil)
152 assert_equal %w|30 11 10 9|, changesets.collect(&:revision)
153 assert_equal %w|30 11 10 9|, changesets.collect(&:revision)
153
154
154 changesets = @repository.latest_changesets(
155 changesets = @repository.latest_changesets(
155 '/sql_escape/underscore_dir/understrike_file.txt', nil)
156 '/sql_escape/underscore_dir/understrike_file.txt', nil)
156 assert_equal %w|30 12 9|, changesets.collect(&:revision)
157 assert_equal %w|30 12 9|, changesets.collect(&:revision)
157
158
158 changesets = @repository.latest_changesets('README', nil)
159 changesets = @repository.latest_changesets('README', nil)
159 assert_equal %w|31 30 28 17 8 6 1 0|, changesets.collect(&:revision)
160 assert_equal %w|31 30 28 17 8 6 1 0|, changesets.collect(&:revision)
160
161
161 changesets = @repository.latest_changesets('README','8')
162 changesets = @repository.latest_changesets('README','8')
162 assert_equal %w|8 6 1 0|, changesets.collect(&:revision)
163 assert_equal %w|8 6 1 0|, changesets.collect(&:revision)
163
164
164 changesets = @repository.latest_changesets('README','8', 2)
165 changesets = @repository.latest_changesets('README','8', 2)
165 assert_equal %w|8 6|, changesets.collect(&:revision)
166 assert_equal %w|8 6|, changesets.collect(&:revision)
166
167
167 # with_dirpath
168 # with_dirpath
168 changesets = @repository.latest_changesets('images', nil)
169 changesets = @repository.latest_changesets('images', nil)
169 assert_equal %w|1 0|, changesets.collect(&:revision)
170 assert_equal %w|1 0|, changesets.collect(&:revision)
170
171
171 path = 'sql_escape/percent%dir'
172 path = 'sql_escape/percent%dir'
172 changesets = @repository.latest_changesets(path, nil)
173 changesets = @repository.latest_changesets(path, nil)
173 assert_equal %w|30 13 11 10 9|, changesets.collect(&:revision)
174 assert_equal %w|30 13 11 10 9|, changesets.collect(&:revision)
174
175
175 changesets = @repository.latest_changesets(path, '11')
176 changesets = @repository.latest_changesets(path, '11')
176 assert_equal %w|11 10 9|, changesets.collect(&:revision)
177 assert_equal %w|11 10 9|, changesets.collect(&:revision)
177
178
178 changesets = @repository.latest_changesets(path, '11', 2)
179 changesets = @repository.latest_changesets(path, '11', 2)
179 assert_equal %w|11 10|, changesets.collect(&:revision)
180 assert_equal %w|11 10|, changesets.collect(&:revision)
180
181
181 path = 'sql_escape/underscore_dir'
182 path = 'sql_escape/underscore_dir'
182 changesets = @repository.latest_changesets(path, nil)
183 changesets = @repository.latest_changesets(path, nil)
183 assert_equal %w|30 13 12 9|, changesets.collect(&:revision)
184 assert_equal %w|30 13 12 9|, changesets.collect(&:revision)
184
185
185 changesets = @repository.latest_changesets(path, '12')
186 changesets = @repository.latest_changesets(path, '12')
186 assert_equal %w|12 9|, changesets.collect(&:revision)
187 assert_equal %w|12 9|, changesets.collect(&:revision)
187
188
188 changesets = @repository.latest_changesets(path, '12', 1)
189 changesets = @repository.latest_changesets(path, '12', 1)
189 assert_equal %w|12|, changesets.collect(&:revision)
190 assert_equal %w|12|, changesets.collect(&:revision)
190
191
191 # tag
192 # tag
192 changesets = @repository.latest_changesets('', 'tag_test.00')
193 changesets = @repository.latest_changesets('', 'tag_test.00')
193 assert_equal %w|5 4 3 2 1 0|, changesets.collect(&:revision)
194 assert_equal %w|5 4 3 2 1 0|, changesets.collect(&:revision)
194
195
195 changesets = @repository.latest_changesets('', 'tag_test.00', 2)
196 changesets = @repository.latest_changesets('', 'tag_test.00', 2)
196 assert_equal %w|5 4|, changesets.collect(&:revision)
197 assert_equal %w|5 4|, changesets.collect(&:revision)
197
198
198 changesets = @repository.latest_changesets('sources', 'tag_test.00')
199 changesets = @repository.latest_changesets('sources', 'tag_test.00')
199 assert_equal %w|4 3 2 1 0|, changesets.collect(&:revision)
200 assert_equal %w|4 3 2 1 0|, changesets.collect(&:revision)
200
201
201 changesets = @repository.latest_changesets('sources', 'tag_test.00', 2)
202 changesets = @repository.latest_changesets('sources', 'tag_test.00', 2)
202 assert_equal %w|4 3|, changesets.collect(&:revision)
203 assert_equal %w|4 3|, changesets.collect(&:revision)
203
204
204 # named branch
205 # named branch
205 if @repository.scm.class.client_version_above?([1, 6])
206 if @repository.scm.class.client_version_above?([1, 6])
206 changesets = @repository.latest_changesets('', @branch_char_1)
207 changesets = @repository.latest_changesets('', @branch_char_1)
207 assert_equal %w|27 26|, changesets.collect(&:revision)
208 assert_equal %w|27 26|, changesets.collect(&:revision)
208 end
209 end
209
210
210 changesets = @repository.latest_changesets("latin-1-dir/test-#{@char_1}-subdir", @branch_char_1)
211 changesets = @repository.latest_changesets("latin-1-dir/test-#{@char_1}-subdir", @branch_char_1)
211 assert_equal %w|27|, changesets.collect(&:revision)
212 assert_equal %w|27|, changesets.collect(&:revision)
212 end
213 end
213
214
214 def test_copied_files
215 def test_copied_files
215 assert_equal 0, @repository.changesets.count
216 assert_equal 0, @repository.changesets.count
216 @repository.fetch_changesets
217 @repository.fetch_changesets
217 @project.reload
218 @project.reload
218 assert_equal NUM_REV, @repository.changesets.count
219 assert_equal NUM_REV, @repository.changesets.count
219
220
220 cs1 = @repository.changesets.find_by_revision('13')
221 cs1 = @repository.changesets.find_by_revision('13')
221 assert_not_nil cs1
222 assert_not_nil cs1
222 c1 = cs1.filechanges.sort_by(&:path)
223 c1 = cs1.filechanges.sort_by(&:path)
223 assert_equal 2, c1.size
224 assert_equal 2, c1.size
224
225
225 assert_equal 'A', c1[0].action
226 assert_equal 'A', c1[0].action
226 assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path
227 assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path
227 assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path
228 assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path
228 assert_equal '3a330eb32958', c1[0].from_revision
229 assert_equal '3a330eb32958', c1[0].from_revision
229
230
230 assert_equal 'A', c1[1].action
231 assert_equal 'A', c1[1].action
231 assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path
232 assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path
232 assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path
233 assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path
233
234
234 cs2 = @repository.changesets.find_by_revision('15')
235 cs2 = @repository.changesets.find_by_revision('15')
235 c2 = cs2.filechanges
236 c2 = cs2.filechanges
236 assert_equal 1, c2.size
237 assert_equal 1, c2.size
237
238
238 assert_equal 'A', c2[0].action
239 assert_equal 'A', c2[0].action
239 assert_equal '/README (1)[2]&,%.-3_4', c2[0].path
240 assert_equal '/README (1)[2]&,%.-3_4', c2[0].path
240 assert_equal '/README', c2[0].from_path
241 assert_equal '/README', c2[0].from_path
241 assert_equal '933ca60293d7', c2[0].from_revision
242 assert_equal '933ca60293d7', c2[0].from_revision
242
243
243 cs3 = @repository.changesets.find_by_revision('19')
244 cs3 = @repository.changesets.find_by_revision('19')
244 c3 = cs3.filechanges
245 c3 = cs3.filechanges
245 assert_equal 1, c3.size
246 assert_equal 1, c3.size
246 assert_equal 'A', c3[0].action
247 assert_equal 'A', c3[0].action
247 assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path
248 assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path
248 assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path
249 assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path
249 assert_equal '5d9891a1b425', c3[0].from_revision
250 assert_equal '5d9891a1b425', c3[0].from_revision
250 end
251 end
251
252
252 def test_find_changeset_by_name
253 def test_find_changeset_by_name
253 assert_equal 0, @repository.changesets.count
254 assert_equal 0, @repository.changesets.count
254 @repository.fetch_changesets
255 @repository.fetch_changesets
255 @project.reload
256 @project.reload
256 assert_equal NUM_REV, @repository.changesets.count
257 assert_equal NUM_REV, @repository.changesets.count
257 %w|2 400bb8672109 400|.each do |r|
258 %w|2 400bb8672109 400|.each do |r|
258 assert_equal '2', @repository.find_changeset_by_name(r).revision
259 assert_equal '2', @repository.find_changeset_by_name(r).revision
259 end
260 end
260 end
261 end
261
262
262 def test_find_changeset_by_invalid_name
263 def test_find_changeset_by_invalid_name
263 assert_equal 0, @repository.changesets.count
264 assert_equal 0, @repository.changesets.count
264 @repository.fetch_changesets
265 @repository.fetch_changesets
265 @project.reload
266 @project.reload
266 assert_equal NUM_REV, @repository.changesets.count
267 assert_equal NUM_REV, @repository.changesets.count
267 assert_nil @repository.find_changeset_by_name('100000')
268 assert_nil @repository.find_changeset_by_name('100000')
268 end
269 end
269
270
270 def test_identifier
271 def test_identifier
271 assert_equal 0, @repository.changesets.count
272 assert_equal 0, @repository.changesets.count
272 @repository.fetch_changesets
273 @repository.fetch_changesets
273 @project.reload
274 @project.reload
274 assert_equal NUM_REV, @repository.changesets.count
275 assert_equal NUM_REV, @repository.changesets.count
275 c = @repository.changesets.find_by_revision('2')
276 c = @repository.changesets.find_by_revision('2')
276 assert_equal c.scmid, c.identifier
277 assert_equal c.scmid, c.identifier
277 end
278 end
278
279
279 def test_format_identifier
280 def test_format_identifier
280 assert_equal 0, @repository.changesets.count
281 assert_equal 0, @repository.changesets.count
281 @repository.fetch_changesets
282 @repository.fetch_changesets
282 @project.reload
283 @project.reload
283 assert_equal NUM_REV, @repository.changesets.count
284 assert_equal NUM_REV, @repository.changesets.count
284 c = @repository.changesets.find_by_revision('2')
285 c = @repository.changesets.find_by_revision('2')
285 assert_equal '2:400bb8672109', c.format_identifier
286 assert_equal '2:400bb8672109', c.format_identifier
286 end
287 end
287
288
288 def test_find_changeset_by_empty_name
289 def test_find_changeset_by_empty_name
289 assert_equal 0, @repository.changesets.count
290 assert_equal 0, @repository.changesets.count
290 @repository.fetch_changesets
291 @repository.fetch_changesets
291 @project.reload
292 @project.reload
292 assert_equal NUM_REV, @repository.changesets.count
293 assert_equal NUM_REV, @repository.changesets.count
293 ['', ' ', nil].each do |r|
294 ['', ' ', nil].each do |r|
294 assert_nil @repository.find_changeset_by_name(r)
295 assert_nil @repository.find_changeset_by_name(r)
295 end
296 end
296 end
297 end
297
298
298 def test_parents
299 def test_parents
299 assert_equal 0, @repository.changesets.count
300 assert_equal 0, @repository.changesets.count
300 @repository.fetch_changesets
301 @repository.fetch_changesets
301 @project.reload
302 @project.reload
302 assert_equal NUM_REV, @repository.changesets.count
303 assert_equal NUM_REV, @repository.changesets.count
303 r1 = @repository.changesets.find_by_revision('0')
304 r1 = @repository.changesets.find_by_revision('0')
304 assert_equal [], r1.parents
305 assert_equal [], r1.parents
305 r2 = @repository.changesets.find_by_revision('1')
306 r2 = @repository.changesets.find_by_revision('1')
306 assert_equal 1, r2.parents.length
307 assert_equal 1, r2.parents.length
307 assert_equal "0885933ad4f6",
308 assert_equal "0885933ad4f6",
308 r2.parents[0].identifier
309 r2.parents[0].identifier
309 r3 = @repository.changesets.find_by_revision('30')
310 r3 = @repository.changesets.find_by_revision('30')
310 assert_equal 2, r3.parents.length
311 assert_equal 2, r3.parents.length
311 r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort
312 r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort
312 assert_equal "3a330eb32958", r4[0]
313 assert_equal "3a330eb32958", r4[0]
313 assert_equal "a94b0528f24f", r4[1]
314 assert_equal "a94b0528f24f", r4[1]
314 end
315 end
315
316
316 def test_activities
317 def test_activities
317 c = Changeset.new(:repository => @repository,
318 c = Changeset.new(:repository => @repository,
318 :committed_on => Time.now,
319 :committed_on => Time.now,
319 :revision => '123',
320 :revision => '123',
320 :scmid => 'abc400bb8672',
321 :scmid => 'abc400bb8672',
321 :comments => 'test')
322 :comments => 'test')
322 assert c.event_title.include?('123:abc400bb8672:')
323 assert c.event_title.include?('123:abc400bb8672:')
323 assert_equal 'abc400bb8672', c.event_url[:rev]
324 assert_equal 'abc400bb8672', c.event_url[:rev]
324 end
325 end
325
326
326 def test_previous
327 def test_previous
327 assert_equal 0, @repository.changesets.count
328 assert_equal 0, @repository.changesets.count
328 @repository.fetch_changesets
329 @repository.fetch_changesets
329 @project.reload
330 @project.reload
330 assert_equal NUM_REV, @repository.changesets.count
331 assert_equal NUM_REV, @repository.changesets.count
331 %w|28 3ae45e2d177d 3ae45|.each do |r1|
332 %w|28 3ae45e2d177d 3ae45|.each do |r1|
332 changeset = @repository.find_changeset_by_name(r1)
333 changeset = @repository.find_changeset_by_name(r1)
333 %w|27 7bbf4c738e71 7bbf|.each do |r2|
334 %w|27 7bbf4c738e71 7bbf|.each do |r2|
334 assert_equal @repository.find_changeset_by_name(r2), changeset.previous
335 assert_equal @repository.find_changeset_by_name(r2), changeset.previous
335 end
336 end
336 end
337 end
337 end
338 end
338
339
339 def test_previous_nil
340 def test_previous_nil
340 assert_equal 0, @repository.changesets.count
341 assert_equal 0, @repository.changesets.count
341 @repository.fetch_changesets
342 @repository.fetch_changesets
342 @project.reload
343 @project.reload
343 assert_equal NUM_REV, @repository.changesets.count
344 assert_equal NUM_REV, @repository.changesets.count
344 %w|0 0885933ad4f6 0885|.each do |r1|
345 %w|0 0885933ad4f6 0885|.each do |r1|
345 changeset = @repository.find_changeset_by_name(r1)
346 changeset = @repository.find_changeset_by_name(r1)
346 assert_nil changeset.previous
347 assert_nil changeset.previous
347 end
348 end
348 end
349 end
349
350
350 def test_next
351 def test_next
351 assert_equal 0, @repository.changesets.count
352 assert_equal 0, @repository.changesets.count
352 @repository.fetch_changesets
353 @repository.fetch_changesets
353 @project.reload
354 @project.reload
354 assert_equal NUM_REV, @repository.changesets.count
355 assert_equal NUM_REV, @repository.changesets.count
355 %w|27 7bbf4c738e71 7bbf|.each do |r2|
356 %w|27 7bbf4c738e71 7bbf|.each do |r2|
356 changeset = @repository.find_changeset_by_name(r2)
357 changeset = @repository.find_changeset_by_name(r2)
357 %w|28 3ae45e2d177d 3ae45|.each do |r1|
358 %w|28 3ae45e2d177d 3ae45|.each do |r1|
358 assert_equal @repository.find_changeset_by_name(r1), changeset.next
359 assert_equal @repository.find_changeset_by_name(r1), changeset.next
359 end
360 end
360 end
361 end
361 end
362 end
362
363
363 def test_next_nil
364 def test_next_nil
364 assert_equal 0, @repository.changesets.count
365 assert_equal 0, @repository.changesets.count
365 @repository.fetch_changesets
366 @repository.fetch_changesets
366 @project.reload
367 @project.reload
367 assert_equal NUM_REV, @repository.changesets.count
368 assert_equal NUM_REV, @repository.changesets.count
368 %w|31 31eeee7395c8 31eee|.each do |r1|
369 %w|31 31eeee7395c8 31eee|.each do |r1|
369 changeset = @repository.find_changeset_by_name(r1)
370 changeset = @repository.find_changeset_by_name(r1)
370 assert_nil changeset.next
371 assert_nil changeset.next
371 end
372 end
372 end
373 end
373 else
374 else
374 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
375 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
375 def test_fake; assert true end
376 def test_fake; assert true end
376 end
377 end
377 end
378 end
@@ -1,259 +1,260
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
2 # Copyright (C) 2006-2013 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
19
20 class RepositorySubversionTest < ActiveSupport::TestCase
20 class RepositorySubversionTest < ActiveSupport::TestCase
21 fixtures :projects, :repositories, :enabled_modules, :users, :roles
21 fixtures :projects, :repositories, :enabled_modules, :users, :roles
22
22
23 include Redmine::I18n
23 include Redmine::I18n
24
24
25 NUM_REV = 11
25 NUM_REV = 11
26
26
27 def setup
27 def setup
28 @project = Project.find(3)
28 @project = Project.find(3)
29 @repository = Repository::Subversion.create(:project => @project,
29 @repository = Repository::Subversion.create(:project => @project,
30 :url => self.class.subversion_repository_url)
30 :url => self.class.subversion_repository_url)
31 assert @repository
31 assert @repository
32 end
32 end
33
33
34 def test_invalid_url
34 def test_invalid_url
35 set_language_if_valid 'en'
35 set_language_if_valid 'en'
36 ['invalid', 'http://', 'svn://', 'svn+ssh://', 'file://'].each do |url|
36 ['invalid', 'http://', 'svn://', 'svn+ssh://', 'file://'].each do |url|
37 repo = Repository::Subversion.new(
37 repo = Repository::Subversion.new(
38 :project => @project,
38 :project => @project,
39 :identifier => 'test',
39 :identifier => 'test',
40 :url => url
40 :url => url
41 )
41 )
42 assert !repo.save
42 assert !repo.save
43 assert_equal ["is invalid"], repo.errors[:url]
43 assert_equal ["is invalid"], repo.errors[:url]
44 end
44 end
45 end
45 end
46
46
47 def test_valid_url
47 def test_valid_url
48 ['http://valid', 'svn://valid', 'svn+ssh://valid', 'file://valid'].each do |url|
48 ['http://valid', 'svn://valid', 'svn+ssh://valid', 'file://valid'].each do |url|
49 repo = Repository::Subversion.new(
49 repo = Repository::Subversion.new(
50 :project => @project,
50 :project => @project,
51 :identifier => 'test',
51 :identifier => 'test',
52 :url => url
52 :url => url
53 )
53 )
54 assert repo.save
54 assert repo.save
55 assert_equal [], repo.errors[:url]
55 assert_equal [], repo.errors[:url]
56 assert repo.destroy
56 assert repo.destroy
57 end
57 end
58 end
58 end
59
59
60 if repository_configured?('subversion')
60 if repository_configured?('subversion')
61 def test_fetch_changesets_from_scratch
61 def test_fetch_changesets_from_scratch
62 assert_equal 0, @repository.changesets.count
62 assert_equal 0, @repository.changesets.count
63 @repository.fetch_changesets
63 @repository.fetch_changesets
64 @project.reload
64 @project.reload
65
65
66 assert_equal NUM_REV, @repository.changesets.count
66 assert_equal NUM_REV, @repository.changesets.count
67 assert_equal 20, @repository.filechanges.count
67 assert_equal 20, @repository.filechanges.count
68 assert_equal 'Initial import.', @repository.changesets.find_by_revision('1').comments
68 assert_equal 'Initial import.', @repository.changesets.find_by_revision('1').comments
69 end
69 end
70
70
71 def test_fetch_changesets_incremental
71 def test_fetch_changesets_incremental
72 assert_equal 0, @repository.changesets.count
72 assert_equal 0, @repository.changesets.count
73 @repository.fetch_changesets
73 @repository.fetch_changesets
74 @project.reload
74 @project.reload
75 assert_equal NUM_REV, @repository.changesets.count
75 assert_equal NUM_REV, @repository.changesets.count
76
76
77 # Remove changesets with revision > 5
77 # Remove changesets with revision > 5
78 @repository.changesets.all.each {|c| c.destroy if c.revision.to_i > 5}
78 @repository.changesets.all.each {|c| c.destroy if c.revision.to_i > 5}
79 @project.reload
79 @project.reload
80 @repository.reload
80 assert_equal 5, @repository.changesets.count
81 assert_equal 5, @repository.changesets.count
81
82
82 @repository.fetch_changesets
83 @repository.fetch_changesets
83 @project.reload
84 @project.reload
84 assert_equal NUM_REV, @repository.changesets.count
85 assert_equal NUM_REV, @repository.changesets.count
85 end
86 end
86
87
87 def test_entries
88 def test_entries
88 entries = @repository.entries
89 entries = @repository.entries
89 assert_kind_of Redmine::Scm::Adapters::Entries, entries
90 assert_kind_of Redmine::Scm::Adapters::Entries, entries
90 end
91 end
91
92
92 def test_entries_for_invalid_path_should_return_nil
93 def test_entries_for_invalid_path_should_return_nil
93 entries = @repository.entries('invalid_path')
94 entries = @repository.entries('invalid_path')
94 assert_nil entries
95 assert_nil entries
95 end
96 end
96
97
97 def test_latest_changesets
98 def test_latest_changesets
98 assert_equal 0, @repository.changesets.count
99 assert_equal 0, @repository.changesets.count
99 @repository.fetch_changesets
100 @repository.fetch_changesets
100 @project.reload
101 @project.reload
101 assert_equal NUM_REV, @repository.changesets.count
102 assert_equal NUM_REV, @repository.changesets.count
102
103
103 # with limit
104 # with limit
104 changesets = @repository.latest_changesets('', nil, 2)
105 changesets = @repository.latest_changesets('', nil, 2)
105 assert_equal 2, changesets.size
106 assert_equal 2, changesets.size
106 assert_equal @repository.latest_changesets('', nil).slice(0,2), changesets
107 assert_equal @repository.latest_changesets('', nil).slice(0,2), changesets
107
108
108 # with path
109 # with path
109 changesets = @repository.latest_changesets('subversion_test/folder', nil)
110 changesets = @repository.latest_changesets('subversion_test/folder', nil)
110 assert_equal ["10", "9", "7", "6", "5", "2"], changesets.collect(&:revision)
111 assert_equal ["10", "9", "7", "6", "5", "2"], changesets.collect(&:revision)
111
112
112 # with path and revision
113 # with path and revision
113 changesets = @repository.latest_changesets('subversion_test/folder', 8)
114 changesets = @repository.latest_changesets('subversion_test/folder', 8)
114 assert_equal ["7", "6", "5", "2"], changesets.collect(&:revision)
115 assert_equal ["7", "6", "5", "2"], changesets.collect(&:revision)
115 end
116 end
116
117
117 def test_directory_listing_with_square_brackets_in_path
118 def test_directory_listing_with_square_brackets_in_path
118 assert_equal 0, @repository.changesets.count
119 assert_equal 0, @repository.changesets.count
119 @repository.fetch_changesets
120 @repository.fetch_changesets
120 @project.reload
121 @project.reload
121 assert_equal NUM_REV, @repository.changesets.count
122 assert_equal NUM_REV, @repository.changesets.count
122
123
123 entries = @repository.entries('subversion_test/[folder_with_brackets]')
124 entries = @repository.entries('subversion_test/[folder_with_brackets]')
124 assert_not_nil entries, 'Expect to find entries in folder_with_brackets'
125 assert_not_nil entries, 'Expect to find entries in folder_with_brackets'
125 assert_equal 1, entries.size, 'Expect one entry in folder_with_brackets'
126 assert_equal 1, entries.size, 'Expect one entry in folder_with_brackets'
126 assert_equal 'README.txt', entries.first.name
127 assert_equal 'README.txt', entries.first.name
127 end
128 end
128
129
129 def test_directory_listing_with_square_brackets_in_base
130 def test_directory_listing_with_square_brackets_in_base
130 @project = Project.find(3)
131 @project = Project.find(3)
131 @repository = Repository::Subversion.create(
132 @repository = Repository::Subversion.create(
132 :project => @project,
133 :project => @project,
133 :url => "file:///#{self.class.repository_path('subversion')}/subversion_test/[folder_with_brackets]")
134 :url => "file:///#{self.class.repository_path('subversion')}/subversion_test/[folder_with_brackets]")
134
135
135 assert_equal 0, @repository.changesets.count
136 assert_equal 0, @repository.changesets.count
136 @repository.fetch_changesets
137 @repository.fetch_changesets
137 @project.reload
138 @project.reload
138
139
139 assert_equal 1, @repository.changesets.count, 'Expected to see 1 revision'
140 assert_equal 1, @repository.changesets.count, 'Expected to see 1 revision'
140 assert_equal 2, @repository.filechanges.count, 'Expected to see 2 changes, dir add and file add'
141 assert_equal 2, @repository.filechanges.count, 'Expected to see 2 changes, dir add and file add'
141
142
142 entries = @repository.entries('')
143 entries = @repository.entries('')
143 assert_not_nil entries, 'Expect to find entries'
144 assert_not_nil entries, 'Expect to find entries'
144 assert_equal 1, entries.size, 'Expect a single entry'
145 assert_equal 1, entries.size, 'Expect a single entry'
145 assert_equal 'README.txt', entries.first.name
146 assert_equal 'README.txt', entries.first.name
146 end
147 end
147
148
148 def test_identifier
149 def test_identifier
149 assert_equal 0, @repository.changesets.count
150 assert_equal 0, @repository.changesets.count
150 @repository.fetch_changesets
151 @repository.fetch_changesets
151 @project.reload
152 @project.reload
152 assert_equal NUM_REV, @repository.changesets.count
153 assert_equal NUM_REV, @repository.changesets.count
153 c = @repository.changesets.find_by_revision('1')
154 c = @repository.changesets.find_by_revision('1')
154 assert_equal c.revision, c.identifier
155 assert_equal c.revision, c.identifier
155 end
156 end
156
157
157 def test_find_changeset_by_empty_name
158 def test_find_changeset_by_empty_name
158 assert_equal 0, @repository.changesets.count
159 assert_equal 0, @repository.changesets.count
159 @repository.fetch_changesets
160 @repository.fetch_changesets
160 @project.reload
161 @project.reload
161 assert_equal NUM_REV, @repository.changesets.count
162 assert_equal NUM_REV, @repository.changesets.count
162 ['', ' ', nil].each do |r|
163 ['', ' ', nil].each do |r|
163 assert_nil @repository.find_changeset_by_name(r)
164 assert_nil @repository.find_changeset_by_name(r)
164 end
165 end
165 end
166 end
166
167
167 def test_identifier_nine_digit
168 def test_identifier_nine_digit
168 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
169 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
169 :revision => '123456789', :comments => 'test')
170 :revision => '123456789', :comments => 'test')
170 assert_equal c.identifier, c.revision
171 assert_equal c.identifier, c.revision
171 end
172 end
172
173
173 def test_format_identifier
174 def test_format_identifier
174 assert_equal 0, @repository.changesets.count
175 assert_equal 0, @repository.changesets.count
175 @repository.fetch_changesets
176 @repository.fetch_changesets
176 @project.reload
177 @project.reload
177 assert_equal NUM_REV, @repository.changesets.count
178 assert_equal NUM_REV, @repository.changesets.count
178 c = @repository.changesets.find_by_revision('1')
179 c = @repository.changesets.find_by_revision('1')
179 assert_equal c.format_identifier, c.revision
180 assert_equal c.format_identifier, c.revision
180 end
181 end
181
182
182 def test_format_identifier_nine_digit
183 def test_format_identifier_nine_digit
183 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
184 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
184 :revision => '123456789', :comments => 'test')
185 :revision => '123456789', :comments => 'test')
185 assert_equal c.format_identifier, c.revision
186 assert_equal c.format_identifier, c.revision
186 end
187 end
187
188
188 def test_activities
189 def test_activities
189 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
190 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
190 :revision => '1', :comments => 'test')
191 :revision => '1', :comments => 'test')
191 assert c.event_title.include?('1:')
192 assert c.event_title.include?('1:')
192 assert_equal '1', c.event_url[:rev]
193 assert_equal '1', c.event_url[:rev]
193 end
194 end
194
195
195 def test_activities_nine_digit
196 def test_activities_nine_digit
196 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
197 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
197 :revision => '123456789', :comments => 'test')
198 :revision => '123456789', :comments => 'test')
198 assert c.event_title.include?('123456789:')
199 assert c.event_title.include?('123456789:')
199 assert_equal '123456789', c.event_url[:rev]
200 assert_equal '123456789', c.event_url[:rev]
200 end
201 end
201
202
202 def test_log_encoding_ignore_setting
203 def test_log_encoding_ignore_setting
203 with_settings :commit_logs_encoding => 'windows-1252' do
204 with_settings :commit_logs_encoding => 'windows-1252' do
204 s1 = "\xC2\x80"
205 s1 = "\xC2\x80"
205 s2 = "\xc3\x82\xc2\x80"
206 s2 = "\xc3\x82\xc2\x80"
206 if s1.respond_to?(:force_encoding)
207 if s1.respond_to?(:force_encoding)
207 s1.force_encoding('ISO-8859-1')
208 s1.force_encoding('ISO-8859-1')
208 s2.force_encoding('UTF-8')
209 s2.force_encoding('UTF-8')
209 assert_equal s1.encode('UTF-8'), s2
210 assert_equal s1.encode('UTF-8'), s2
210 end
211 end
211 c = Changeset.new(:repository => @repository,
212 c = Changeset.new(:repository => @repository,
212 :comments => s2,
213 :comments => s2,
213 :revision => '123',
214 :revision => '123',
214 :committed_on => Time.now)
215 :committed_on => Time.now)
215 assert c.save
216 assert c.save
216 assert_equal s2, c.comments
217 assert_equal s2, c.comments
217 end
218 end
218 end
219 end
219
220
220 def test_previous
221 def test_previous
221 assert_equal 0, @repository.changesets.count
222 assert_equal 0, @repository.changesets.count
222 @repository.fetch_changesets
223 @repository.fetch_changesets
223 @project.reload
224 @project.reload
224 assert_equal NUM_REV, @repository.changesets.count
225 assert_equal NUM_REV, @repository.changesets.count
225 changeset = @repository.find_changeset_by_name('3')
226 changeset = @repository.find_changeset_by_name('3')
226 assert_equal @repository.find_changeset_by_name('2'), changeset.previous
227 assert_equal @repository.find_changeset_by_name('2'), changeset.previous
227 end
228 end
228
229
229 def test_previous_nil
230 def test_previous_nil
230 assert_equal 0, @repository.changesets.count
231 assert_equal 0, @repository.changesets.count
231 @repository.fetch_changesets
232 @repository.fetch_changesets
232 @project.reload
233 @project.reload
233 assert_equal NUM_REV, @repository.changesets.count
234 assert_equal NUM_REV, @repository.changesets.count
234 changeset = @repository.find_changeset_by_name('1')
235 changeset = @repository.find_changeset_by_name('1')
235 assert_nil changeset.previous
236 assert_nil changeset.previous
236 end
237 end
237
238
238 def test_next
239 def test_next
239 assert_equal 0, @repository.changesets.count
240 assert_equal 0, @repository.changesets.count
240 @repository.fetch_changesets
241 @repository.fetch_changesets
241 @project.reload
242 @project.reload
242 assert_equal NUM_REV, @repository.changesets.count
243 assert_equal NUM_REV, @repository.changesets.count
243 changeset = @repository.find_changeset_by_name('2')
244 changeset = @repository.find_changeset_by_name('2')
244 assert_equal @repository.find_changeset_by_name('3'), changeset.next
245 assert_equal @repository.find_changeset_by_name('3'), changeset.next
245 end
246 end
246
247
247 def test_next_nil
248 def test_next_nil
248 assert_equal 0, @repository.changesets.count
249 assert_equal 0, @repository.changesets.count
249 @repository.fetch_changesets
250 @repository.fetch_changesets
250 @project.reload
251 @project.reload
251 assert_equal NUM_REV, @repository.changesets.count
252 assert_equal NUM_REV, @repository.changesets.count
252 changeset = @repository.find_changeset_by_name('11')
253 changeset = @repository.find_changeset_by_name('11')
253 assert_nil changeset.next
254 assert_nil changeset.next
254 end
255 end
255 else
256 else
256 puts "Subversion test repository NOT FOUND. Skipping unit tests !!!"
257 puts "Subversion test repository NOT FOUND. Skipping unit tests !!!"
257 def test_fake; assert true end
258 def test_fake; assert true end
258 end
259 end
259 end
260 end
General Comments 0
You need to be logged in to leave comments. Login now