##// END OF EJS Templates
scm: mercurial: add one "closed" branch to test repository (#16177)...
Toshi MARUYAMA -
r12654:e266ddb30965
parent child
Show More
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
@@ -1,526 +1,526
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2014 Jean-Philippe Lang
2 # Copyright (C) 2006-2014 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 RepositoriesMercurialControllerTest < ActionController::TestCase
20 class RepositoriesMercurialControllerTest < ActionController::TestCase
21 tests RepositoriesController
21 tests RepositoriesController
22
22
23 fixtures :projects, :users, :roles, :members, :member_roles,
23 fixtures :projects, :users, :roles, :members, :member_roles,
24 :repositories, :enabled_modules
24 :repositories, :enabled_modules
25
25
26 REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s
26 REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s
27 CHAR_1_HEX = "\xc3\x9c"
27 CHAR_1_HEX = "\xc3\x9c"
28 PRJ_ID = 3
28 PRJ_ID = 3
29 NUM_REV = 32
29 NUM_REV = 34
30
30
31 ruby19_non_utf8_pass =
31 ruby19_non_utf8_pass =
32 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
32 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
33
33
34 def setup
34 def setup
35 User.current = nil
35 User.current = nil
36 @project = Project.find(PRJ_ID)
36 @project = Project.find(PRJ_ID)
37 @repository = Repository::Mercurial.create(
37 @repository = Repository::Mercurial.create(
38 :project => @project,
38 :project => @project,
39 :url => REPOSITORY_PATH,
39 :url => REPOSITORY_PATH,
40 :path_encoding => 'ISO-8859-1'
40 :path_encoding => 'ISO-8859-1'
41 )
41 )
42 assert @repository
42 assert @repository
43 @diff_c_support = true
43 @diff_c_support = true
44 @char_1 = CHAR_1_HEX.dup
44 @char_1 = CHAR_1_HEX.dup
45 @tag_char_1 = "tag-#{CHAR_1_HEX}-00"
45 @tag_char_1 = "tag-#{CHAR_1_HEX}-00"
46 @branch_char_0 = "branch-#{CHAR_1_HEX}-00"
46 @branch_char_0 = "branch-#{CHAR_1_HEX}-00"
47 @branch_char_1 = "branch-#{CHAR_1_HEX}-01"
47 @branch_char_1 = "branch-#{CHAR_1_HEX}-01"
48 if @char_1.respond_to?(:force_encoding)
48 if @char_1.respond_to?(:force_encoding)
49 @char_1.force_encoding('UTF-8')
49 @char_1.force_encoding('UTF-8')
50 @tag_char_1.force_encoding('UTF-8')
50 @tag_char_1.force_encoding('UTF-8')
51 @branch_char_0.force_encoding('UTF-8')
51 @branch_char_0.force_encoding('UTF-8')
52 @branch_char_1.force_encoding('UTF-8')
52 @branch_char_1.force_encoding('UTF-8')
53 end
53 end
54 end
54 end
55
55
56 if ruby19_non_utf8_pass
56 if ruby19_non_utf8_pass
57 puts "TODO: Mercurial functional test fails in Ruby 1.9 " +
57 puts "TODO: Mercurial functional test fails in Ruby 1.9 " +
58 "and Encoding.default_external is not UTF-8. " +
58 "and Encoding.default_external is not UTF-8. " +
59 "Current value is '#{Encoding.default_external.to_s}'"
59 "Current value is '#{Encoding.default_external.to_s}'"
60 def test_fake; assert true end
60 def test_fake; assert true end
61 elsif File.directory?(REPOSITORY_PATH)
61 elsif File.directory?(REPOSITORY_PATH)
62
62
63 def test_get_new
63 def test_get_new
64 @request.session[:user_id] = 1
64 @request.session[:user_id] = 1
65 @project.repository.destroy
65 @project.repository.destroy
66 get :new, :project_id => 'subproject1', :repository_scm => 'Mercurial'
66 get :new, :project_id => 'subproject1', :repository_scm => 'Mercurial'
67 assert_response :success
67 assert_response :success
68 assert_template 'new'
68 assert_template 'new'
69 assert_kind_of Repository::Mercurial, assigns(:repository)
69 assert_kind_of Repository::Mercurial, assigns(:repository)
70 assert assigns(:repository).new_record?
70 assert assigns(:repository).new_record?
71 end
71 end
72
72
73 def test_show_root
73 def test_show_root
74 assert_equal 0, @repository.changesets.count
74 assert_equal 0, @repository.changesets.count
75 @repository.fetch_changesets
75 @repository.fetch_changesets
76 @project.reload
76 @project.reload
77 assert_equal NUM_REV, @repository.changesets.count
77 assert_equal NUM_REV, @repository.changesets.count
78 get :show, :id => PRJ_ID
78 get :show, :id => PRJ_ID
79 assert_response :success
79 assert_response :success
80 assert_template 'show'
80 assert_template 'show'
81 assert_not_nil assigns(:entries)
81 assert_not_nil assigns(:entries)
82 assert_equal 4, assigns(:entries).size
82 assert_equal 4, assigns(:entries).size
83 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
83 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
84 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
84 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
85 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
85 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
86 assert_not_nil assigns(:changesets)
86 assert_not_nil assigns(:changesets)
87 assert assigns(:changesets).size > 0
87 assert assigns(:changesets).size > 0
88 end
88 end
89
89
90 def test_show_directory
90 def test_show_directory
91 assert_equal 0, @repository.changesets.count
91 assert_equal 0, @repository.changesets.count
92 @repository.fetch_changesets
92 @repository.fetch_changesets
93 @project.reload
93 @project.reload
94 assert_equal NUM_REV, @repository.changesets.count
94 assert_equal NUM_REV, @repository.changesets.count
95 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param]
95 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param]
96 assert_response :success
96 assert_response :success
97 assert_template 'show'
97 assert_template 'show'
98 assert_not_nil assigns(:entries)
98 assert_not_nil assigns(:entries)
99 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
99 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
100 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
100 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
101 assert_not_nil entry
101 assert_not_nil entry
102 assert_equal 'file', entry.kind
102 assert_equal 'file', entry.kind
103 assert_equal 'images/edit.png', entry.path
103 assert_equal 'images/edit.png', entry.path
104 assert_not_nil assigns(:changesets)
104 assert_not_nil assigns(:changesets)
105 assert assigns(:changesets).size > 0
105 assert assigns(:changesets).size > 0
106 end
106 end
107
107
108 def test_show_at_given_revision
108 def test_show_at_given_revision
109 assert_equal 0, @repository.changesets.count
109 assert_equal 0, @repository.changesets.count
110 @repository.fetch_changesets
110 @repository.fetch_changesets
111 @project.reload
111 @project.reload
112 assert_equal NUM_REV, @repository.changesets.count
112 assert_equal NUM_REV, @repository.changesets.count
113 [0, '0', '0885933ad4f6'].each do |r1|
113 [0, '0', '0885933ad4f6'].each do |r1|
114 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param],
114 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param],
115 :rev => r1
115 :rev => r1
116 assert_response :success
116 assert_response :success
117 assert_template 'show'
117 assert_template 'show'
118 assert_not_nil assigns(:entries)
118 assert_not_nil assigns(:entries)
119 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
119 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
120 assert_not_nil assigns(:changesets)
120 assert_not_nil assigns(:changesets)
121 assert assigns(:changesets).size > 0
121 assert assigns(:changesets).size > 0
122 end
122 end
123 end
123 end
124
124
125 def test_show_directory_sql_escape_percent
125 def test_show_directory_sql_escape_percent
126 assert_equal 0, @repository.changesets.count
126 assert_equal 0, @repository.changesets.count
127 @repository.fetch_changesets
127 @repository.fetch_changesets
128 @project.reload
128 @project.reload
129 assert_equal NUM_REV, @repository.changesets.count
129 assert_equal NUM_REV, @repository.changesets.count
130 [13, '13', '3a330eb32958'].each do |r1|
130 [13, '13', '3a330eb32958'].each do |r1|
131 get :show, :id => PRJ_ID,
131 get :show, :id => PRJ_ID,
132 :path => repository_path_hash(['sql_escape', 'percent%dir'])[:param],
132 :path => repository_path_hash(['sql_escape', 'percent%dir'])[:param],
133 :rev => r1
133 :rev => r1
134 assert_response :success
134 assert_response :success
135 assert_template 'show'
135 assert_template 'show'
136
136
137 assert_not_nil assigns(:entries)
137 assert_not_nil assigns(:entries)
138 assert_equal ['percent%file1.txt', 'percentfile1.txt'],
138 assert_equal ['percent%file1.txt', 'percentfile1.txt'],
139 assigns(:entries).collect(&:name)
139 assigns(:entries).collect(&:name)
140 changesets = assigns(:changesets)
140 changesets = assigns(:changesets)
141 assert_not_nil changesets
141 assert_not_nil changesets
142 assert assigns(:changesets).size > 0
142 assert assigns(:changesets).size > 0
143 assert_equal %w(13 11 10 9), changesets.collect(&:revision)
143 assert_equal %w(13 11 10 9), changesets.collect(&:revision)
144 end
144 end
145 end
145 end
146
146
147 def test_show_directory_latin_1_path
147 def test_show_directory_latin_1_path
148 assert_equal 0, @repository.changesets.count
148 assert_equal 0, @repository.changesets.count
149 @repository.fetch_changesets
149 @repository.fetch_changesets
150 @project.reload
150 @project.reload
151 assert_equal NUM_REV, @repository.changesets.count
151 assert_equal NUM_REV, @repository.changesets.count
152 [21, '21', 'adf805632193'].each do |r1|
152 [21, '21', 'adf805632193'].each do |r1|
153 get :show, :id => PRJ_ID,
153 get :show, :id => PRJ_ID,
154 :path => repository_path_hash(['latin-1-dir'])[:param],
154 :path => repository_path_hash(['latin-1-dir'])[:param],
155 :rev => r1
155 :rev => r1
156 assert_response :success
156 assert_response :success
157 assert_template 'show'
157 assert_template 'show'
158
158
159 assert_not_nil assigns(:entries)
159 assert_not_nil assigns(:entries)
160 assert_equal ["make-latin-1-file.rb",
160 assert_equal ["make-latin-1-file.rb",
161 "test-#{@char_1}-1.txt",
161 "test-#{@char_1}-1.txt",
162 "test-#{@char_1}-2.txt",
162 "test-#{@char_1}-2.txt",
163 "test-#{@char_1}.txt"], assigns(:entries).collect(&:name)
163 "test-#{@char_1}.txt"], assigns(:entries).collect(&:name)
164 changesets = assigns(:changesets)
164 changesets = assigns(:changesets)
165 assert_not_nil changesets
165 assert_not_nil changesets
166 assert_equal %w(21 20 19 18 17), changesets.collect(&:revision)
166 assert_equal %w(21 20 19 18 17), changesets.collect(&:revision)
167 end
167 end
168 end
168 end
169
169
170 def show_should_show_branch_selection_form
170 def show_should_show_branch_selection_form
171 @repository.fetch_changesets
171 @repository.fetch_changesets
172 @project.reload
172 @project.reload
173 get :show, :id => PRJ_ID
173 get :show, :id => PRJ_ID
174 assert_tag 'form', :attributes => {:id => 'revision_selector', :action => '/projects/subproject1/repository/show'}
174 assert_tag 'form', :attributes => {:id => 'revision_selector', :action => '/projects/subproject1/repository/show'}
175 assert_tag 'select', :attributes => {:name => 'branch'},
175 assert_tag 'select', :attributes => {:name => 'branch'},
176 :child => {:tag => 'option', :attributes => {:value => 'test-branch-01'}},
176 :child => {:tag => 'option', :attributes => {:value => 'test-branch-01'}},
177 :parent => {:tag => 'form', :attributes => {:id => 'revision_selector'}}
177 :parent => {:tag => 'form', :attributes => {:id => 'revision_selector'}}
178 end
178 end
179
179
180 def test_show_branch
180 def test_show_branch
181 assert_equal 0, @repository.changesets.count
181 assert_equal 0, @repository.changesets.count
182 @repository.fetch_changesets
182 @repository.fetch_changesets
183 @project.reload
183 @project.reload
184 assert_equal NUM_REV, @repository.changesets.count
184 assert_equal NUM_REV, @repository.changesets.count
185 [
185 [
186 'default',
186 'default',
187 @branch_char_1,
187 @branch_char_1,
188 'branch (1)[2]&,%.-3_4',
188 'branch (1)[2]&,%.-3_4',
189 @branch_char_0,
189 @branch_char_0,
190 'test_branch.latin-1',
190 'test_branch.latin-1',
191 'test-branch-00',
191 'test-branch-00',
192 ].each do |bra|
192 ].each do |bra|
193 get :show, :id => PRJ_ID, :rev => bra
193 get :show, :id => PRJ_ID, :rev => bra
194 assert_response :success
194 assert_response :success
195 assert_template 'show'
195 assert_template 'show'
196 assert_not_nil assigns(:entries)
196 assert_not_nil assigns(:entries)
197 assert assigns(:entries).size > 0
197 assert assigns(:entries).size > 0
198 assert_not_nil assigns(:changesets)
198 assert_not_nil assigns(:changesets)
199 assert assigns(:changesets).size > 0
199 assert assigns(:changesets).size > 0
200 end
200 end
201 end
201 end
202
202
203 def test_show_tag
203 def test_show_tag
204 assert_equal 0, @repository.changesets.count
204 assert_equal 0, @repository.changesets.count
205 @repository.fetch_changesets
205 @repository.fetch_changesets
206 @project.reload
206 @project.reload
207 assert_equal NUM_REV, @repository.changesets.count
207 assert_equal NUM_REV, @repository.changesets.count
208 [
208 [
209 @tag_char_1,
209 @tag_char_1,
210 'tag_test.00',
210 'tag_test.00',
211 'tag-init-revision'
211 'tag-init-revision'
212 ].each do |tag|
212 ].each do |tag|
213 get :show, :id => PRJ_ID, :rev => tag
213 get :show, :id => PRJ_ID, :rev => tag
214 assert_response :success
214 assert_response :success
215 assert_template 'show'
215 assert_template 'show'
216 assert_not_nil assigns(:entries)
216 assert_not_nil assigns(:entries)
217 assert assigns(:entries).size > 0
217 assert assigns(:entries).size > 0
218 assert_not_nil assigns(:changesets)
218 assert_not_nil assigns(:changesets)
219 assert assigns(:changesets).size > 0
219 assert assigns(:changesets).size > 0
220 end
220 end
221 end
221 end
222
222
223 def test_changes
223 def test_changes
224 get :changes, :id => PRJ_ID,
224 get :changes, :id => PRJ_ID,
225 :path => repository_path_hash(['images', 'edit.png'])[:param]
225 :path => repository_path_hash(['images', 'edit.png'])[:param]
226 assert_response :success
226 assert_response :success
227 assert_template 'changes'
227 assert_template 'changes'
228 assert_tag :tag => 'h2', :content => 'edit.png'
228 assert_tag :tag => 'h2', :content => 'edit.png'
229 end
229 end
230
230
231 def test_entry_show
231 def test_entry_show
232 get :entry, :id => PRJ_ID,
232 get :entry, :id => PRJ_ID,
233 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
233 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
234 assert_response :success
234 assert_response :success
235 assert_template 'entry'
235 assert_template 'entry'
236 # Line 10
236 # Line 10
237 assert_tag :tag => 'th',
237 assert_tag :tag => 'th',
238 :content => '10',
238 :content => '10',
239 :attributes => { :class => 'line-num' },
239 :attributes => { :class => 'line-num' },
240 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
240 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
241 end
241 end
242
242
243 def test_entry_show_latin_1_path
243 def test_entry_show_latin_1_path
244 [21, '21', 'adf805632193'].each do |r1|
244 [21, '21', 'adf805632193'].each do |r1|
245 get :entry, :id => PRJ_ID,
245 get :entry, :id => PRJ_ID,
246 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}-2.txt"])[:param],
246 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}-2.txt"])[:param],
247 :rev => r1
247 :rev => r1
248 assert_response :success
248 assert_response :success
249 assert_template 'entry'
249 assert_template 'entry'
250 assert_tag :tag => 'th',
250 assert_tag :tag => 'th',
251 :content => '1',
251 :content => '1',
252 :attributes => { :class => 'line-num' },
252 :attributes => { :class => 'line-num' },
253 :sibling => { :tag => 'td',
253 :sibling => { :tag => 'td',
254 :content => /Mercurial is a distributed version control system/ }
254 :content => /Mercurial is a distributed version control system/ }
255 end
255 end
256 end
256 end
257
257
258 def test_entry_show_latin_1_contents
258 def test_entry_show_latin_1_contents
259 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
259 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
260 [27, '27', '7bbf4c738e71'].each do |r1|
260 [27, '27', '7bbf4c738e71'].each do |r1|
261 get :entry, :id => PRJ_ID,
261 get :entry, :id => PRJ_ID,
262 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
262 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
263 :rev => r1
263 :rev => r1
264 assert_response :success
264 assert_response :success
265 assert_template 'entry'
265 assert_template 'entry'
266 assert_tag :tag => 'th',
266 assert_tag :tag => 'th',
267 :content => '1',
267 :content => '1',
268 :attributes => { :class => 'line-num' },
268 :attributes => { :class => 'line-num' },
269 :sibling => { :tag => 'td',
269 :sibling => { :tag => 'td',
270 :content => /test-#{@char_1}.txt/ }
270 :content => /test-#{@char_1}.txt/ }
271 end
271 end
272 end
272 end
273 end
273 end
274
274
275 def test_entry_download
275 def test_entry_download
276 get :entry, :id => PRJ_ID,
276 get :entry, :id => PRJ_ID,
277 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
277 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
278 :format => 'raw'
278 :format => 'raw'
279 assert_response :success
279 assert_response :success
280 # File content
280 # File content
281 assert @response.body.include?('WITHOUT ANY WARRANTY')
281 assert @response.body.include?('WITHOUT ANY WARRANTY')
282 end
282 end
283
283
284 def test_entry_binary_force_download
284 def test_entry_binary_force_download
285 get :entry, :id => PRJ_ID, :rev => 1,
285 get :entry, :id => PRJ_ID, :rev => 1,
286 :path => repository_path_hash(['images', 'edit.png'])[:param]
286 :path => repository_path_hash(['images', 'edit.png'])[:param]
287 assert_response :success
287 assert_response :success
288 assert_equal 'image/png', @response.content_type
288 assert_equal 'image/png', @response.content_type
289 end
289 end
290
290
291 def test_directory_entry
291 def test_directory_entry
292 get :entry, :id => PRJ_ID,
292 get :entry, :id => PRJ_ID,
293 :path => repository_path_hash(['sources'])[:param]
293 :path => repository_path_hash(['sources'])[:param]
294 assert_response :success
294 assert_response :success
295 assert_template 'show'
295 assert_template 'show'
296 assert_not_nil assigns(:entry)
296 assert_not_nil assigns(:entry)
297 assert_equal 'sources', assigns(:entry).name
297 assert_equal 'sources', assigns(:entry).name
298 end
298 end
299
299
300 def test_diff
300 def test_diff
301 assert_equal 0, @repository.changesets.count
301 assert_equal 0, @repository.changesets.count
302 @repository.fetch_changesets
302 @repository.fetch_changesets
303 @project.reload
303 @project.reload
304 assert_equal NUM_REV, @repository.changesets.count
304 assert_equal NUM_REV, @repository.changesets.count
305 [4, '4', 'def6d2f1254a'].each do |r1|
305 [4, '4', 'def6d2f1254a'].each do |r1|
306 # Full diff of changeset 4
306 # Full diff of changeset 4
307 ['inline', 'sbs'].each do |dt|
307 ['inline', 'sbs'].each do |dt|
308 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
308 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
309 assert_response :success
309 assert_response :success
310 assert_template 'diff'
310 assert_template 'diff'
311 if @diff_c_support
311 if @diff_c_support
312 # Line 22 removed
312 # Line 22 removed
313 assert_tag :tag => 'th',
313 assert_tag :tag => 'th',
314 :content => '22',
314 :content => '22',
315 :sibling => { :tag => 'td',
315 :sibling => { :tag => 'td',
316 :attributes => { :class => /diff_out/ },
316 :attributes => { :class => /diff_out/ },
317 :content => /def remove/ }
317 :content => /def remove/ }
318 assert_tag :tag => 'h2', :content => /4:def6d2f1254a/
318 assert_tag :tag => 'h2', :content => /4:def6d2f1254a/
319 end
319 end
320 end
320 end
321 end
321 end
322 end
322 end
323
323
324 def test_diff_two_revs
324 def test_diff_two_revs
325 assert_equal 0, @repository.changesets.count
325 assert_equal 0, @repository.changesets.count
326 @repository.fetch_changesets
326 @repository.fetch_changesets
327 @project.reload
327 @project.reload
328 assert_equal NUM_REV, @repository.changesets.count
328 assert_equal NUM_REV, @repository.changesets.count
329 [2, '400bb8672109', '400', 400].each do |r1|
329 [2, '400bb8672109', '400', 400].each do |r1|
330 [4, 'def6d2f1254a'].each do |r2|
330 [4, 'def6d2f1254a'].each do |r2|
331 ['inline', 'sbs'].each do |dt|
331 ['inline', 'sbs'].each do |dt|
332 get :diff,
332 get :diff,
333 :id => PRJ_ID,
333 :id => PRJ_ID,
334 :rev => r1,
334 :rev => r1,
335 :rev_to => r2,
335 :rev_to => r2,
336 :type => dt
336 :type => dt
337 assert_response :success
337 assert_response :success
338 assert_template 'diff'
338 assert_template 'diff'
339 diff = assigns(:diff)
339 diff = assigns(:diff)
340 assert_not_nil diff
340 assert_not_nil diff
341 assert_tag :tag => 'h2',
341 assert_tag :tag => 'h2',
342 :content => /4:def6d2f1254a 2:400bb8672109/
342 :content => /4:def6d2f1254a 2:400bb8672109/
343 end
343 end
344 end
344 end
345 end
345 end
346 end
346 end
347
347
348 def test_diff_latin_1_path
348 def test_diff_latin_1_path
349 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
349 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
350 [21, 'adf805632193'].each do |r1|
350 [21, 'adf805632193'].each do |r1|
351 ['inline', 'sbs'].each do |dt|
351 ['inline', 'sbs'].each do |dt|
352 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
352 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
353 assert_response :success
353 assert_response :success
354 assert_template 'diff'
354 assert_template 'diff'
355 assert_tag :tag => 'thead',
355 assert_tag :tag => 'thead',
356 :descendant => {
356 :descendant => {
357 :tag => 'th',
357 :tag => 'th',
358 :attributes => { :class => 'filename' } ,
358 :attributes => { :class => 'filename' } ,
359 :content => /latin-1-dir\/test-#{@char_1}-2.txt/ ,
359 :content => /latin-1-dir\/test-#{@char_1}-2.txt/ ,
360 },
360 },
361 :sibling => {
361 :sibling => {
362 :tag => 'tbody',
362 :tag => 'tbody',
363 :descendant => {
363 :descendant => {
364 :tag => 'td',
364 :tag => 'td',
365 :attributes => { :class => /diff_in/ },
365 :attributes => { :class => /diff_in/ },
366 :content => /It is written in Python/
366 :content => /It is written in Python/
367 }
367 }
368 }
368 }
369 end
369 end
370 end
370 end
371 end
371 end
372 end
372 end
373
373
374 def test_diff_should_show_modified_filenames
374 def test_diff_should_show_modified_filenames
375 get :diff, :id => PRJ_ID, :rev => '400bb8672109', :type => 'inline'
375 get :diff, :id => PRJ_ID, :rev => '400bb8672109', :type => 'inline'
376 assert_response :success
376 assert_response :success
377 assert_template 'diff'
377 assert_template 'diff'
378 assert_select 'th.filename', :text => 'sources/watchers_controller.rb'
378 assert_select 'th.filename', :text => 'sources/watchers_controller.rb'
379 end
379 end
380
380
381 def test_diff_should_show_deleted_filenames
381 def test_diff_should_show_deleted_filenames
382 get :diff, :id => PRJ_ID, :rev => 'b3a615152df8', :type => 'inline'
382 get :diff, :id => PRJ_ID, :rev => 'b3a615152df8', :type => 'inline'
383 assert_response :success
383 assert_response :success
384 assert_template 'diff'
384 assert_template 'diff'
385 assert_select 'th.filename', :text => 'sources/welcome_controller.rb'
385 assert_select 'th.filename', :text => 'sources/welcome_controller.rb'
386 end
386 end
387
387
388 def test_annotate
388 def test_annotate
389 get :annotate, :id => PRJ_ID,
389 get :annotate, :id => PRJ_ID,
390 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
390 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
391 assert_response :success
391 assert_response :success
392 assert_template 'annotate'
392 assert_template 'annotate'
393
393
394 # Line 22, revision 4:def6d2f1254a
394 # Line 22, revision 4:def6d2f1254a
395 assert_select 'tr' do
395 assert_select 'tr' do
396 assert_select 'th.line-num', :text => '22'
396 assert_select 'th.line-num', :text => '22'
397 assert_select 'td.revision', :text => '4:def6d2f1254a'
397 assert_select 'td.revision', :text => '4:def6d2f1254a'
398 assert_select 'td.author', :text => 'jsmith'
398 assert_select 'td.author', :text => 'jsmith'
399 assert_select 'td', :text => /remove_watcher/
399 assert_select 'td', :text => /remove_watcher/
400 end
400 end
401 end
401 end
402
402
403 def test_annotate_not_in_tip
403 def test_annotate_not_in_tip
404 assert_equal 0, @repository.changesets.count
404 assert_equal 0, @repository.changesets.count
405 @repository.fetch_changesets
405 @repository.fetch_changesets
406 @project.reload
406 @project.reload
407 assert_equal NUM_REV, @repository.changesets.count
407 assert_equal NUM_REV, @repository.changesets.count
408 get :annotate, :id => PRJ_ID,
408 get :annotate, :id => PRJ_ID,
409 :path => repository_path_hash(['sources', 'welcome_controller.rb'])[:param]
409 :path => repository_path_hash(['sources', 'welcome_controller.rb'])[:param]
410 assert_response 404
410 assert_response 404
411 assert_error_tag :content => /was not found/
411 assert_error_tag :content => /was not found/
412 end
412 end
413
413
414 def test_annotate_at_given_revision
414 def test_annotate_at_given_revision
415 assert_equal 0, @repository.changesets.count
415 assert_equal 0, @repository.changesets.count
416 @repository.fetch_changesets
416 @repository.fetch_changesets
417 @project.reload
417 @project.reload
418 assert_equal NUM_REV, @repository.changesets.count
418 assert_equal NUM_REV, @repository.changesets.count
419 [2, '400bb8672109', '400', 400].each do |r1|
419 [2, '400bb8672109', '400', 400].each do |r1|
420 get :annotate, :id => PRJ_ID, :rev => r1,
420 get :annotate, :id => PRJ_ID, :rev => r1,
421 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
421 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
422 assert_response :success
422 assert_response :success
423 assert_template 'annotate'
423 assert_template 'annotate'
424 assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/
424 assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/
425 end
425 end
426 end
426 end
427
427
428 def test_annotate_latin_1_path
428 def test_annotate_latin_1_path
429 [21, '21', 'adf805632193'].each do |r1|
429 [21, '21', 'adf805632193'].each do |r1|
430 get :annotate, :id => PRJ_ID,
430 get :annotate, :id => PRJ_ID,
431 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}-2.txt"])[:param],
431 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}-2.txt"])[:param],
432 :rev => r1
432 :rev => r1
433 assert_response :success
433 assert_response :success
434 assert_template 'annotate'
434 assert_template 'annotate'
435 assert_select "th.line-num", :text => '1' do
435 assert_select "th.line-num", :text => '1' do
436 assert_select "+ td.revision" do
436 assert_select "+ td.revision" do
437 assert_select "a", :text => '20:709858aafd1b'
437 assert_select "a", :text => '20:709858aafd1b'
438 assert_select "+ td.author", :text => "jsmith" do
438 assert_select "+ td.author", :text => "jsmith" do
439 assert_select "+ td",
439 assert_select "+ td",
440 :text => "Mercurial is a distributed version control system."
440 :text => "Mercurial is a distributed version control system."
441 end
441 end
442 end
442 end
443 end
443 end
444 end
444 end
445 end
445 end
446
446
447 def test_annotate_latin_1_contents
447 def test_annotate_latin_1_contents
448 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
448 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
449 [27, '7bbf4c738e71'].each do |r1|
449 [27, '7bbf4c738e71'].each do |r1|
450 get :annotate, :id => PRJ_ID,
450 get :annotate, :id => PRJ_ID,
451 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
451 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
452 :rev => r1
452 :rev => r1
453 assert_tag :tag => 'th',
453 assert_tag :tag => 'th',
454 :content => '1',
454 :content => '1',
455 :attributes => { :class => 'line-num' },
455 :attributes => { :class => 'line-num' },
456 :sibling => { :tag => 'td',
456 :sibling => { :tag => 'td',
457 :content => /test-#{@char_1}.txt/ }
457 :content => /test-#{@char_1}.txt/ }
458 end
458 end
459 end
459 end
460 end
460 end
461
461
462 def test_revision
462 def test_revision
463 assert_equal 0, @repository.changesets.count
463 assert_equal 0, @repository.changesets.count
464 @repository.fetch_changesets
464 @repository.fetch_changesets
465 @project.reload
465 @project.reload
466 assert_equal NUM_REV, @repository.changesets.count
466 assert_equal NUM_REV, @repository.changesets.count
467 ['1', '9d5b5b', '9d5b5b004199'].each do |r|
467 ['1', '9d5b5b', '9d5b5b004199'].each do |r|
468 with_settings :default_language => "en" do
468 with_settings :default_language => "en" do
469 get :revision, :id => PRJ_ID, :rev => r
469 get :revision, :id => PRJ_ID, :rev => r
470 assert_response :success
470 assert_response :success
471 assert_template 'revision'
471 assert_template 'revision'
472 assert_select 'title',
472 assert_select 'title',
473 :text => 'Revision 1:9d5b5b004199 - Added 2 files and modified one. - eCookbook Subproject 1 - Redmine'
473 :text => 'Revision 1:9d5b5b004199 - Added 2 files and modified one. - eCookbook Subproject 1 - Redmine'
474 end
474 end
475 end
475 end
476 end
476 end
477
477
478 def test_empty_revision
478 def test_empty_revision
479 assert_equal 0, @repository.changesets.count
479 assert_equal 0, @repository.changesets.count
480 @repository.fetch_changesets
480 @repository.fetch_changesets
481 @project.reload
481 @project.reload
482 assert_equal NUM_REV, @repository.changesets.count
482 assert_equal NUM_REV, @repository.changesets.count
483 ['', ' ', nil].each do |r|
483 ['', ' ', nil].each do |r|
484 get :revision, :id => PRJ_ID, :rev => r
484 get :revision, :id => PRJ_ID, :rev => r
485 assert_response 404
485 assert_response 404
486 assert_error_tag :content => /was not found/
486 assert_error_tag :content => /was not found/
487 end
487 end
488 end
488 end
489
489
490 def test_destroy_valid_repository
490 def test_destroy_valid_repository
491 @request.session[:user_id] = 1 # admin
491 @request.session[:user_id] = 1 # admin
492 assert_equal 0, @repository.changesets.count
492 assert_equal 0, @repository.changesets.count
493 @repository.fetch_changesets
493 @repository.fetch_changesets
494 assert_equal NUM_REV, @repository.changesets.count
494 assert_equal NUM_REV, @repository.changesets.count
495
495
496 assert_difference 'Repository.count', -1 do
496 assert_difference 'Repository.count', -1 do
497 delete :destroy, :id => @repository.id
497 delete :destroy, :id => @repository.id
498 end
498 end
499 assert_response 302
499 assert_response 302
500 @project.reload
500 @project.reload
501 assert_nil @project.repository
501 assert_nil @project.repository
502 end
502 end
503
503
504 def test_destroy_invalid_repository
504 def test_destroy_invalid_repository
505 @request.session[:user_id] = 1 # admin
505 @request.session[:user_id] = 1 # admin
506 @project.repository.destroy
506 @project.repository.destroy
507 @repository = Repository::Mercurial.create!(
507 @repository = Repository::Mercurial.create!(
508 :project => Project.find(PRJ_ID),
508 :project => Project.find(PRJ_ID),
509 :url => "/invalid",
509 :url => "/invalid",
510 :path_encoding => 'ISO-8859-1'
510 :path_encoding => 'ISO-8859-1'
511 )
511 )
512 @repository.fetch_changesets
512 @repository.fetch_changesets
513 assert_equal 0, @repository.changesets.count
513 assert_equal 0, @repository.changesets.count
514
514
515 assert_difference 'Repository.count', -1 do
515 assert_difference 'Repository.count', -1 do
516 delete :destroy, :id => @repository.id
516 delete :destroy, :id => @repository.id
517 end
517 end
518 assert_response 302
518 assert_response 302
519 @project.reload
519 @project.reload
520 assert_nil @project.repository
520 assert_nil @project.repository
521 end
521 end
522 else
522 else
523 puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
523 puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
524 def test_fake; assert true end
524 def test_fake; assert true end
525 end
525 end
526 end
526 end
@@ -1,475 +1,475
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2014 Jean-Philippe Lang
2 # Copyright (C) 2006-2014 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 begin
19 begin
20 require 'mocha/setup'
20 require 'mocha/setup'
21
21
22 class MercurialAdapterTest < ActiveSupport::TestCase
22 class MercurialAdapterTest < ActiveSupport::TestCase
23 HELPERS_DIR = Redmine::Scm::Adapters::MercurialAdapter::HELPERS_DIR
23 HELPERS_DIR = Redmine::Scm::Adapters::MercurialAdapter::HELPERS_DIR
24 TEMPLATE_NAME = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_NAME
24 TEMPLATE_NAME = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_NAME
25 TEMPLATE_EXTENSION = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_EXTENSION
25 TEMPLATE_EXTENSION = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_EXTENSION
26
26
27 REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s
27 REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s
28 CHAR_1_HEX = "\xc3\x9c"
28 CHAR_1_HEX = "\xc3\x9c"
29
29
30 if File.directory?(REPOSITORY_PATH)
30 if File.directory?(REPOSITORY_PATH)
31 def setup
31 def setup
32 adapter_class = Redmine::Scm::Adapters::MercurialAdapter
32 adapter_class = Redmine::Scm::Adapters::MercurialAdapter
33 assert adapter_class
33 assert adapter_class
34 assert adapter_class.client_command
34 assert adapter_class.client_command
35 assert_equal true, adapter_class.client_available
35 assert_equal true, adapter_class.client_available
36 assert_equal true, adapter_class.client_version_above?([0, 9, 5])
36 assert_equal true, adapter_class.client_version_above?([0, 9, 5])
37
37
38 @adapter = Redmine::Scm::Adapters::MercurialAdapter.new(
38 @adapter = Redmine::Scm::Adapters::MercurialAdapter.new(
39 REPOSITORY_PATH,
39 REPOSITORY_PATH,
40 nil,
40 nil,
41 nil,
41 nil,
42 nil,
42 nil,
43 'ISO-8859-1')
43 'ISO-8859-1')
44 @diff_c_support = true
44 @diff_c_support = true
45 @char_1 = CHAR_1_HEX.dup
45 @char_1 = CHAR_1_HEX.dup
46 @tag_char_1 = "tag-#{CHAR_1_HEX}-00"
46 @tag_char_1 = "tag-#{CHAR_1_HEX}-00"
47 @branch_char_0 = "branch-#{CHAR_1_HEX}-00"
47 @branch_char_0 = "branch-#{CHAR_1_HEX}-00"
48 @branch_char_1 = "branch-#{CHAR_1_HEX}-01"
48 @branch_char_1 = "branch-#{CHAR_1_HEX}-01"
49 if @tag_char_1.respond_to?(:force_encoding)
49 if @tag_char_1.respond_to?(:force_encoding)
50 @char_1.force_encoding('UTF-8')
50 @char_1.force_encoding('UTF-8')
51 @tag_char_1.force_encoding('UTF-8')
51 @tag_char_1.force_encoding('UTF-8')
52 @branch_char_0.force_encoding('UTF-8')
52 @branch_char_0.force_encoding('UTF-8')
53 @branch_char_1.force_encoding('UTF-8')
53 @branch_char_1.force_encoding('UTF-8')
54 end
54 end
55 end
55 end
56
56
57 def test_hgversion
57 def test_hgversion
58 to_test = { "Mercurial Distributed SCM (version 0.9.5)\n" => [0,9,5],
58 to_test = { "Mercurial Distributed SCM (version 0.9.5)\n" => [0,9,5],
59 "Mercurial Distributed SCM (1.0)\n" => [1,0],
59 "Mercurial Distributed SCM (1.0)\n" => [1,0],
60 "Mercurial Distributed SCM (1e4ddc9ac9f7+20080325)\n" => nil,
60 "Mercurial Distributed SCM (1e4ddc9ac9f7+20080325)\n" => nil,
61 "Mercurial Distributed SCM (1.0.1+20080525)\n" => [1,0,1],
61 "Mercurial Distributed SCM (1.0.1+20080525)\n" => [1,0,1],
62 "Mercurial Distributed SCM (1916e629a29d)\n" => nil,
62 "Mercurial Distributed SCM (1916e629a29d)\n" => nil,
63 "Mercurial SCM Distribuito (versione 0.9.5)\n" => [0,9,5],
63 "Mercurial SCM Distribuito (versione 0.9.5)\n" => [0,9,5],
64 "(1.6)\n(1.7)\n(1.8)" => [1,6],
64 "(1.6)\n(1.7)\n(1.8)" => [1,6],
65 "(1.7.1)\r\n(1.8.1)\r\n(1.9.1)" => [1,7,1]}
65 "(1.7.1)\r\n(1.8.1)\r\n(1.9.1)" => [1,7,1]}
66
66
67 to_test.each do |s, v|
67 to_test.each do |s, v|
68 test_hgversion_for(s, v)
68 test_hgversion_for(s, v)
69 end
69 end
70 end
70 end
71
71
72 def test_template_path
72 def test_template_path
73 to_test = {
73 to_test = {
74 [1,2] => "1.0",
74 [1,2] => "1.0",
75 [] => "1.0",
75 [] => "1.0",
76 [1,2,1] => "1.0",
76 [1,2,1] => "1.0",
77 [1,7] => "1.0",
77 [1,7] => "1.0",
78 [1,7,1] => "1.0",
78 [1,7,1] => "1.0",
79 [2,0] => "1.0",
79 [2,0] => "1.0",
80 }
80 }
81 to_test.each do |v, template|
81 to_test.each do |v, template|
82 test_template_path_for(v, template)
82 test_template_path_for(v, template)
83 end
83 end
84 end
84 end
85
85
86 def test_info
86 def test_info
87 [REPOSITORY_PATH, REPOSITORY_PATH + "/",
87 [REPOSITORY_PATH, REPOSITORY_PATH + "/",
88 REPOSITORY_PATH + "//"].each do |repo|
88 REPOSITORY_PATH + "//"].each do |repo|
89 adp = Redmine::Scm::Adapters::MercurialAdapter.new(repo)
89 adp = Redmine::Scm::Adapters::MercurialAdapter.new(repo)
90 repo_path = adp.info.root_url.gsub(/\\/, "/")
90 repo_path = adp.info.root_url.gsub(/\\/, "/")
91 assert_equal REPOSITORY_PATH, repo_path
91 assert_equal REPOSITORY_PATH, repo_path
92 assert_equal '31', adp.info.lastrev.revision
92 assert_equal '33', adp.info.lastrev.revision
93 assert_equal '31eeee7395c8c78e66dd54c50addd078d10b2355',adp.info.lastrev.scmid
93 assert_equal '2e6d546429230f377d7d19c2078abd2dd909f235',adp.info.lastrev.scmid
94 end
94 end
95 end
95 end
96
96
97 def test_revisions
97 def test_revisions
98 revisions = @adapter.revisions(nil, 2, 4)
98 revisions = @adapter.revisions(nil, 2, 4)
99 assert_equal 3, revisions.size
99 assert_equal 3, revisions.size
100 assert_equal '2', revisions[0].revision
100 assert_equal '2', revisions[0].revision
101 assert_equal '400bb86721098697c7d17b3724c794c57636de70', revisions[0].scmid
101 assert_equal '400bb86721098697c7d17b3724c794c57636de70', revisions[0].scmid
102 assert_equal '4', revisions[2].revision
102 assert_equal '4', revisions[2].revision
103 assert_equal 'def6d2f1254a56fb8fbe9ec3b5c0451674dbd8b8', revisions[2].scmid
103 assert_equal 'def6d2f1254a56fb8fbe9ec3b5c0451674dbd8b8', revisions[2].scmid
104
104
105 revisions = @adapter.revisions(nil, 2, 4, {:limit => 2})
105 revisions = @adapter.revisions(nil, 2, 4, {:limit => 2})
106 assert_equal 2, revisions.size
106 assert_equal 2, revisions.size
107 assert_equal '2', revisions[0].revision
107 assert_equal '2', revisions[0].revision
108 assert_equal '400bb86721098697c7d17b3724c794c57636de70', revisions[0].scmid
108 assert_equal '400bb86721098697c7d17b3724c794c57636de70', revisions[0].scmid
109 end
109 end
110
110
111 def test_parents
111 def test_parents
112 revs1 = @adapter.revisions(nil, 0, 0)
112 revs1 = @adapter.revisions(nil, 0, 0)
113 assert_equal 1, revs1.size
113 assert_equal 1, revs1.size
114 assert_equal [], revs1[0].parents
114 assert_equal [], revs1[0].parents
115 revs2 = @adapter.revisions(nil, 1, 1)
115 revs2 = @adapter.revisions(nil, 1, 1)
116 assert_equal 1, revs2.size
116 assert_equal 1, revs2.size
117 assert_equal 1, revs2[0].parents.size
117 assert_equal 1, revs2[0].parents.size
118 assert_equal "0885933ad4f68d77c2649cd11f8311276e7ef7ce", revs2[0].parents[0]
118 assert_equal "0885933ad4f68d77c2649cd11f8311276e7ef7ce", revs2[0].parents[0]
119 revs3 = @adapter.revisions(nil, 30, 30)
119 revs3 = @adapter.revisions(nil, 30, 30)
120 assert_equal 1, revs3.size
120 assert_equal 1, revs3.size
121 assert_equal 2, revs3[0].parents.size
121 assert_equal 2, revs3[0].parents.size
122 assert_equal "a94b0528f24fe05ebaef496ae0500bb050772e36", revs3[0].parents[0]
122 assert_equal "a94b0528f24fe05ebaef496ae0500bb050772e36", revs3[0].parents[0]
123 assert_equal "3a330eb329586ea2adb3f83237c23310e744ebe9", revs3[0].parents[1]
123 assert_equal "3a330eb329586ea2adb3f83237c23310e744ebe9", revs3[0].parents[1]
124 end
124 end
125
125
126 def test_diff
126 def test_diff
127 if @adapter.class.client_version_above?([1, 2])
127 if @adapter.class.client_version_above?([1, 2])
128 assert_nil @adapter.diff(nil, '100000')
128 assert_nil @adapter.diff(nil, '100000')
129 end
129 end
130 assert_nil @adapter.diff(nil, '100000', '200000')
130 assert_nil @adapter.diff(nil, '100000', '200000')
131 [2, '400bb8672109', '400', 400].each do |r1|
131 [2, '400bb8672109', '400', 400].each do |r1|
132 diff1 = @adapter.diff(nil, r1)
132 diff1 = @adapter.diff(nil, r1)
133 if @diff_c_support
133 if @diff_c_support
134 assert_equal 28, diff1.size
134 assert_equal 28, diff1.size
135 buf = diff1[24].gsub(/\r\n|\r|\n/, "")
135 buf = diff1[24].gsub(/\r\n|\r|\n/, "")
136 assert_equal "+ return true unless klass.respond_to?('watched_by')", buf
136 assert_equal "+ return true unless klass.respond_to?('watched_by')", buf
137 else
137 else
138 assert_equal 0, diff1.size
138 assert_equal 0, diff1.size
139 end
139 end
140 [4, 'def6d2f1254a'].each do |r2|
140 [4, 'def6d2f1254a'].each do |r2|
141 diff2 = @adapter.diff(nil, r1, r2)
141 diff2 = @adapter.diff(nil, r1, r2)
142 assert_equal 49, diff2.size
142 assert_equal 49, diff2.size
143 buf = diff2[41].gsub(/\r\n|\r|\n/, "")
143 buf = diff2[41].gsub(/\r\n|\r|\n/, "")
144 assert_equal "+class WelcomeController < ApplicationController", buf
144 assert_equal "+class WelcomeController < ApplicationController", buf
145 diff3 = @adapter.diff('sources/watchers_controller.rb', r1, r2)
145 diff3 = @adapter.diff('sources/watchers_controller.rb', r1, r2)
146 assert_equal 20, diff3.size
146 assert_equal 20, diff3.size
147 buf = diff3[12].gsub(/\r\n|\r|\n/, "")
147 buf = diff3[12].gsub(/\r\n|\r|\n/, "")
148 assert_equal "+ @watched.remove_watcher(user)", buf
148 assert_equal "+ @watched.remove_watcher(user)", buf
149
149
150 diff4 = @adapter.diff(nil, r2, r1)
150 diff4 = @adapter.diff(nil, r2, r1)
151 assert_equal 49, diff4.size
151 assert_equal 49, diff4.size
152 buf = diff4[41].gsub(/\r\n|\r|\n/, "")
152 buf = diff4[41].gsub(/\r\n|\r|\n/, "")
153 assert_equal "-class WelcomeController < ApplicationController", buf
153 assert_equal "-class WelcomeController < ApplicationController", buf
154 diff5 = @adapter.diff('sources/watchers_controller.rb', r2, r1)
154 diff5 = @adapter.diff('sources/watchers_controller.rb', r2, r1)
155 assert_equal 20, diff5.size
155 assert_equal 20, diff5.size
156 buf = diff5[9].gsub(/\r\n|\r|\n/, "")
156 buf = diff5[9].gsub(/\r\n|\r|\n/, "")
157 assert_equal "- @watched.remove_watcher(user)", buf
157 assert_equal "- @watched.remove_watcher(user)", buf
158 end
158 end
159 end
159 end
160 end
160 end
161
161
162 def test_diff_made_by_revision
162 def test_diff_made_by_revision
163 if @diff_c_support
163 if @diff_c_support
164 [24, '24', '4cddb4e45f52'].each do |r1|
164 [24, '24', '4cddb4e45f52'].each do |r1|
165 diff1 = @adapter.diff(nil, r1)
165 diff1 = @adapter.diff(nil, r1)
166 assert_equal 5, diff1.size
166 assert_equal 5, diff1.size
167 buf = diff1[4].gsub(/\r\n|\r|\n/, "")
167 buf = diff1[4].gsub(/\r\n|\r|\n/, "")
168 assert_equal '+0885933ad4f68d77c2649cd11f8311276e7ef7ce tag-init-revision', buf
168 assert_equal '+0885933ad4f68d77c2649cd11f8311276e7ef7ce tag-init-revision', buf
169 end
169 end
170 end
170 end
171 end
171 end
172
172
173 def test_cat
173 def test_cat
174 [2, '400bb8672109', '400', 400].each do |r|
174 [2, '400bb8672109', '400', 400].each do |r|
175 buf = @adapter.cat('sources/welcome_controller.rb', r)
175 buf = @adapter.cat('sources/welcome_controller.rb', r)
176 assert buf
176 assert buf
177 lines = buf.split("\r\n")
177 lines = buf.split("\r\n")
178 assert_equal 25, lines.length
178 assert_equal 25, lines.length
179 assert_equal 'class WelcomeController < ApplicationController', lines[17]
179 assert_equal 'class WelcomeController < ApplicationController', lines[17]
180 end
180 end
181 assert_nil @adapter.cat('sources/welcome_controller.rb')
181 assert_nil @adapter.cat('sources/welcome_controller.rb')
182 end
182 end
183
183
184 def test_annotate
184 def test_annotate
185 assert_equal [], @adapter.annotate("sources/welcome_controller.rb").lines
185 assert_equal [], @adapter.annotate("sources/welcome_controller.rb").lines
186 [2, '400bb8672109', '400', 400].each do |r|
186 [2, '400bb8672109', '400', 400].each do |r|
187 ann = @adapter.annotate('sources/welcome_controller.rb', r)
187 ann = @adapter.annotate('sources/welcome_controller.rb', r)
188 assert ann
188 assert ann
189 assert_equal '1', ann.revisions[17].revision
189 assert_equal '1', ann.revisions[17].revision
190 assert_equal '9d5b5b004199', ann.revisions[17].identifier
190 assert_equal '9d5b5b004199', ann.revisions[17].identifier
191 assert_equal 'jsmith', ann.revisions[0].author
191 assert_equal 'jsmith', ann.revisions[0].author
192 assert_equal 25, ann.lines.length
192 assert_equal 25, ann.lines.length
193 assert_equal 'class WelcomeController < ApplicationController', ann.lines[17]
193 assert_equal 'class WelcomeController < ApplicationController', ann.lines[17]
194 end
194 end
195 end
195 end
196
196
197 def test_entries
197 def test_entries
198 assert_nil @adapter.entries(nil, '100000')
198 assert_nil @adapter.entries(nil, '100000')
199
199
200 assert_equal 1, @adapter.entries("sources", 3).size
200 assert_equal 1, @adapter.entries("sources", 3).size
201 assert_equal 1, @adapter.entries("sources", 'b3a615152df8').size
201 assert_equal 1, @adapter.entries("sources", 'b3a615152df8').size
202
202
203 [2, '400bb8672109', '400', 400].each do |r|
203 [2, '400bb8672109', '400', 400].each do |r|
204 entries1 = @adapter.entries(nil, r)
204 entries1 = @adapter.entries(nil, r)
205 assert entries1
205 assert entries1
206 assert_equal 3, entries1.size
206 assert_equal 3, entries1.size
207 assert_equal 'sources', entries1[1].name
207 assert_equal 'sources', entries1[1].name
208 assert_equal 'sources', entries1[1].path
208 assert_equal 'sources', entries1[1].path
209 assert_equal 'dir', entries1[1].kind
209 assert_equal 'dir', entries1[1].kind
210 readme = entries1[2]
210 readme = entries1[2]
211 assert_equal 'README', readme.name
211 assert_equal 'README', readme.name
212 assert_equal 'README', readme.path
212 assert_equal 'README', readme.path
213 assert_equal 'file', readme.kind
213 assert_equal 'file', readme.kind
214 assert_equal 27, readme.size
214 assert_equal 27, readme.size
215 assert_equal '1', readme.lastrev.revision
215 assert_equal '1', readme.lastrev.revision
216 assert_equal '9d5b5b00419901478496242e0768deba1ce8c51e', readme.lastrev.identifier
216 assert_equal '9d5b5b00419901478496242e0768deba1ce8c51e', readme.lastrev.identifier
217 # 2007-12-14 10:24:01 +0100
217 # 2007-12-14 10:24:01 +0100
218 assert_equal Time.gm(2007, 12, 14, 9, 24, 1), readme.lastrev.time
218 assert_equal Time.gm(2007, 12, 14, 9, 24, 1), readme.lastrev.time
219
219
220 entries2 = @adapter.entries('sources', r)
220 entries2 = @adapter.entries('sources', r)
221 assert entries2
221 assert entries2
222 assert_equal 2, entries2.size
222 assert_equal 2, entries2.size
223 assert_equal 'watchers_controller.rb', entries2[0].name
223 assert_equal 'watchers_controller.rb', entries2[0].name
224 assert_equal 'sources/watchers_controller.rb', entries2[0].path
224 assert_equal 'sources/watchers_controller.rb', entries2[0].path
225 assert_equal 'file', entries2[0].kind
225 assert_equal 'file', entries2[0].kind
226 assert_equal 'welcome_controller.rb', entries2[1].name
226 assert_equal 'welcome_controller.rb', entries2[1].name
227 assert_equal 'sources/welcome_controller.rb', entries2[1].path
227 assert_equal 'sources/welcome_controller.rb', entries2[1].path
228 assert_equal 'file', entries2[1].kind
228 assert_equal 'file', entries2[1].kind
229 end
229 end
230 end
230 end
231
231
232 def test_entries_tag
232 def test_entries_tag
233 entries1 = @adapter.entries(nil, 'tag_test.00')
233 entries1 = @adapter.entries(nil, 'tag_test.00')
234 assert entries1
234 assert entries1
235 assert_equal 3, entries1.size
235 assert_equal 3, entries1.size
236 assert_equal 'sources', entries1[1].name
236 assert_equal 'sources', entries1[1].name
237 assert_equal 'sources', entries1[1].path
237 assert_equal 'sources', entries1[1].path
238 assert_equal 'dir', entries1[1].kind
238 assert_equal 'dir', entries1[1].kind
239 readme = entries1[2]
239 readme = entries1[2]
240 assert_equal 'README', readme.name
240 assert_equal 'README', readme.name
241 assert_equal 'README', readme.path
241 assert_equal 'README', readme.path
242 assert_equal 'file', readme.kind
242 assert_equal 'file', readme.kind
243 assert_equal 21, readme.size
243 assert_equal 21, readme.size
244 assert_equal '0', readme.lastrev.revision
244 assert_equal '0', readme.lastrev.revision
245 assert_equal '0885933ad4f68d77c2649cd11f8311276e7ef7ce', readme.lastrev.identifier
245 assert_equal '0885933ad4f68d77c2649cd11f8311276e7ef7ce', readme.lastrev.identifier
246 # 2007-12-14 10:22:52 +0100
246 # 2007-12-14 10:22:52 +0100
247 assert_equal Time.gm(2007, 12, 14, 9, 22, 52), readme.lastrev.time
247 assert_equal Time.gm(2007, 12, 14, 9, 22, 52), readme.lastrev.time
248 end
248 end
249
249
250 def test_entries_branch
250 def test_entries_branch
251 entries1 = @adapter.entries(nil, 'test-branch-00')
251 entries1 = @adapter.entries(nil, 'test-branch-00')
252 assert entries1
252 assert entries1
253 assert_equal 5, entries1.size
253 assert_equal 5, entries1.size
254 assert_equal 'sql_escape', entries1[2].name
254 assert_equal 'sql_escape', entries1[2].name
255 assert_equal 'sql_escape', entries1[2].path
255 assert_equal 'sql_escape', entries1[2].path
256 assert_equal 'dir', entries1[2].kind
256 assert_equal 'dir', entries1[2].kind
257 readme = entries1[4]
257 readme = entries1[4]
258 assert_equal 'README', readme.name
258 assert_equal 'README', readme.name
259 assert_equal 'README', readme.path
259 assert_equal 'README', readme.path
260 assert_equal 'file', readme.kind
260 assert_equal 'file', readme.kind
261 assert_equal 365, readme.size
261 assert_equal 365, readme.size
262 assert_equal '8', readme.lastrev.revision
262 assert_equal '8', readme.lastrev.revision
263 assert_equal 'c51f5bb613cd60793c2a9fe9df29332e74bb949f', readme.lastrev.identifier
263 assert_equal 'c51f5bb613cd60793c2a9fe9df29332e74bb949f', readme.lastrev.identifier
264 # 2001-02-01 00:00:00 -0900
264 # 2001-02-01 00:00:00 -0900
265 assert_equal Time.gm(2001, 2, 1, 9, 0, 0), readme.lastrev.time
265 assert_equal Time.gm(2001, 2, 1, 9, 0, 0), readme.lastrev.time
266 end
266 end
267
267
268 def test_entry
268 def test_entry
269 entry = @adapter.entry()
269 entry = @adapter.entry()
270 assert_equal "", entry.path
270 assert_equal "", entry.path
271 assert_equal "dir", entry.kind
271 assert_equal "dir", entry.kind
272 entry = @adapter.entry('')
272 entry = @adapter.entry('')
273 assert_equal "", entry.path
273 assert_equal "", entry.path
274 assert_equal "dir", entry.kind
274 assert_equal "dir", entry.kind
275 assert_nil @adapter.entry('invalid')
275 assert_nil @adapter.entry('invalid')
276 assert_nil @adapter.entry('/invalid')
276 assert_nil @adapter.entry('/invalid')
277 assert_nil @adapter.entry('/invalid/')
277 assert_nil @adapter.entry('/invalid/')
278 assert_nil @adapter.entry('invalid/invalid')
278 assert_nil @adapter.entry('invalid/invalid')
279 assert_nil @adapter.entry('invalid/invalid/')
279 assert_nil @adapter.entry('invalid/invalid/')
280 assert_nil @adapter.entry('/invalid/invalid')
280 assert_nil @adapter.entry('/invalid/invalid')
281 assert_nil @adapter.entry('/invalid/invalid/')
281 assert_nil @adapter.entry('/invalid/invalid/')
282 ["README", "/README"].each do |path|
282 ["README", "/README"].each do |path|
283 ["0", "0885933ad4f6", "0885933ad4f68d77c2649cd11f8311276e7ef7ce"].each do |rev|
283 ["0", "0885933ad4f6", "0885933ad4f68d77c2649cd11f8311276e7ef7ce"].each do |rev|
284 entry = @adapter.entry(path, rev)
284 entry = @adapter.entry(path, rev)
285 assert_equal "README", entry.path
285 assert_equal "README", entry.path
286 assert_equal "file", entry.kind
286 assert_equal "file", entry.kind
287 assert_equal '0', entry.lastrev.revision
287 assert_equal '0', entry.lastrev.revision
288 assert_equal '0885933ad4f68d77c2649cd11f8311276e7ef7ce', entry.lastrev.identifier
288 assert_equal '0885933ad4f68d77c2649cd11f8311276e7ef7ce', entry.lastrev.identifier
289 end
289 end
290 end
290 end
291 ["sources", "/sources", "/sources/"].each do |path|
291 ["sources", "/sources", "/sources/"].each do |path|
292 ["0", "0885933ad4f6", "0885933ad4f68d77c2649cd11f8311276e7ef7ce"].each do |rev|
292 ["0", "0885933ad4f6", "0885933ad4f68d77c2649cd11f8311276e7ef7ce"].each do |rev|
293 entry = @adapter.entry(path, rev)
293 entry = @adapter.entry(path, rev)
294 assert_equal "sources", entry.path
294 assert_equal "sources", entry.path
295 assert_equal "dir", entry.kind
295 assert_equal "dir", entry.kind
296 end
296 end
297 end
297 end
298 ["sources/watchers_controller.rb", "/sources/watchers_controller.rb"].each do |path|
298 ["sources/watchers_controller.rb", "/sources/watchers_controller.rb"].each do |path|
299 ["0", "0885933ad4f6", "0885933ad4f68d77c2649cd11f8311276e7ef7ce"].each do |rev|
299 ["0", "0885933ad4f6", "0885933ad4f68d77c2649cd11f8311276e7ef7ce"].each do |rev|
300 entry = @adapter.entry(path, rev)
300 entry = @adapter.entry(path, rev)
301 assert_equal "sources/watchers_controller.rb", entry.path
301 assert_equal "sources/watchers_controller.rb", entry.path
302 assert_equal "file", entry.kind
302 assert_equal "file", entry.kind
303 assert_equal '0', entry.lastrev.revision
303 assert_equal '0', entry.lastrev.revision
304 assert_equal '0885933ad4f68d77c2649cd11f8311276e7ef7ce', entry.lastrev.identifier
304 assert_equal '0885933ad4f68d77c2649cd11f8311276e7ef7ce', entry.lastrev.identifier
305 end
305 end
306 end
306 end
307 end
307 end
308
308
309 def test_locate_on_outdated_repository
309 def test_locate_on_outdated_repository
310 assert_equal 1, @adapter.entries("images", 0).size
310 assert_equal 1, @adapter.entries("images", 0).size
311 assert_equal 2, @adapter.entries("images").size
311 assert_equal 2, @adapter.entries("images").size
312 assert_equal 2, @adapter.entries("images", 2).size
312 assert_equal 2, @adapter.entries("images", 2).size
313 end
313 end
314
314
315 def test_access_by_nodeid
315 def test_access_by_nodeid
316 path = 'sources/welcome_controller.rb'
316 path = 'sources/welcome_controller.rb'
317 assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400bb8672109')
317 assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400bb8672109')
318 end
318 end
319
319
320 def test_access_by_fuzzy_nodeid
320 def test_access_by_fuzzy_nodeid
321 path = 'sources/welcome_controller.rb'
321 path = 'sources/welcome_controller.rb'
322 # falls back to nodeid
322 # falls back to nodeid
323 assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400')
323 assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400')
324 end
324 end
325
325
326 def test_tags
326 def test_tags
327 assert_equal [@tag_char_1, 'tag_test.00', 'tag-init-revision'], @adapter.tags
327 assert_equal [@tag_char_1, 'tag_test.00', 'tag-init-revision'], @adapter.tags
328 end
328 end
329
329
330 def test_tagmap
330 def test_tagmap
331 tm = {
331 tm = {
332 @tag_char_1 => 'adf805632193500ad3b615cd04f58f9b0769f576',
332 @tag_char_1 => 'adf805632193500ad3b615cd04f58f9b0769f576',
333 'tag_test.00' => '6987191f453a5f6557018d522feea2c450d5588d',
333 'tag_test.00' => '6987191f453a5f6557018d522feea2c450d5588d',
334 'tag-init-revision' => '0885933ad4f68d77c2649cd11f8311276e7ef7ce',
334 'tag-init-revision' => '0885933ad4f68d77c2649cd11f8311276e7ef7ce',
335 }
335 }
336 assert_equal tm, @adapter.tagmap
336 assert_equal tm, @adapter.tagmap
337 end
337 end
338
338
339 def test_branches
339 def test_branches
340 brs = []
340 brs = []
341 @adapter.branches.each do |b|
341 @adapter.branches.each do |b|
342 brs << b
342 brs << b
343 end
343 end
344 assert_equal 7, brs.length
344 assert_equal 7, brs.length
345 assert_equal 'default', brs[0].to_s
345 assert_equal 'default', brs[0].to_s
346 assert_equal '31', brs[0].revision
346 assert_equal '31', brs[0].revision
347 assert_equal '31eeee7395c8c78e66dd54c50addd078d10b2355', brs[0].scmid
347 assert_equal '31eeee7395c8c78e66dd54c50addd078d10b2355', brs[0].scmid
348 assert_equal 'test-branch-01', brs[1].to_s
348 assert_equal 'test-branch-01', brs[1].to_s
349 assert_equal '30', brs[1].revision
349 assert_equal '30', brs[1].revision
350 assert_equal 'ad4dc4f80284a4f9168b77e0b6de288e5d207ee7', brs[1].scmid
350 assert_equal 'ad4dc4f80284a4f9168b77e0b6de288e5d207ee7', brs[1].scmid
351 assert_equal @branch_char_1, brs[2].to_s
351 assert_equal @branch_char_1, brs[2].to_s
352 assert_equal '27', brs[2].revision
352 assert_equal '27', brs[2].revision
353 assert_equal '7bbf4c738e7145149d2e5eb1eed1d3a8ddd3b914', brs[2].scmid
353 assert_equal '7bbf4c738e7145149d2e5eb1eed1d3a8ddd3b914', brs[2].scmid
354 assert_equal 'branch (1)[2]&,%.-3_4', brs[3].to_s
354 assert_equal 'branch (1)[2]&,%.-3_4', brs[3].to_s
355 assert_equal '25', brs[3].revision
355 assert_equal '25', brs[3].revision
356 assert_equal 'afc61e85bde74de930e5846c8451bd55b5bafc9c', brs[3].scmid
356 assert_equal 'afc61e85bde74de930e5846c8451bd55b5bafc9c', brs[3].scmid
357 assert_equal @branch_char_0, brs[4].to_s
357 assert_equal @branch_char_0, brs[4].to_s
358 assert_equal '23', brs[4].revision
358 assert_equal '23', brs[4].revision
359 assert_equal 'c8d3e4887474af6a589190140508037ebaa9d9c3', brs[4].scmid
359 assert_equal 'c8d3e4887474af6a589190140508037ebaa9d9c3', brs[4].scmid
360 assert_equal 'test_branch.latin-1', brs[5].to_s
360 assert_equal 'test_branch.latin-1', brs[5].to_s
361 assert_equal '22', brs[5].revision
361 assert_equal '22', brs[5].revision
362 assert_equal 'c2ffe7da686aa3d956e59f2a2854cf8980a8b768', brs[5].scmid
362 assert_equal 'c2ffe7da686aa3d956e59f2a2854cf8980a8b768', brs[5].scmid
363 assert_equal 'test-branch-00', brs[6].to_s
363 assert_equal 'test-branch-00', brs[6].to_s
364 assert_equal '13', brs[6].revision
364 assert_equal '13', brs[6].revision
365 assert_equal '3a330eb329586ea2adb3f83237c23310e744ebe9', brs[6].scmid
365 assert_equal '3a330eb329586ea2adb3f83237c23310e744ebe9', brs[6].scmid
366 end
366 end
367
367
368 def test_branchmap
368 def test_branchmap
369 bm = {
369 bm = {
370 'default' => '31eeee7395c8c78e66dd54c50addd078d10b2355',
370 'default' => '31eeee7395c8c78e66dd54c50addd078d10b2355',
371 'test_branch.latin-1' => 'c2ffe7da686aa3d956e59f2a2854cf8980a8b768',
371 'test_branch.latin-1' => 'c2ffe7da686aa3d956e59f2a2854cf8980a8b768',
372 'branch (1)[2]&,%.-3_4' => 'afc61e85bde74de930e5846c8451bd55b5bafc9c',
372 'branch (1)[2]&,%.-3_4' => 'afc61e85bde74de930e5846c8451bd55b5bafc9c',
373 'test-branch-00' => '3a330eb329586ea2adb3f83237c23310e744ebe9',
373 'test-branch-00' => '3a330eb329586ea2adb3f83237c23310e744ebe9',
374 "test-branch-01" => 'ad4dc4f80284a4f9168b77e0b6de288e5d207ee7',
374 "test-branch-01" => 'ad4dc4f80284a4f9168b77e0b6de288e5d207ee7',
375 @branch_char_0 => 'c8d3e4887474af6a589190140508037ebaa9d9c3',
375 @branch_char_0 => 'c8d3e4887474af6a589190140508037ebaa9d9c3',
376 @branch_char_1 => '7bbf4c738e7145149d2e5eb1eed1d3a8ddd3b914',
376 @branch_char_1 => '7bbf4c738e7145149d2e5eb1eed1d3a8ddd3b914',
377 }
377 }
378 assert_equal bm, @adapter.branchmap
378 assert_equal bm, @adapter.branchmap
379 end
379 end
380
380
381 def test_path_space
381 def test_path_space
382 p = 'README (1)[2]&,%.-3_4'
382 p = 'README (1)[2]&,%.-3_4'
383 [15, '933ca60293d7'].each do |r1|
383 [15, '933ca60293d7'].each do |r1|
384 assert @adapter.diff(p, r1)
384 assert @adapter.diff(p, r1)
385 assert @adapter.cat(p, r1)
385 assert @adapter.cat(p, r1)
386 assert_equal 1, @adapter.annotate(p, r1).lines.length
386 assert_equal 1, @adapter.annotate(p, r1).lines.length
387 [25, 'afc61e85bde7'].each do |r2|
387 [25, 'afc61e85bde7'].each do |r2|
388 assert @adapter.diff(p, r1, r2)
388 assert @adapter.diff(p, r1, r2)
389 end
389 end
390 end
390 end
391 end
391 end
392
392
393 def test_tag_non_ascii
393 def test_tag_non_ascii
394 p = "latin-1-dir/test-#{@char_1}-1.txt"
394 p = "latin-1-dir/test-#{@char_1}-1.txt"
395 assert @adapter.cat(p, @tag_char_1)
395 assert @adapter.cat(p, @tag_char_1)
396 assert_equal 1, @adapter.annotate(p, @tag_char_1).lines.length
396 assert_equal 1, @adapter.annotate(p, @tag_char_1).lines.length
397 end
397 end
398
398
399 def test_branch_non_ascii
399 def test_branch_non_ascii
400 p = "latin-1-dir/test-#{@char_1}-subdir/test-#{@char_1}-1.txt"
400 p = "latin-1-dir/test-#{@char_1}-subdir/test-#{@char_1}-1.txt"
401 assert @adapter.cat(p, @branch_char_1)
401 assert @adapter.cat(p, @branch_char_1)
402 assert_equal 1, @adapter.annotate(p, @branch_char_1).lines.length
402 assert_equal 1, @adapter.annotate(p, @branch_char_1).lines.length
403 end
403 end
404
404
405 def test_nodes_in_branch
405 def test_nodes_in_branch
406 [
406 [
407 'default',
407 'default',
408 @branch_char_1,
408 @branch_char_1,
409 'branch (1)[2]&,%.-3_4',
409 'branch (1)[2]&,%.-3_4',
410 @branch_char_0,
410 @branch_char_0,
411 'test_branch.latin-1',
411 'test_branch.latin-1',
412 'test-branch-00',
412 'test-branch-00',
413 ].each do |bra|
413 ].each do |bra|
414 nib0 = @adapter.nodes_in_branch(bra)
414 nib0 = @adapter.nodes_in_branch(bra)
415 assert nib0
415 assert nib0
416 nib1 = @adapter.nodes_in_branch(bra, :limit => 1)
416 nib1 = @adapter.nodes_in_branch(bra, :limit => 1)
417 assert_equal 1, nib1.size
417 assert_equal 1, nib1.size
418 case bra
418 case bra
419 when 'branch (1)[2]&,%.-3_4'
419 when 'branch (1)[2]&,%.-3_4'
420 if @adapter.class.client_version_above?([1, 6])
420 if @adapter.class.client_version_above?([1, 6])
421 assert_equal 3, nib0.size
421 assert_equal 3, nib0.size
422 assert_equal 'afc61e85bde74de930e5846c8451bd55b5bafc9c', nib0[0]
422 assert_equal 'afc61e85bde74de930e5846c8451bd55b5bafc9c', nib0[0]
423 nib2 = @adapter.nodes_in_branch(bra, :limit => 2)
423 nib2 = @adapter.nodes_in_branch(bra, :limit => 2)
424 assert_equal 2, nib2.size
424 assert_equal 2, nib2.size
425 assert_equal '933ca60293d78f7c7979dd123cc0c02431683575', nib2[1]
425 assert_equal '933ca60293d78f7c7979dd123cc0c02431683575', nib2[1]
426 end
426 end
427 when @branch_char_1
427 when @branch_char_1
428 if @adapter.class.client_version_above?([1, 6])
428 if @adapter.class.client_version_above?([1, 6])
429 assert_equal 2, nib0.size
429 assert_equal 2, nib0.size
430 assert_equal '08ff3227303ec0dfcc818efa8e9cc652fe81859f', nib0[1]
430 assert_equal '08ff3227303ec0dfcc818efa8e9cc652fe81859f', nib0[1]
431 nib2 = @adapter.nodes_in_branch(bra, :limit => 1)
431 nib2 = @adapter.nodes_in_branch(bra, :limit => 1)
432 assert_equal 1, nib2.size
432 assert_equal 1, nib2.size
433 assert_equal '7bbf4c738e7145149d2e5eb1eed1d3a8ddd3b914', nib2[0]
433 assert_equal '7bbf4c738e7145149d2e5eb1eed1d3a8ddd3b914', nib2[0]
434 end
434 end
435 end
435 end
436 end
436 end
437 end
437 end
438
438
439 def test_path_encoding_default_utf8
439 def test_path_encoding_default_utf8
440 adpt1 = Redmine::Scm::Adapters::MercurialAdapter.new(
440 adpt1 = Redmine::Scm::Adapters::MercurialAdapter.new(
441 REPOSITORY_PATH
441 REPOSITORY_PATH
442 )
442 )
443 assert_equal "UTF-8", adpt1.path_encoding
443 assert_equal "UTF-8", adpt1.path_encoding
444 adpt2 = Redmine::Scm::Adapters::MercurialAdapter.new(
444 adpt2 = Redmine::Scm::Adapters::MercurialAdapter.new(
445 REPOSITORY_PATH,
445 REPOSITORY_PATH,
446 nil,
446 nil,
447 nil,
447 nil,
448 nil,
448 nil,
449 ""
449 ""
450 )
450 )
451 assert_equal "UTF-8", adpt2.path_encoding
451 assert_equal "UTF-8", adpt2.path_encoding
452 end
452 end
453
453
454 private
454 private
455
455
456 def test_hgversion_for(hgversion, version)
456 def test_hgversion_for(hgversion, version)
457 @adapter.class.expects(:hgversion_from_command_line).returns(hgversion)
457 @adapter.class.expects(:hgversion_from_command_line).returns(hgversion)
458 assert_equal version, @adapter.class.hgversion
458 assert_equal version, @adapter.class.hgversion
459 end
459 end
460
460
461 def test_template_path_for(version, template)
461 def test_template_path_for(version, template)
462 assert_equal "#{HELPERS_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}",
462 assert_equal "#{HELPERS_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}",
463 @adapter.class.template_path_for(version)
463 @adapter.class.template_path_for(version)
464 assert File.exist?(@adapter.class.template_path_for(version))
464 assert File.exist?(@adapter.class.template_path_for(version))
465 end
465 end
466 else
466 else
467 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
467 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
468 def test_fake; assert true end
468 def test_fake; assert true end
469 end
469 end
470 end
470 end
471 rescue LoadError
471 rescue LoadError
472 class MercurialMochaFake < ActiveSupport::TestCase
472 class MercurialMochaFake < ActiveSupport::TestCase
473 def test_fake; assert(false, "Requires mocha to run those tests") end
473 def test_fake; assert(false, "Requires mocha to run those tests") end
474 end
474 end
475 end
475 end
@@ -1,653 +1,653
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2014 Jean-Philippe Lang
2 # Copyright (C) 2006-2014 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 = 34
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 def test_blank_path_to_repository_error_message
49 def test_blank_path_to_repository_error_message
50 set_language_if_valid 'en'
50 set_language_if_valid 'en'
51 repo = Repository::Mercurial.new(
51 repo = Repository::Mercurial.new(
52 :project => @project,
52 :project => @project,
53 :identifier => 'test'
53 :identifier => 'test'
54 )
54 )
55 assert !repo.save
55 assert !repo.save
56 assert_include "Path to repository can't be blank",
56 assert_include "Path to repository can't be blank",
57 repo.errors.full_messages
57 repo.errors.full_messages
58 end
58 end
59
59
60 def test_blank_path_to_repository_error_message_fr
60 def test_blank_path_to_repository_error_message_fr
61 set_language_if_valid 'fr'
61 set_language_if_valid 'fr'
62 str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)"
62 str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)"
63 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
63 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
64 repo = Repository::Mercurial.new(
64 repo = Repository::Mercurial.new(
65 :project => @project,
65 :project => @project,
66 :url => "",
66 :url => "",
67 :identifier => 'test',
67 :identifier => 'test',
68 :path_encoding => ''
68 :path_encoding => ''
69 )
69 )
70 assert !repo.save
70 assert !repo.save
71 assert_include str, repo.errors.full_messages
71 assert_include str, repo.errors.full_messages
72 end
72 end
73
73
74 if File.directory?(REPOSITORY_PATH)
74 if File.directory?(REPOSITORY_PATH)
75 def test_scm_available
75 def test_scm_available
76 klass = Repository::Mercurial
76 klass = Repository::Mercurial
77 assert_equal "Mercurial", klass.scm_name
77 assert_equal "Mercurial", klass.scm_name
78 assert klass.scm_adapter_class
78 assert klass.scm_adapter_class
79 assert_not_equal "", klass.scm_command
79 assert_not_equal "", klass.scm_command
80 assert_equal true, klass.scm_available
80 assert_equal true, klass.scm_available
81 end
81 end
82
82
83 def test_entries_on_tip
83 def test_entries_on_tip
84 entries = @repository.entries
84 entries = @repository.entries
85 assert_kind_of Redmine::Scm::Adapters::Entries, entries
85 assert_kind_of Redmine::Scm::Adapters::Entries, entries
86 end
86 end
87
87
88 def assert_entries(is_short_scmid=true)
88 def assert_entries(is_short_scmid=true)
89 hex = "9d5b5b00419901478496242e0768deba1ce8c51e"
89 hex = "9d5b5b00419901478496242e0768deba1ce8c51e"
90 scmid = scmid_for_assert(hex, is_short_scmid)
90 scmid = scmid_for_assert(hex, is_short_scmid)
91 [2, '400bb8672109', '400', 400].each do |r|
91 [2, '400bb8672109', '400', 400].each do |r|
92 entries1 = @repository.entries(nil, r)
92 entries1 = @repository.entries(nil, r)
93 assert entries1
93 assert entries1
94 assert_kind_of Redmine::Scm::Adapters::Entries, entries1
94 assert_kind_of Redmine::Scm::Adapters::Entries, entries1
95 assert_equal 3, entries1.size
95 assert_equal 3, entries1.size
96 readme = entries1[2]
96 readme = entries1[2]
97 assert_equal '1', readme.lastrev.revision
97 assert_equal '1', readme.lastrev.revision
98 assert_equal scmid, readme.lastrev.identifier
98 assert_equal scmid, readme.lastrev.identifier
99 assert_equal '1', readme.changeset.revision
99 assert_equal '1', readme.changeset.revision
100 assert_equal scmid, readme.changeset.scmid
100 assert_equal scmid, readme.changeset.scmid
101 end
101 end
102 end
102 end
103 private :assert_entries
103 private :assert_entries
104
104
105 def test_entries_short_id
105 def test_entries_short_id
106 assert_equal 0, @repository.changesets.count
106 assert_equal 0, @repository.changesets.count
107 create_rev0_short_id
107 create_rev0_short_id
108 assert_equal 1, @repository.changesets.count
108 assert_equal 1, @repository.changesets.count
109 @repository.fetch_changesets
109 @repository.fetch_changesets
110 @project.reload
110 @project.reload
111 assert_equal NUM_REV, @repository.changesets.count
111 assert_equal NUM_REV, @repository.changesets.count
112 assert_entries(true)
112 assert_entries(true)
113 end
113 end
114
114
115 def test_entries_long_id
115 def test_entries_long_id
116 assert_equal 0, @repository.changesets.count
116 assert_equal 0, @repository.changesets.count
117 @repository.fetch_changesets
117 @repository.fetch_changesets
118 @project.reload
118 @project.reload
119 assert_equal NUM_REV, @repository.changesets.count
119 assert_equal NUM_REV, @repository.changesets.count
120 assert_entries(false)
120 assert_entries(false)
121 end
121 end
122
122
123 def test_entry_on_tip
123 def test_entry_on_tip
124 entry = @repository.entry
124 entry = @repository.entry
125 assert_kind_of Redmine::Scm::Adapters::Entry, entry
125 assert_kind_of Redmine::Scm::Adapters::Entry, entry
126 assert_equal "", entry.path
126 assert_equal "", entry.path
127 assert_equal 'dir', entry.kind
127 assert_equal 'dir', entry.kind
128 end
128 end
129
129
130 def assert_entry(is_short_scmid=true)
130 def assert_entry(is_short_scmid=true)
131 hex = "0885933ad4f68d77c2649cd11f8311276e7ef7ce"
131 hex = "0885933ad4f68d77c2649cd11f8311276e7ef7ce"
132 scmid = scmid_for_assert(hex, is_short_scmid)
132 scmid = scmid_for_assert(hex, is_short_scmid)
133 ["README", "/README"].each do |path|
133 ["README", "/README"].each do |path|
134 ["0", "0885933ad4f6", "0885933ad4f68d77c2649cd11f8311276e7ef7ce"].each do |rev|
134 ["0", "0885933ad4f6", "0885933ad4f68d77c2649cd11f8311276e7ef7ce"].each do |rev|
135 entry = @repository.entry(path, rev)
135 entry = @repository.entry(path, rev)
136 assert_kind_of Redmine::Scm::Adapters::Entry, entry
136 assert_kind_of Redmine::Scm::Adapters::Entry, entry
137 assert_equal "README", entry.path
137 assert_equal "README", entry.path
138 assert_equal "file", entry.kind
138 assert_equal "file", entry.kind
139 assert_equal '0', entry.lastrev.revision
139 assert_equal '0', entry.lastrev.revision
140 assert_equal scmid, entry.lastrev.identifier
140 assert_equal scmid, entry.lastrev.identifier
141 end
141 end
142 end
142 end
143 ["sources", "/sources", "/sources/"].each do |path|
143 ["sources", "/sources", "/sources/"].each do |path|
144 ["0", "0885933ad4f6", "0885933ad4f68d77c2649cd11f8311276e7ef7ce"].each do |rev|
144 ["0", "0885933ad4f6", "0885933ad4f68d77c2649cd11f8311276e7ef7ce"].each do |rev|
145 entry = @repository.entry(path, rev)
145 entry = @repository.entry(path, rev)
146 assert_kind_of Redmine::Scm::Adapters::Entry, entry
146 assert_kind_of Redmine::Scm::Adapters::Entry, entry
147 assert_equal "sources", entry.path
147 assert_equal "sources", entry.path
148 assert_equal "dir", entry.kind
148 assert_equal "dir", entry.kind
149 end
149 end
150 end
150 end
151 ["sources/watchers_controller.rb", "/sources/watchers_controller.rb"].each do |path|
151 ["sources/watchers_controller.rb", "/sources/watchers_controller.rb"].each do |path|
152 ["0", "0885933ad4f6", "0885933ad4f68d77c2649cd11f8311276e7ef7ce"].each do |rev|
152 ["0", "0885933ad4f6", "0885933ad4f68d77c2649cd11f8311276e7ef7ce"].each do |rev|
153 entry = @repository.entry(path, rev)
153 entry = @repository.entry(path, rev)
154 assert_kind_of Redmine::Scm::Adapters::Entry, entry
154 assert_kind_of Redmine::Scm::Adapters::Entry, entry
155 assert_equal "sources/watchers_controller.rb", entry.path
155 assert_equal "sources/watchers_controller.rb", entry.path
156 assert_equal "file", entry.kind
156 assert_equal "file", entry.kind
157 assert_equal '0', entry.lastrev.revision
157 assert_equal '0', entry.lastrev.revision
158 assert_equal scmid, entry.lastrev.identifier
158 assert_equal scmid, entry.lastrev.identifier
159 end
159 end
160 end
160 end
161 end
161 end
162 private :assert_entry
162 private :assert_entry
163
163
164 def test_entry_short_id
164 def test_entry_short_id
165 assert_equal 0, @repository.changesets.count
165 assert_equal 0, @repository.changesets.count
166 create_rev0_short_id
166 create_rev0_short_id
167 assert_equal 1, @repository.changesets.count
167 assert_equal 1, @repository.changesets.count
168 assert_entry(true)
168 assert_entry(true)
169 end
169 end
170
170
171 def test_entry_long_id
171 def test_entry_long_id
172 assert_entry(false)
172 assert_entry(false)
173 end
173 end
174
174
175 def test_fetch_changesets_from_scratch
175 def test_fetch_changesets_from_scratch
176 assert_equal 0, @repository.changesets.count
176 assert_equal 0, @repository.changesets.count
177 @repository.fetch_changesets
177 @repository.fetch_changesets
178 @project.reload
178 @project.reload
179 assert_equal NUM_REV, @repository.changesets.count
179 assert_equal NUM_REV, @repository.changesets.count
180 assert_equal 46, @repository.filechanges.count
180 assert_equal 46, @repository.filechanges.count
181 rev0 = @repository.changesets.find_by_revision('0')
181 rev0 = @repository.changesets.find_by_revision('0')
182 assert_equal "Initial import.\nThe repository contains 3 files.",
182 assert_equal "Initial import.\nThe repository contains 3 files.",
183 rev0.comments
183 rev0.comments
184 assert_equal "0885933ad4f68d77c2649cd11f8311276e7ef7ce", rev0.scmid
184 assert_equal "0885933ad4f68d77c2649cd11f8311276e7ef7ce", rev0.scmid
185 first_rev = @repository.changesets.first
185 first_rev = @repository.changesets.first
186 last_rev = @repository.changesets.last
186 last_rev = @repository.changesets.last
187 assert_equal "#{NUM_REV - 1}", first_rev.revision
187 assert_equal "#{NUM_REV - 1}", first_rev.revision
188 assert_equal "0", last_rev.revision
188 assert_equal "0", last_rev.revision
189 end
189 end
190
190
191 def test_fetch_changesets_keep_short_id
191 def test_fetch_changesets_keep_short_id
192 assert_equal 0, @repository.changesets.count
192 assert_equal 0, @repository.changesets.count
193 create_rev0_short_id
193 create_rev0_short_id
194 assert_equal 1, @repository.changesets.count
194 assert_equal 1, @repository.changesets.count
195 @repository.fetch_changesets
195 @repository.fetch_changesets
196 @project.reload
196 @project.reload
197 assert_equal NUM_REV, @repository.changesets.count
197 assert_equal NUM_REV, @repository.changesets.count
198 rev1 = @repository.changesets.find_by_revision('1')
198 rev1 = @repository.changesets.find_by_revision('1')
199 assert_equal "9d5b5b004199", rev1.scmid
199 assert_equal "9d5b5b004199", rev1.scmid
200 end
200 end
201
201
202 def test_fetch_changesets_keep_long_id
202 def test_fetch_changesets_keep_long_id
203 assert_equal 0, @repository.changesets.count
203 assert_equal 0, @repository.changesets.count
204 Changeset.create!(:repository => @repository,
204 Changeset.create!(:repository => @repository,
205 :committed_on => Time.now,
205 :committed_on => Time.now,
206 :revision => '0',
206 :revision => '0',
207 :scmid => '0885933ad4f68d77c2649cd11f8311276e7ef7ce',
207 :scmid => '0885933ad4f68d77c2649cd11f8311276e7ef7ce',
208 :comments => 'test')
208 :comments => 'test')
209 assert_equal 1, @repository.changesets.count
209 assert_equal 1, @repository.changesets.count
210 @repository.fetch_changesets
210 @repository.fetch_changesets
211 @project.reload
211 @project.reload
212 assert_equal NUM_REV, @repository.changesets.count
212 assert_equal NUM_REV, @repository.changesets.count
213 rev1 = @repository.changesets.find_by_revision('1')
213 rev1 = @repository.changesets.find_by_revision('1')
214 assert_equal "9d5b5b00419901478496242e0768deba1ce8c51e", rev1.scmid
214 assert_equal "9d5b5b00419901478496242e0768deba1ce8c51e", rev1.scmid
215 end
215 end
216
216
217 def test_fetch_changesets_incremental
217 def test_fetch_changesets_incremental
218 assert_equal 0, @repository.changesets.count
218 assert_equal 0, @repository.changesets.count
219 @repository.fetch_changesets
219 @repository.fetch_changesets
220 @project.reload
220 @project.reload
221 assert_equal NUM_REV, @repository.changesets.count
221 assert_equal NUM_REV, @repository.changesets.count
222 # Remove changesets with revision > 2
222 # Remove changesets with revision > 2
223 @repository.changesets.each {|c| c.destroy if c.revision.to_i > 2}
223 @repository.changesets.each {|c| c.destroy if c.revision.to_i > 2}
224 @project.reload
224 @project.reload
225 @repository.reload
225 @repository.reload
226 assert_equal 3, @repository.changesets.count
226 assert_equal 3, @repository.changesets.count
227
227
228 @repository.fetch_changesets
228 @repository.fetch_changesets
229 @project.reload
229 @project.reload
230 assert_equal NUM_REV, @repository.changesets.count
230 assert_equal NUM_REV, @repository.changesets.count
231 end
231 end
232
232
233 def test_isodatesec
233 def test_isodatesec
234 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher
234 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher
235 if @repository.scm.class.client_version_above?([1, 0])
235 if @repository.scm.class.client_version_above?([1, 0])
236 assert_equal 0, @repository.changesets.count
236 assert_equal 0, @repository.changesets.count
237 @repository.fetch_changesets
237 @repository.fetch_changesets
238 @project.reload
238 @project.reload
239 assert_equal NUM_REV, @repository.changesets.count
239 assert_equal NUM_REV, @repository.changesets.count
240 rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52)
240 rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52)
241 assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on
241 assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on
242 end
242 end
243 end
243 end
244
244
245 def test_changeset_order_by_revision
245 def test_changeset_order_by_revision
246 assert_equal 0, @repository.changesets.count
246 assert_equal 0, @repository.changesets.count
247 @repository.fetch_changesets
247 @repository.fetch_changesets
248 @project.reload
248 @project.reload
249 assert_equal NUM_REV, @repository.changesets.count
249 assert_equal NUM_REV, @repository.changesets.count
250
250
251 c0 = @repository.latest_changeset
251 c0 = @repository.latest_changeset
252 c1 = @repository.changesets.find_by_revision('0')
252 c1 = @repository.changesets.find_by_revision('0')
253 # sorted by revision (id), not by date
253 # sorted by revision (id), not by date
254 assert c0.revision.to_i > c1.revision.to_i
254 assert c0.revision.to_i > c1.revision.to_i
255 assert c0.committed_on < c1.committed_on
255 assert c0.committed_on < c1.committed_on
256 end
256 end
257
257
258 def test_latest_changesets
258 def test_latest_changesets
259 assert_equal 0, @repository.changesets.count
259 assert_equal 0, @repository.changesets.count
260 @repository.fetch_changesets
260 @repository.fetch_changesets
261 @project.reload
261 @project.reload
262 assert_equal NUM_REV, @repository.changesets.count
262 assert_equal NUM_REV, @repository.changesets.count
263
263
264 # with_limit
264 # with_limit
265 changesets = @repository.latest_changesets('', nil, 2)
265 changesets = @repository.latest_changesets('', nil, 2)
266 assert_equal %w|31 30|, changesets.collect(&:revision)
266 assert_equal ["#{NUM_REV - 1}", "#{NUM_REV - 2}"], changesets.collect(&:revision)
267
267
268 # with_filepath
268 # with_filepath
269 changesets = @repository.latest_changesets(
269 changesets = @repository.latest_changesets(
270 '/sql_escape/percent%dir/percent%file1.txt', nil)
270 '/sql_escape/percent%dir/percent%file1.txt', nil)
271 assert_equal %w|30 11 10 9|, changesets.collect(&:revision)
271 assert_equal %w|30 11 10 9|, changesets.collect(&:revision)
272
272
273 changesets = @repository.latest_changesets(
273 changesets = @repository.latest_changesets(
274 '/sql_escape/underscore_dir/understrike_file.txt', nil)
274 '/sql_escape/underscore_dir/understrike_file.txt', nil)
275 assert_equal %w|30 12 9|, changesets.collect(&:revision)
275 assert_equal %w|30 12 9|, changesets.collect(&:revision)
276
276
277 changesets = @repository.latest_changesets('README', nil)
277 changesets = @repository.latest_changesets('README', nil)
278 assert_equal %w|31 30 28 17 8 6 1 0|, changesets.collect(&:revision)
278 assert_equal %w|31 30 28 17 8 6 1 0|, changesets.collect(&:revision)
279
279
280 changesets = @repository.latest_changesets('README','8')
280 changesets = @repository.latest_changesets('README','8')
281 assert_equal %w|8 6 1 0|, changesets.collect(&:revision)
281 assert_equal %w|8 6 1 0|, changesets.collect(&:revision)
282
282
283 changesets = @repository.latest_changesets('README','8', 2)
283 changesets = @repository.latest_changesets('README','8', 2)
284 assert_equal %w|8 6|, changesets.collect(&:revision)
284 assert_equal %w|8 6|, changesets.collect(&:revision)
285
285
286 # with_dirpath
286 # with_dirpath
287 changesets = @repository.latest_changesets('images', nil)
287 changesets = @repository.latest_changesets('images', nil)
288 assert_equal %w|1 0|, changesets.collect(&:revision)
288 assert_equal %w|1 0|, changesets.collect(&:revision)
289
289
290 path = 'sql_escape/percent%dir'
290 path = 'sql_escape/percent%dir'
291 changesets = @repository.latest_changesets(path, nil)
291 changesets = @repository.latest_changesets(path, nil)
292 assert_equal %w|30 13 11 10 9|, changesets.collect(&:revision)
292 assert_equal %w|30 13 11 10 9|, changesets.collect(&:revision)
293
293
294 changesets = @repository.latest_changesets(path, '11')
294 changesets = @repository.latest_changesets(path, '11')
295 assert_equal %w|11 10 9|, changesets.collect(&:revision)
295 assert_equal %w|11 10 9|, changesets.collect(&:revision)
296
296
297 changesets = @repository.latest_changesets(path, '11', 2)
297 changesets = @repository.latest_changesets(path, '11', 2)
298 assert_equal %w|11 10|, changesets.collect(&:revision)
298 assert_equal %w|11 10|, changesets.collect(&:revision)
299
299
300 path = 'sql_escape/underscore_dir'
300 path = 'sql_escape/underscore_dir'
301 changesets = @repository.latest_changesets(path, nil)
301 changesets = @repository.latest_changesets(path, nil)
302 assert_equal %w|30 13 12 9|, changesets.collect(&:revision)
302 assert_equal %w|30 13 12 9|, changesets.collect(&:revision)
303
303
304 changesets = @repository.latest_changesets(path, '12')
304 changesets = @repository.latest_changesets(path, '12')
305 assert_equal %w|12 9|, changesets.collect(&:revision)
305 assert_equal %w|12 9|, changesets.collect(&:revision)
306
306
307 changesets = @repository.latest_changesets(path, '12', 1)
307 changesets = @repository.latest_changesets(path, '12', 1)
308 assert_equal %w|12|, changesets.collect(&:revision)
308 assert_equal %w|12|, changesets.collect(&:revision)
309 end
309 end
310
310
311 def assert_latest_changesets_tag
311 def assert_latest_changesets_tag
312 changesets = @repository.latest_changesets('', 'tag_test.00')
312 changesets = @repository.latest_changesets('', 'tag_test.00')
313 assert_equal %w|5 4 3 2 1 0|, changesets.collect(&:revision)
313 assert_equal %w|5 4 3 2 1 0|, changesets.collect(&:revision)
314 end
314 end
315 private :assert_latest_changesets_tag
315 private :assert_latest_changesets_tag
316
316
317 def test_latest_changesets_tag
317 def test_latest_changesets_tag
318 assert_equal 0, @repository.changesets.count
318 assert_equal 0, @repository.changesets.count
319 @repository.fetch_changesets
319 @repository.fetch_changesets
320 @project.reload
320 @project.reload
321 assert_equal NUM_REV, @repository.changesets.count
321 assert_equal NUM_REV, @repository.changesets.count
322 assert_latest_changesets_tag
322 assert_latest_changesets_tag
323 end
323 end
324
324
325 def test_latest_changesets_tag_short_id
325 def test_latest_changesets_tag_short_id
326 assert_equal 0, @repository.changesets.count
326 assert_equal 0, @repository.changesets.count
327 create_rev0_short_id
327 create_rev0_short_id
328 assert_equal 1, @repository.changesets.count
328 assert_equal 1, @repository.changesets.count
329 @repository.fetch_changesets
329 @repository.fetch_changesets
330 @project.reload
330 @project.reload
331 assert_equal NUM_REV, @repository.changesets.count
331 assert_equal NUM_REV, @repository.changesets.count
332 assert_latest_changesets_tag
332 assert_latest_changesets_tag
333 end
333 end
334
334
335 def test_latest_changesets_tag_with_path
335 def test_latest_changesets_tag_with_path
336 assert_equal 0, @repository.changesets.count
336 assert_equal 0, @repository.changesets.count
337 @repository.fetch_changesets
337 @repository.fetch_changesets
338 @project.reload
338 @project.reload
339 assert_equal NUM_REV, @repository.changesets.count
339 assert_equal NUM_REV, @repository.changesets.count
340
340
341 changesets = @repository.latest_changesets('sources', 'tag_test.00')
341 changesets = @repository.latest_changesets('sources', 'tag_test.00')
342 assert_equal %w|4 3 2 1 0|, changesets.collect(&:revision)
342 assert_equal %w|4 3 2 1 0|, changesets.collect(&:revision)
343 end
343 end
344
344
345 def test_latest_changesets_tag_with_limit
345 def test_latest_changesets_tag_with_limit
346 assert_equal 0, @repository.changesets.count
346 assert_equal 0, @repository.changesets.count
347 @repository.fetch_changesets
347 @repository.fetch_changesets
348 @project.reload
348 @project.reload
349 assert_equal NUM_REV, @repository.changesets.count
349 assert_equal NUM_REV, @repository.changesets.count
350
350
351 changesets = @repository.latest_changesets('', 'tag_test.00', 2)
351 changesets = @repository.latest_changesets('', 'tag_test.00', 2)
352 assert_equal %w|5 4|, changesets.collect(&:revision)
352 assert_equal %w|5 4|, changesets.collect(&:revision)
353
353
354 changesets = @repository.latest_changesets('sources', 'tag_test.00', 2)
354 changesets = @repository.latest_changesets('sources', 'tag_test.00', 2)
355 assert_equal %w|4 3|, changesets.collect(&:revision)
355 assert_equal %w|4 3|, changesets.collect(&:revision)
356 end
356 end
357
357
358 def test_latest_changesets_branch
358 def test_latest_changesets_branch
359 assert_equal 0, @repository.changesets.count
359 assert_equal 0, @repository.changesets.count
360 @repository.fetch_changesets
360 @repository.fetch_changesets
361 @project.reload
361 @project.reload
362 assert_equal NUM_REV, @repository.changesets.count
362 assert_equal NUM_REV, @repository.changesets.count
363
363
364 if @repository.scm.class.client_version_above?([1, 6])
364 if @repository.scm.class.client_version_above?([1, 6])
365 changesets = @repository.latest_changesets('', @branch_char_1)
365 changesets = @repository.latest_changesets('', @branch_char_1)
366 assert_equal %w|27 26|, changesets.collect(&:revision)
366 assert_equal %w|27 26|, changesets.collect(&:revision)
367 end
367 end
368
368
369 changesets = @repository.latest_changesets("latin-1-dir/test-#{@char_1}-subdir", @branch_char_1)
369 changesets = @repository.latest_changesets("latin-1-dir/test-#{@char_1}-subdir", @branch_char_1)
370 assert_equal %w|27|, changesets.collect(&:revision)
370 assert_equal %w|27|, changesets.collect(&:revision)
371 end
371 end
372
372
373 def assert_latest_changesets_default_branch
373 def assert_latest_changesets_default_branch
374 changesets = @repository.latest_changesets('', 'default')
374 changesets = @repository.latest_changesets('', 'default')
375 assert_equal %w|31 28 24 6 4 3 2 1 0|, changesets.collect(&:revision)
375 assert_equal %w|31 28 24 6 4 3 2 1 0|, changesets.collect(&:revision)
376 end
376 end
377 private :assert_latest_changesets_default_branch
377 private :assert_latest_changesets_default_branch
378
378
379 def test_latest_changesets_default_branch
379 def test_latest_changesets_default_branch
380 assert_equal 0, @repository.changesets.count
380 assert_equal 0, @repository.changesets.count
381 @repository.fetch_changesets
381 @repository.fetch_changesets
382 @project.reload
382 @project.reload
383 assert_equal NUM_REV, @repository.changesets.count
383 assert_equal NUM_REV, @repository.changesets.count
384 assert_latest_changesets_default_branch
384 assert_latest_changesets_default_branch
385 end
385 end
386
386
387 def test_latest_changesets_default_branch_short_id
387 def test_latest_changesets_default_branch_short_id
388 assert_equal 0, @repository.changesets.count
388 assert_equal 0, @repository.changesets.count
389 create_rev0_short_id
389 create_rev0_short_id
390 assert_equal 1, @repository.changesets.count
390 assert_equal 1, @repository.changesets.count
391 @repository.fetch_changesets
391 @repository.fetch_changesets
392 @project.reload
392 @project.reload
393 assert_equal NUM_REV, @repository.changesets.count
393 assert_equal NUM_REV, @repository.changesets.count
394 assert_latest_changesets_default_branch
394 assert_latest_changesets_default_branch
395 end
395 end
396
396
397 def assert_copied_files(is_short_scmid=true)
397 def assert_copied_files(is_short_scmid=true)
398 cs1 = @repository.changesets.find_by_revision('13')
398 cs1 = @repository.changesets.find_by_revision('13')
399 assert_not_nil cs1
399 assert_not_nil cs1
400 c1 = cs1.filechanges.sort_by(&:path)
400 c1 = cs1.filechanges.sort_by(&:path)
401 assert_equal 2, c1.size
401 assert_equal 2, c1.size
402
402
403 hex1 = "3a330eb329586ea2adb3f83237c23310e744ebe9"
403 hex1 = "3a330eb329586ea2adb3f83237c23310e744ebe9"
404 scmid1 = scmid_for_assert(hex1, is_short_scmid)
404 scmid1 = scmid_for_assert(hex1, is_short_scmid)
405 assert_equal 'A', c1[0].action
405 assert_equal 'A', c1[0].action
406 assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path
406 assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path
407 assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path
407 assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path
408 assert_equal scmid1, c1[0].from_revision
408 assert_equal scmid1, c1[0].from_revision
409
409
410 assert_equal 'A', c1[1].action
410 assert_equal 'A', c1[1].action
411 assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path
411 assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path
412 assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path
412 assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path
413
413
414 cs2 = @repository.changesets.find_by_revision('15')
414 cs2 = @repository.changesets.find_by_revision('15')
415 c2 = cs2.filechanges
415 c2 = cs2.filechanges
416 assert_equal 1, c2.size
416 assert_equal 1, c2.size
417
417
418 hex2 = "933ca60293d78f7c7979dd123cc0c02431683575"
418 hex2 = "933ca60293d78f7c7979dd123cc0c02431683575"
419 scmid2 = scmid_for_assert(hex2, is_short_scmid)
419 scmid2 = scmid_for_assert(hex2, is_short_scmid)
420 assert_equal 'A', c2[0].action
420 assert_equal 'A', c2[0].action
421 assert_equal '/README (1)[2]&,%.-3_4', c2[0].path
421 assert_equal '/README (1)[2]&,%.-3_4', c2[0].path
422 assert_equal '/README', c2[0].from_path
422 assert_equal '/README', c2[0].from_path
423 assert_equal scmid2, c2[0].from_revision
423 assert_equal scmid2, c2[0].from_revision
424
424
425 cs3 = @repository.changesets.find_by_revision('19')
425 cs3 = @repository.changesets.find_by_revision('19')
426 c3 = cs3.filechanges
426 c3 = cs3.filechanges
427
427
428 hex3 = "5d9891a1b4258ea256552aa856e388f2da28256a"
428 hex3 = "5d9891a1b4258ea256552aa856e388f2da28256a"
429 scmid3 = scmid_for_assert(hex3, is_short_scmid)
429 scmid3 = scmid_for_assert(hex3, is_short_scmid)
430 assert_equal 1, c3.size
430 assert_equal 1, c3.size
431 assert_equal 'A', c3[0].action
431 assert_equal 'A', c3[0].action
432 assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path
432 assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path
433 assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path
433 assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path
434 assert_equal scmid3, c3[0].from_revision
434 assert_equal scmid3, c3[0].from_revision
435 end
435 end
436 private :assert_copied_files
436 private :assert_copied_files
437
437
438 def test_copied_files_short_id
438 def test_copied_files_short_id
439 assert_equal 0, @repository.changesets.count
439 assert_equal 0, @repository.changesets.count
440 create_rev0_short_id
440 create_rev0_short_id
441 assert_equal 1, @repository.changesets.count
441 assert_equal 1, @repository.changesets.count
442 @repository.fetch_changesets
442 @repository.fetch_changesets
443 @project.reload
443 @project.reload
444 assert_equal NUM_REV, @repository.changesets.count
444 assert_equal NUM_REV, @repository.changesets.count
445 assert_copied_files(true)
445 assert_copied_files(true)
446 end
446 end
447
447
448 def test_copied_files_long_id
448 def test_copied_files_long_id
449 assert_equal 0, @repository.changesets.count
449 assert_equal 0, @repository.changesets.count
450 @repository.fetch_changesets
450 @repository.fetch_changesets
451 @project.reload
451 @project.reload
452 assert_equal NUM_REV, @repository.changesets.count
452 assert_equal NUM_REV, @repository.changesets.count
453 assert_copied_files(false)
453 assert_copied_files(false)
454 end
454 end
455
455
456 def test_find_changeset_by_name
456 def test_find_changeset_by_name
457 assert_equal 0, @repository.changesets.count
457 assert_equal 0, @repository.changesets.count
458 @repository.fetch_changesets
458 @repository.fetch_changesets
459 @project.reload
459 @project.reload
460 assert_equal NUM_REV, @repository.changesets.count
460 assert_equal NUM_REV, @repository.changesets.count
461 %w|2 400bb8672109 400|.each do |r|
461 %w|2 400bb8672109 400|.each do |r|
462 assert_equal '2', @repository.find_changeset_by_name(r).revision
462 assert_equal '2', @repository.find_changeset_by_name(r).revision
463 end
463 end
464 end
464 end
465
465
466 def test_find_changeset_by_invalid_name
466 def test_find_changeset_by_invalid_name
467 assert_equal 0, @repository.changesets.count
467 assert_equal 0, @repository.changesets.count
468 @repository.fetch_changesets
468 @repository.fetch_changesets
469 @project.reload
469 @project.reload
470 assert_equal NUM_REV, @repository.changesets.count
470 assert_equal NUM_REV, @repository.changesets.count
471 assert_nil @repository.find_changeset_by_name('100000')
471 assert_nil @repository.find_changeset_by_name('100000')
472 end
472 end
473
473
474 def test_identifier
474 def test_identifier
475 assert_equal 0, @repository.changesets.count
475 assert_equal 0, @repository.changesets.count
476 @repository.fetch_changesets
476 @repository.fetch_changesets
477 @project.reload
477 @project.reload
478 assert_equal NUM_REV, @repository.changesets.count
478 assert_equal NUM_REV, @repository.changesets.count
479 c = @repository.changesets.find_by_revision('2')
479 c = @repository.changesets.find_by_revision('2')
480 assert_equal c.scmid, c.identifier
480 assert_equal c.scmid, c.identifier
481 end
481 end
482
482
483 def test_format_identifier
483 def test_format_identifier
484 assert_equal 0, @repository.changesets.count
484 assert_equal 0, @repository.changesets.count
485 @repository.fetch_changesets
485 @repository.fetch_changesets
486 @project.reload
486 @project.reload
487 assert_equal NUM_REV, @repository.changesets.count
487 assert_equal NUM_REV, @repository.changesets.count
488 c = @repository.changesets.find_by_revision('2')
488 c = @repository.changesets.find_by_revision('2')
489 assert_equal '2:400bb8672109', c.format_identifier
489 assert_equal '2:400bb8672109', c.format_identifier
490 end
490 end
491
491
492 def test_format_identifier_long_id
492 def test_format_identifier_long_id
493 assert_equal 0, @repository.changesets.count
493 assert_equal 0, @repository.changesets.count
494 Changeset.create!(:repository => @repository,
494 Changeset.create!(:repository => @repository,
495 :committed_on => Time.now,
495 :committed_on => Time.now,
496 :revision => '0',
496 :revision => '0',
497 :scmid => '0885933ad4f68d77c2649cd11f8311276e7ef7ce',
497 :scmid => '0885933ad4f68d77c2649cd11f8311276e7ef7ce',
498 :comments => 'test')
498 :comments => 'test')
499 c = @repository.changesets.find_by_revision('0')
499 c = @repository.changesets.find_by_revision('0')
500 assert_equal '0:0885933ad4f6', c.format_identifier
500 assert_equal '0:0885933ad4f6', c.format_identifier
501 end
501 end
502
502
503 def test_find_changeset_by_empty_name
503 def test_find_changeset_by_empty_name
504 assert_equal 0, @repository.changesets.count
504 assert_equal 0, @repository.changesets.count
505 @repository.fetch_changesets
505 @repository.fetch_changesets
506 @project.reload
506 @project.reload
507 assert_equal NUM_REV, @repository.changesets.count
507 assert_equal NUM_REV, @repository.changesets.count
508 ['', ' ', nil].each do |r|
508 ['', ' ', nil].each do |r|
509 assert_nil @repository.find_changeset_by_name(r)
509 assert_nil @repository.find_changeset_by_name(r)
510 end
510 end
511 end
511 end
512
512
513 def assert_parents(is_short_scmid=true)
513 def assert_parents(is_short_scmid=true)
514 r1 = @repository.changesets.find_by_revision('0')
514 r1 = @repository.changesets.find_by_revision('0')
515 assert_equal [], r1.parents
515 assert_equal [], r1.parents
516 r2 = @repository.changesets.find_by_revision('1')
516 r2 = @repository.changesets.find_by_revision('1')
517 hex2 = "0885933ad4f68d77c2649cd11f8311276e7ef7ce"
517 hex2 = "0885933ad4f68d77c2649cd11f8311276e7ef7ce"
518 scmid2 = scmid_for_assert(hex2, is_short_scmid)
518 scmid2 = scmid_for_assert(hex2, is_short_scmid)
519 assert_equal 1, r2.parents.length
519 assert_equal 1, r2.parents.length
520 assert_equal scmid2, r2.parents[0].identifier
520 assert_equal scmid2, r2.parents[0].identifier
521 r3 = @repository.changesets.find_by_revision('30')
521 r3 = @repository.changesets.find_by_revision('30')
522 assert_equal 2, r3.parents.length
522 assert_equal 2, r3.parents.length
523 r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort
523 r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort
524 hex41 = "3a330eb329586ea2adb3f83237c23310e744ebe9"
524 hex41 = "3a330eb329586ea2adb3f83237c23310e744ebe9"
525 scmid41 = scmid_for_assert(hex41, is_short_scmid)
525 scmid41 = scmid_for_assert(hex41, is_short_scmid)
526 hex42 = "a94b0528f24fe05ebaef496ae0500bb050772e36"
526 hex42 = "a94b0528f24fe05ebaef496ae0500bb050772e36"
527 scmid42 = scmid_for_assert(hex42, is_short_scmid)
527 scmid42 = scmid_for_assert(hex42, is_short_scmid)
528 assert_equal scmid41, r4[0]
528 assert_equal scmid41, r4[0]
529 assert_equal scmid42, r4[1]
529 assert_equal scmid42, r4[1]
530 end
530 end
531 private :assert_parents
531 private :assert_parents
532
532
533 def test_parents_short_id
533 def test_parents_short_id
534 assert_equal 0, @repository.changesets.count
534 assert_equal 0, @repository.changesets.count
535 create_rev0_short_id
535 create_rev0_short_id
536 assert_equal 1, @repository.changesets.count
536 assert_equal 1, @repository.changesets.count
537 @repository.fetch_changesets
537 @repository.fetch_changesets
538 @project.reload
538 @project.reload
539 assert_equal NUM_REV, @repository.changesets.count
539 assert_equal NUM_REV, @repository.changesets.count
540 assert_parents(true)
540 assert_parents(true)
541 end
541 end
542
542
543 def test_parents_long_id
543 def test_parents_long_id
544 assert_equal 0, @repository.changesets.count
544 assert_equal 0, @repository.changesets.count
545 @repository.fetch_changesets
545 @repository.fetch_changesets
546 @project.reload
546 @project.reload
547 assert_equal NUM_REV, @repository.changesets.count
547 assert_equal NUM_REV, @repository.changesets.count
548 assert_parents(false)
548 assert_parents(false)
549 end
549 end
550
550
551 def test_activities
551 def test_activities
552 c = Changeset.new(:repository => @repository,
552 c = Changeset.new(:repository => @repository,
553 :committed_on => Time.now,
553 :committed_on => Time.now,
554 :revision => '123',
554 :revision => '123',
555 :scmid => 'abc400bb8672',
555 :scmid => 'abc400bb8672',
556 :comments => 'test')
556 :comments => 'test')
557 assert c.event_title.include?('123:abc400bb8672:')
557 assert c.event_title.include?('123:abc400bb8672:')
558 assert_equal 'abc400bb8672', c.event_url[:rev]
558 assert_equal 'abc400bb8672', c.event_url[:rev]
559 end
559 end
560
560
561 def test_previous
561 def test_previous
562 assert_equal 0, @repository.changesets.count
562 assert_equal 0, @repository.changesets.count
563 @repository.fetch_changesets
563 @repository.fetch_changesets
564 @project.reload
564 @project.reload
565 assert_equal NUM_REV, @repository.changesets.count
565 assert_equal NUM_REV, @repository.changesets.count
566 %w|28 3ae45e2d177d 3ae45|.each do |r1|
566 %w|28 3ae45e2d177d 3ae45|.each do |r1|
567 changeset = @repository.find_changeset_by_name(r1)
567 changeset = @repository.find_changeset_by_name(r1)
568 %w|27 7bbf4c738e71 7bbf|.each do |r2|
568 %w|27 7bbf4c738e71 7bbf|.each do |r2|
569 assert_equal @repository.find_changeset_by_name(r2), changeset.previous
569 assert_equal @repository.find_changeset_by_name(r2), changeset.previous
570 end
570 end
571 end
571 end
572 end
572 end
573
573
574 def test_previous_nil
574 def test_previous_nil
575 assert_equal 0, @repository.changesets.count
575 assert_equal 0, @repository.changesets.count
576 @repository.fetch_changesets
576 @repository.fetch_changesets
577 @project.reload
577 @project.reload
578 assert_equal NUM_REV, @repository.changesets.count
578 assert_equal NUM_REV, @repository.changesets.count
579 %w|0 0885933ad4f6 0885|.each do |r1|
579 %w|0 0885933ad4f6 0885|.each do |r1|
580 changeset = @repository.find_changeset_by_name(r1)
580 changeset = @repository.find_changeset_by_name(r1)
581 assert_nil changeset.previous
581 assert_nil changeset.previous
582 end
582 end
583 end
583 end
584
584
585 def test_next
585 def test_next
586 assert_equal 0, @repository.changesets.count
586 assert_equal 0, @repository.changesets.count
587 @repository.fetch_changesets
587 @repository.fetch_changesets
588 @project.reload
588 @project.reload
589 assert_equal NUM_REV, @repository.changesets.count
589 assert_equal NUM_REV, @repository.changesets.count
590 %w|27 7bbf4c738e71 7bbf|.each do |r2|
590 %w|27 7bbf4c738e71 7bbf|.each do |r2|
591 changeset = @repository.find_changeset_by_name(r2)
591 changeset = @repository.find_changeset_by_name(r2)
592 %w|28 3ae45e2d177d 3ae45|.each do |r1|
592 %w|28 3ae45e2d177d 3ae45|.each do |r1|
593 assert_equal @repository.find_changeset_by_name(r1), changeset.next
593 assert_equal @repository.find_changeset_by_name(r1), changeset.next
594 end
594 end
595 end
595 end
596 end
596 end
597
597
598 def test_next_nil
598 def test_next_nil
599 assert_equal 0, @repository.changesets.count
599 assert_equal 0, @repository.changesets.count
600 @repository.fetch_changesets
600 @repository.fetch_changesets
601 @project.reload
601 @project.reload
602 assert_equal NUM_REV, @repository.changesets.count
602 assert_equal NUM_REV, @repository.changesets.count
603 %w|31 31eeee7395c8 31eee|.each do |r1|
603 ["#{NUM_REV - 1}", "2e6d54642923", "2e6d5"].each do |r1|
604 changeset = @repository.find_changeset_by_name(r1)
604 changeset = @repository.find_changeset_by_name(r1)
605 assert_nil changeset.next
605 assert_nil changeset.next
606 end
606 end
607 end
607 end
608
608
609 def test_scmid_for_inserting_db_short_id
609 def test_scmid_for_inserting_db_short_id
610 assert_equal 0, @repository.changesets.count
610 assert_equal 0, @repository.changesets.count
611 create_rev0_short_id
611 create_rev0_short_id
612 assert_equal 1, @repository.changesets.count
612 assert_equal 1, @repository.changesets.count
613 rev = "0123456789012345678901234567890123456789"
613 rev = "0123456789012345678901234567890123456789"
614 assert_equal 12, @repository.scmid_for_inserting_db(rev).length
614 assert_equal 12, @repository.scmid_for_inserting_db(rev).length
615 end
615 end
616
616
617 def test_scmid_for_inserting_db_long_id
617 def test_scmid_for_inserting_db_long_id
618 rev = "0123456789012345678901234567890123456789"
618 rev = "0123456789012345678901234567890123456789"
619 assert_equal 0, @repository.changesets.count
619 assert_equal 0, @repository.changesets.count
620 assert_equal 40, @repository.scmid_for_inserting_db(rev).length
620 assert_equal 40, @repository.scmid_for_inserting_db(rev).length
621 Changeset.create!(:repository => @repository,
621 Changeset.create!(:repository => @repository,
622 :committed_on => Time.now,
622 :committed_on => Time.now,
623 :revision => '0',
623 :revision => '0',
624 :scmid => rev,
624 :scmid => rev,
625 :comments => 'test')
625 :comments => 'test')
626 assert_equal 1, @repository.changesets.count
626 assert_equal 1, @repository.changesets.count
627 assert_equal 40, @repository.scmid_for_inserting_db(rev).length
627 assert_equal 40, @repository.scmid_for_inserting_db(rev).length
628 end
628 end
629
629
630 def test_scmid_for_assert
630 def test_scmid_for_assert
631 rev = "0123456789012345678901234567890123456789"
631 rev = "0123456789012345678901234567890123456789"
632 assert_equal rev, scmid_for_assert(rev, false)
632 assert_equal rev, scmid_for_assert(rev, false)
633 assert_equal "012345678901", scmid_for_assert(rev, true)
633 assert_equal "012345678901", scmid_for_assert(rev, true)
634 end
634 end
635
635
636 private
636 private
637
637
638 def scmid_for_assert(hex, is_short=true)
638 def scmid_for_assert(hex, is_short=true)
639 is_short ? hex[0, 12] : hex
639 is_short ? hex[0, 12] : hex
640 end
640 end
641
641
642 def create_rev0_short_id
642 def create_rev0_short_id
643 Changeset.create!(:repository => @repository,
643 Changeset.create!(:repository => @repository,
644 :committed_on => Time.now,
644 :committed_on => Time.now,
645 :revision => '0',
645 :revision => '0',
646 :scmid => '0885933ad4f6',
646 :scmid => '0885933ad4f6',
647 :comments => 'test')
647 :comments => 'test')
648 end
648 end
649 else
649 else
650 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
650 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
651 def test_fake; assert true end
651 def test_fake; assert true end
652 end
652 end
653 end
653 end
General Comments 0
You need to be logged in to leave comments. Login now