##// END OF EJS Templates
Merged r12929 from trunk to 2.4-stable (#16177)...
Toshi MARUYAMA -
r12658:5e031bce4703
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,434 +1,434
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 '31eeee7395c8',adp.info.lastrev.scmid
93 assert_equal '2e6d54642923',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 '400bb8672109', revisions[0].scmid
101 assert_equal '400bb8672109', revisions[0].scmid
102 assert_equal '4', revisions[2].revision
102 assert_equal '4', revisions[2].revision
103 assert_equal 'def6d2f1254a', revisions[2].scmid
103 assert_equal 'def6d2f1254a', 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 '400bb8672109', revisions[0].scmid
108 assert_equal '400bb8672109', 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 "0885933ad4f6", revs2[0].parents[0]
118 assert_equal "0885933ad4f6", 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 "a94b0528f24f", revs3[0].parents[0]
122 assert_equal "a94b0528f24f", revs3[0].parents[0]
123 assert_equal "3a330eb32958", revs3[0].parents[1]
123 assert_equal "3a330eb32958", 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 '9d5b5b004199', readme.lastrev.identifier
216 assert_equal '9d5b5b004199', 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 '0885933ad4f6', readme.lastrev.identifier
245 assert_equal '0885933ad4f6', 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 'c51f5bb613cd', readme.lastrev.identifier
263 assert_equal 'c51f5bb613cd', 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_locate_on_outdated_repository
268 def test_locate_on_outdated_repository
269 assert_equal 1, @adapter.entries("images", 0).size
269 assert_equal 1, @adapter.entries("images", 0).size
270 assert_equal 2, @adapter.entries("images").size
270 assert_equal 2, @adapter.entries("images").size
271 assert_equal 2, @adapter.entries("images", 2).size
271 assert_equal 2, @adapter.entries("images", 2).size
272 end
272 end
273
273
274 def test_access_by_nodeid
274 def test_access_by_nodeid
275 path = 'sources/welcome_controller.rb'
275 path = 'sources/welcome_controller.rb'
276 assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400bb8672109')
276 assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400bb8672109')
277 end
277 end
278
278
279 def test_access_by_fuzzy_nodeid
279 def test_access_by_fuzzy_nodeid
280 path = 'sources/welcome_controller.rb'
280 path = 'sources/welcome_controller.rb'
281 # falls back to nodeid
281 # falls back to nodeid
282 assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400')
282 assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400')
283 end
283 end
284
284
285 def test_tags
285 def test_tags
286 assert_equal [@tag_char_1, 'tag_test.00', 'tag-init-revision'], @adapter.tags
286 assert_equal [@tag_char_1, 'tag_test.00', 'tag-init-revision'], @adapter.tags
287 end
287 end
288
288
289 def test_tagmap
289 def test_tagmap
290 tm = {
290 tm = {
291 @tag_char_1 => 'adf805632193',
291 @tag_char_1 => 'adf805632193',
292 'tag_test.00' => '6987191f453a',
292 'tag_test.00' => '6987191f453a',
293 'tag-init-revision' => '0885933ad4f6',
293 'tag-init-revision' => '0885933ad4f6',
294 }
294 }
295 assert_equal tm, @adapter.tagmap
295 assert_equal tm, @adapter.tagmap
296 end
296 end
297
297
298 def test_branches
298 def test_branches
299 brs = []
299 brs = []
300 @adapter.branches.each do |b|
300 @adapter.branches.each do |b|
301 brs << b
301 brs << b
302 end
302 end
303 assert_equal 7, brs.length
303 assert_equal 7, brs.length
304 assert_equal 'default', brs[0].to_s
304 assert_equal 'default', brs[0].to_s
305 assert_equal '31', brs[0].revision
305 assert_equal '31', brs[0].revision
306 assert_equal '31eeee7395c8', brs[0].scmid
306 assert_equal '31eeee7395c8', brs[0].scmid
307 assert_equal 'test-branch-01', brs[1].to_s
307 assert_equal 'test-branch-01', brs[1].to_s
308 assert_equal '30', brs[1].revision
308 assert_equal '30', brs[1].revision
309 assert_equal 'ad4dc4f80284', brs[1].scmid
309 assert_equal 'ad4dc4f80284', brs[1].scmid
310 assert_equal @branch_char_1, brs[2].to_s
310 assert_equal @branch_char_1, brs[2].to_s
311 assert_equal '27', brs[2].revision
311 assert_equal '27', brs[2].revision
312 assert_equal '7bbf4c738e71', brs[2].scmid
312 assert_equal '7bbf4c738e71', brs[2].scmid
313 assert_equal 'branch (1)[2]&,%.-3_4', brs[3].to_s
313 assert_equal 'branch (1)[2]&,%.-3_4', brs[3].to_s
314 assert_equal '25', brs[3].revision
314 assert_equal '25', brs[3].revision
315 assert_equal 'afc61e85bde7', brs[3].scmid
315 assert_equal 'afc61e85bde7', brs[3].scmid
316 assert_equal @branch_char_0, brs[4].to_s
316 assert_equal @branch_char_0, brs[4].to_s
317 assert_equal '23', brs[4].revision
317 assert_equal '23', brs[4].revision
318 assert_equal 'c8d3e4887474', brs[4].scmid
318 assert_equal 'c8d3e4887474', brs[4].scmid
319 assert_equal 'test_branch.latin-1', brs[5].to_s
319 assert_equal 'test_branch.latin-1', brs[5].to_s
320 assert_equal '22', brs[5].revision
320 assert_equal '22', brs[5].revision
321 assert_equal 'c2ffe7da686a', brs[5].scmid
321 assert_equal 'c2ffe7da686a', brs[5].scmid
322 assert_equal 'test-branch-00', brs[6].to_s
322 assert_equal 'test-branch-00', brs[6].to_s
323 assert_equal '13', brs[6].revision
323 assert_equal '13', brs[6].revision
324 assert_equal '3a330eb32958', brs[6].scmid
324 assert_equal '3a330eb32958', brs[6].scmid
325 end
325 end
326
326
327 def test_branchmap
327 def test_branchmap
328 bm = {
328 bm = {
329 'default' => '31eeee7395c8',
329 'default' => '31eeee7395c8',
330 'test_branch.latin-1' => 'c2ffe7da686a',
330 'test_branch.latin-1' => 'c2ffe7da686a',
331 'branch (1)[2]&,%.-3_4' => 'afc61e85bde7',
331 'branch (1)[2]&,%.-3_4' => 'afc61e85bde7',
332 'test-branch-00' => '3a330eb32958',
332 'test-branch-00' => '3a330eb32958',
333 "test-branch-01" => 'ad4dc4f80284',
333 "test-branch-01" => 'ad4dc4f80284',
334 @branch_char_0 => 'c8d3e4887474',
334 @branch_char_0 => 'c8d3e4887474',
335 @branch_char_1 => '7bbf4c738e71',
335 @branch_char_1 => '7bbf4c738e71',
336 }
336 }
337 assert_equal bm, @adapter.branchmap
337 assert_equal bm, @adapter.branchmap
338 end
338 end
339
339
340 def test_path_space
340 def test_path_space
341 p = 'README (1)[2]&,%.-3_4'
341 p = 'README (1)[2]&,%.-3_4'
342 [15, '933ca60293d7'].each do |r1|
342 [15, '933ca60293d7'].each do |r1|
343 assert @adapter.diff(p, r1)
343 assert @adapter.diff(p, r1)
344 assert @adapter.cat(p, r1)
344 assert @adapter.cat(p, r1)
345 assert_equal 1, @adapter.annotate(p, r1).lines.length
345 assert_equal 1, @adapter.annotate(p, r1).lines.length
346 [25, 'afc61e85bde7'].each do |r2|
346 [25, 'afc61e85bde7'].each do |r2|
347 assert @adapter.diff(p, r1, r2)
347 assert @adapter.diff(p, r1, r2)
348 end
348 end
349 end
349 end
350 end
350 end
351
351
352 def test_tag_non_ascii
352 def test_tag_non_ascii
353 p = "latin-1-dir/test-#{@char_1}-1.txt"
353 p = "latin-1-dir/test-#{@char_1}-1.txt"
354 assert @adapter.cat(p, @tag_char_1)
354 assert @adapter.cat(p, @tag_char_1)
355 assert_equal 1, @adapter.annotate(p, @tag_char_1).lines.length
355 assert_equal 1, @adapter.annotate(p, @tag_char_1).lines.length
356 end
356 end
357
357
358 def test_branch_non_ascii
358 def test_branch_non_ascii
359 p = "latin-1-dir/test-#{@char_1}-subdir/test-#{@char_1}-1.txt"
359 p = "latin-1-dir/test-#{@char_1}-subdir/test-#{@char_1}-1.txt"
360 assert @adapter.cat(p, @branch_char_1)
360 assert @adapter.cat(p, @branch_char_1)
361 assert_equal 1, @adapter.annotate(p, @branch_char_1).lines.length
361 assert_equal 1, @adapter.annotate(p, @branch_char_1).lines.length
362 end
362 end
363
363
364 def test_nodes_in_branch
364 def test_nodes_in_branch
365 [
365 [
366 'default',
366 'default',
367 @branch_char_1,
367 @branch_char_1,
368 'branch (1)[2]&,%.-3_4',
368 'branch (1)[2]&,%.-3_4',
369 @branch_char_0,
369 @branch_char_0,
370 'test_branch.latin-1',
370 'test_branch.latin-1',
371 'test-branch-00',
371 'test-branch-00',
372 ].each do |bra|
372 ].each do |bra|
373 nib0 = @adapter.nodes_in_branch(bra)
373 nib0 = @adapter.nodes_in_branch(bra)
374 assert nib0
374 assert nib0
375 nib1 = @adapter.nodes_in_branch(bra, :limit => 1)
375 nib1 = @adapter.nodes_in_branch(bra, :limit => 1)
376 assert_equal 1, nib1.size
376 assert_equal 1, nib1.size
377 case bra
377 case bra
378 when 'branch (1)[2]&,%.-3_4'
378 when 'branch (1)[2]&,%.-3_4'
379 if @adapter.class.client_version_above?([1, 6])
379 if @adapter.class.client_version_above?([1, 6])
380 assert_equal 3, nib0.size
380 assert_equal 3, nib0.size
381 assert_equal nib0[0], 'afc61e85bde7'
381 assert_equal nib0[0], 'afc61e85bde7'
382 nib2 = @adapter.nodes_in_branch(bra, :limit => 2)
382 nib2 = @adapter.nodes_in_branch(bra, :limit => 2)
383 assert_equal 2, nib2.size
383 assert_equal 2, nib2.size
384 assert_equal nib2[1], '933ca60293d7'
384 assert_equal nib2[1], '933ca60293d7'
385 end
385 end
386 when @branch_char_1
386 when @branch_char_1
387 if @adapter.class.client_version_above?([1, 6])
387 if @adapter.class.client_version_above?([1, 6])
388 assert_equal 2, nib0.size
388 assert_equal 2, nib0.size
389 assert_equal nib0[1], '08ff3227303e'
389 assert_equal nib0[1], '08ff3227303e'
390 nib2 = @adapter.nodes_in_branch(bra, :limit => 1)
390 nib2 = @adapter.nodes_in_branch(bra, :limit => 1)
391 assert_equal 1, nib2.size
391 assert_equal 1, nib2.size
392 assert_equal nib2[0], '7bbf4c738e71'
392 assert_equal nib2[0], '7bbf4c738e71'
393 end
393 end
394 end
394 end
395 end
395 end
396 end
396 end
397
397
398 def test_path_encoding_default_utf8
398 def test_path_encoding_default_utf8
399 adpt1 = Redmine::Scm::Adapters::MercurialAdapter.new(
399 adpt1 = Redmine::Scm::Adapters::MercurialAdapter.new(
400 REPOSITORY_PATH
400 REPOSITORY_PATH
401 )
401 )
402 assert_equal "UTF-8", adpt1.path_encoding
402 assert_equal "UTF-8", adpt1.path_encoding
403 adpt2 = Redmine::Scm::Adapters::MercurialAdapter.new(
403 adpt2 = Redmine::Scm::Adapters::MercurialAdapter.new(
404 REPOSITORY_PATH,
404 REPOSITORY_PATH,
405 nil,
405 nil,
406 nil,
406 nil,
407 nil,
407 nil,
408 ""
408 ""
409 )
409 )
410 assert_equal "UTF-8", adpt2.path_encoding
410 assert_equal "UTF-8", adpt2.path_encoding
411 end
411 end
412
412
413 private
413 private
414
414
415 def test_hgversion_for(hgversion, version)
415 def test_hgversion_for(hgversion, version)
416 @adapter.class.expects(:hgversion_from_command_line).returns(hgversion)
416 @adapter.class.expects(:hgversion_from_command_line).returns(hgversion)
417 assert_equal version, @adapter.class.hgversion
417 assert_equal version, @adapter.class.hgversion
418 end
418 end
419
419
420 def test_template_path_for(version, template)
420 def test_template_path_for(version, template)
421 assert_equal "#{HELPERS_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}",
421 assert_equal "#{HELPERS_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}",
422 @adapter.class.template_path_for(version)
422 @adapter.class.template_path_for(version)
423 assert File.exist?(@adapter.class.template_path_for(version))
423 assert File.exist?(@adapter.class.template_path_for(version))
424 end
424 end
425 else
425 else
426 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
426 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
427 def test_fake; assert true end
427 def test_fake; assert true end
428 end
428 end
429 end
429 end
430 rescue LoadError
430 rescue LoadError
431 class MercurialMochaFake < ActiveSupport::TestCase
431 class MercurialMochaFake < ActiveSupport::TestCase
432 def test_fake; assert(false, "Requires mocha to run those tests") end
432 def test_fake; assert(false, "Requires mocha to run those tests") end
433 end
433 end
434 end
434 end
@@ -1,377 +1,377
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
49
50 def test_blank_path_to_repository_error_message
50 def test_blank_path_to_repository_error_message
51 set_language_if_valid 'en'
51 set_language_if_valid 'en'
52 repo = Repository::Mercurial.new(
52 repo = Repository::Mercurial.new(
53 :project => @project,
53 :project => @project,
54 :identifier => 'test'
54 :identifier => 'test'
55 )
55 )
56 assert !repo.save
56 assert !repo.save
57 assert_include "Path to repository can't be blank",
57 assert_include "Path to repository can't be blank",
58 repo.errors.full_messages
58 repo.errors.full_messages
59 end
59 end
60
60
61 def test_blank_path_to_repository_error_message_fr
61 def test_blank_path_to_repository_error_message_fr
62 set_language_if_valid 'fr'
62 set_language_if_valid 'fr'
63 str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)"
63 str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)"
64 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
64 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
65 repo = Repository::Mercurial.new(
65 repo = Repository::Mercurial.new(
66 :project => @project,
66 :project => @project,
67 :url => "",
67 :url => "",
68 :identifier => 'test',
68 :identifier => 'test',
69 :path_encoding => ''
69 :path_encoding => ''
70 )
70 )
71 assert !repo.save
71 assert !repo.save
72 assert_include str, repo.errors.full_messages
72 assert_include str, repo.errors.full_messages
73 end
73 end
74
74
75 if File.directory?(REPOSITORY_PATH)
75 if File.directory?(REPOSITORY_PATH)
76 def test_scm_available
76 def test_scm_available
77 klass = Repository::Mercurial
77 klass = Repository::Mercurial
78 assert_equal "Mercurial", klass.scm_name
78 assert_equal "Mercurial", klass.scm_name
79 assert klass.scm_adapter_class
79 assert klass.scm_adapter_class
80 assert_not_equal "", klass.scm_command
80 assert_not_equal "", klass.scm_command
81 assert_equal true, klass.scm_available
81 assert_equal true, klass.scm_available
82 end
82 end
83
83
84 def test_entries
84 def test_entries
85 entries = @repository.entries
85 entries = @repository.entries
86 assert_kind_of Redmine::Scm::Adapters::Entries, entries
86 assert_kind_of Redmine::Scm::Adapters::Entries, entries
87 end
87 end
88
88
89 def test_fetch_changesets_from_scratch
89 def test_fetch_changesets_from_scratch
90 assert_equal 0, @repository.changesets.count
90 assert_equal 0, @repository.changesets.count
91 @repository.fetch_changesets
91 @repository.fetch_changesets
92 @project.reload
92 @project.reload
93 assert_equal NUM_REV, @repository.changesets.count
93 assert_equal NUM_REV, @repository.changesets.count
94 assert_equal 46, @repository.filechanges.count
94 assert_equal 46, @repository.filechanges.count
95 assert_equal "Initial import.\nThe repository contains 3 files.",
95 assert_equal "Initial import.\nThe repository contains 3 files.",
96 @repository.changesets.find_by_revision('0').comments
96 @repository.changesets.find_by_revision('0').comments
97 end
97 end
98
98
99 def test_fetch_changesets_incremental
99 def test_fetch_changesets_incremental
100 assert_equal 0, @repository.changesets.count
100 assert_equal 0, @repository.changesets.count
101 @repository.fetch_changesets
101 @repository.fetch_changesets
102 @project.reload
102 @project.reload
103 assert_equal NUM_REV, @repository.changesets.count
103 assert_equal NUM_REV, @repository.changesets.count
104 # Remove changesets with revision > 2
104 # Remove changesets with revision > 2
105 @repository.changesets.all.each {|c| c.destroy if c.revision.to_i > 2}
105 @repository.changesets.all.each {|c| c.destroy if c.revision.to_i > 2}
106 @project.reload
106 @project.reload
107 assert_equal 3, @repository.changesets.count
107 assert_equal 3, @repository.changesets.count
108
108
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 end
112 end
113
113
114 def test_isodatesec
114 def test_isodatesec
115 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher
115 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher
116 if @repository.scm.class.client_version_above?([1, 0])
116 if @repository.scm.class.client_version_above?([1, 0])
117 assert_equal 0, @repository.changesets.count
117 assert_equal 0, @repository.changesets.count
118 @repository.fetch_changesets
118 @repository.fetch_changesets
119 @project.reload
119 @project.reload
120 assert_equal NUM_REV, @repository.changesets.count
120 assert_equal NUM_REV, @repository.changesets.count
121 rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52)
121 rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52)
122 assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on
122 assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on
123 end
123 end
124 end
124 end
125
125
126 def test_changeset_order_by_revision
126 def test_changeset_order_by_revision
127 assert_equal 0, @repository.changesets.count
127 assert_equal 0, @repository.changesets.count
128 @repository.fetch_changesets
128 @repository.fetch_changesets
129 @project.reload
129 @project.reload
130 assert_equal NUM_REV, @repository.changesets.count
130 assert_equal NUM_REV, @repository.changesets.count
131
131
132 c0 = @repository.latest_changeset
132 c0 = @repository.latest_changeset
133 c1 = @repository.changesets.find_by_revision('0')
133 c1 = @repository.changesets.find_by_revision('0')
134 # sorted by revision (id), not by date
134 # sorted by revision (id), not by date
135 assert c0.revision.to_i > c1.revision.to_i
135 assert c0.revision.to_i > c1.revision.to_i
136 assert c0.committed_on < c1.committed_on
136 assert c0.committed_on < c1.committed_on
137 end
137 end
138
138
139 def test_latest_changesets
139 def test_latest_changesets
140 assert_equal 0, @repository.changesets.count
140 assert_equal 0, @repository.changesets.count
141 @repository.fetch_changesets
141 @repository.fetch_changesets
142 @project.reload
142 @project.reload
143 assert_equal NUM_REV, @repository.changesets.count
143 assert_equal NUM_REV, @repository.changesets.count
144
144
145 # with_limit
145 # with_limit
146 changesets = @repository.latest_changesets('', nil, 2)
146 changesets = @repository.latest_changesets('', nil, 2)
147 assert_equal %w|31 30|, changesets.collect(&:revision)
147 assert_equal ["#{NUM_REV - 1}", "#{NUM_REV - 2}"], changesets.collect(&:revision)
148
148
149 # with_filepath
149 # with_filepath
150 changesets = @repository.latest_changesets(
150 changesets = @repository.latest_changesets(
151 '/sql_escape/percent%dir/percent%file1.txt', nil)
151 '/sql_escape/percent%dir/percent%file1.txt', nil)
152 assert_equal %w|30 11 10 9|, changesets.collect(&:revision)
152 assert_equal %w|30 11 10 9|, changesets.collect(&:revision)
153
153
154 changesets = @repository.latest_changesets(
154 changesets = @repository.latest_changesets(
155 '/sql_escape/underscore_dir/understrike_file.txt', nil)
155 '/sql_escape/underscore_dir/understrike_file.txt', nil)
156 assert_equal %w|30 12 9|, changesets.collect(&:revision)
156 assert_equal %w|30 12 9|, changesets.collect(&:revision)
157
157
158 changesets = @repository.latest_changesets('README', nil)
158 changesets = @repository.latest_changesets('README', nil)
159 assert_equal %w|31 30 28 17 8 6 1 0|, changesets.collect(&:revision)
159 assert_equal %w|31 30 28 17 8 6 1 0|, changesets.collect(&:revision)
160
160
161 changesets = @repository.latest_changesets('README','8')
161 changesets = @repository.latest_changesets('README','8')
162 assert_equal %w|8 6 1 0|, changesets.collect(&:revision)
162 assert_equal %w|8 6 1 0|, changesets.collect(&:revision)
163
163
164 changesets = @repository.latest_changesets('README','8', 2)
164 changesets = @repository.latest_changesets('README','8', 2)
165 assert_equal %w|8 6|, changesets.collect(&:revision)
165 assert_equal %w|8 6|, changesets.collect(&:revision)
166
166
167 # with_dirpath
167 # with_dirpath
168 changesets = @repository.latest_changesets('images', nil)
168 changesets = @repository.latest_changesets('images', nil)
169 assert_equal %w|1 0|, changesets.collect(&:revision)
169 assert_equal %w|1 0|, changesets.collect(&:revision)
170
170
171 path = 'sql_escape/percent%dir'
171 path = 'sql_escape/percent%dir'
172 changesets = @repository.latest_changesets(path, nil)
172 changesets = @repository.latest_changesets(path, nil)
173 assert_equal %w|30 13 11 10 9|, changesets.collect(&:revision)
173 assert_equal %w|30 13 11 10 9|, changesets.collect(&:revision)
174
174
175 changesets = @repository.latest_changesets(path, '11')
175 changesets = @repository.latest_changesets(path, '11')
176 assert_equal %w|11 10 9|, changesets.collect(&:revision)
176 assert_equal %w|11 10 9|, changesets.collect(&:revision)
177
177
178 changesets = @repository.latest_changesets(path, '11', 2)
178 changesets = @repository.latest_changesets(path, '11', 2)
179 assert_equal %w|11 10|, changesets.collect(&:revision)
179 assert_equal %w|11 10|, changesets.collect(&:revision)
180
180
181 path = 'sql_escape/underscore_dir'
181 path = 'sql_escape/underscore_dir'
182 changesets = @repository.latest_changesets(path, nil)
182 changesets = @repository.latest_changesets(path, nil)
183 assert_equal %w|30 13 12 9|, changesets.collect(&:revision)
183 assert_equal %w|30 13 12 9|, changesets.collect(&:revision)
184
184
185 changesets = @repository.latest_changesets(path, '12')
185 changesets = @repository.latest_changesets(path, '12')
186 assert_equal %w|12 9|, changesets.collect(&:revision)
186 assert_equal %w|12 9|, changesets.collect(&:revision)
187
187
188 changesets = @repository.latest_changesets(path, '12', 1)
188 changesets = @repository.latest_changesets(path, '12', 1)
189 assert_equal %w|12|, changesets.collect(&:revision)
189 assert_equal %w|12|, changesets.collect(&:revision)
190
190
191 # tag
191 # tag
192 changesets = @repository.latest_changesets('', 'tag_test.00')
192 changesets = @repository.latest_changesets('', 'tag_test.00')
193 assert_equal %w|5 4 3 2 1 0|, changesets.collect(&:revision)
193 assert_equal %w|5 4 3 2 1 0|, changesets.collect(&:revision)
194
194
195 changesets = @repository.latest_changesets('', 'tag_test.00', 2)
195 changesets = @repository.latest_changesets('', 'tag_test.00', 2)
196 assert_equal %w|5 4|, changesets.collect(&:revision)
196 assert_equal %w|5 4|, changesets.collect(&:revision)
197
197
198 changesets = @repository.latest_changesets('sources', 'tag_test.00')
198 changesets = @repository.latest_changesets('sources', 'tag_test.00')
199 assert_equal %w|4 3 2 1 0|, changesets.collect(&:revision)
199 assert_equal %w|4 3 2 1 0|, changesets.collect(&:revision)
200
200
201 changesets = @repository.latest_changesets('sources', 'tag_test.00', 2)
201 changesets = @repository.latest_changesets('sources', 'tag_test.00', 2)
202 assert_equal %w|4 3|, changesets.collect(&:revision)
202 assert_equal %w|4 3|, changesets.collect(&:revision)
203
203
204 # named branch
204 # named branch
205 if @repository.scm.class.client_version_above?([1, 6])
205 if @repository.scm.class.client_version_above?([1, 6])
206 changesets = @repository.latest_changesets('', @branch_char_1)
206 changesets = @repository.latest_changesets('', @branch_char_1)
207 assert_equal %w|27 26|, changesets.collect(&:revision)
207 assert_equal %w|27 26|, changesets.collect(&:revision)
208 end
208 end
209
209
210 changesets = @repository.latest_changesets("latin-1-dir/test-#{@char_1}-subdir", @branch_char_1)
210 changesets = @repository.latest_changesets("latin-1-dir/test-#{@char_1}-subdir", @branch_char_1)
211 assert_equal %w|27|, changesets.collect(&:revision)
211 assert_equal %w|27|, changesets.collect(&:revision)
212 end
212 end
213
213
214 def test_copied_files
214 def test_copied_files
215 assert_equal 0, @repository.changesets.count
215 assert_equal 0, @repository.changesets.count
216 @repository.fetch_changesets
216 @repository.fetch_changesets
217 @project.reload
217 @project.reload
218 assert_equal NUM_REV, @repository.changesets.count
218 assert_equal NUM_REV, @repository.changesets.count
219
219
220 cs1 = @repository.changesets.find_by_revision('13')
220 cs1 = @repository.changesets.find_by_revision('13')
221 assert_not_nil cs1
221 assert_not_nil cs1
222 c1 = cs1.filechanges.sort_by(&:path)
222 c1 = cs1.filechanges.sort_by(&:path)
223 assert_equal 2, c1.size
223 assert_equal 2, c1.size
224
224
225 assert_equal 'A', c1[0].action
225 assert_equal 'A', c1[0].action
226 assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path
226 assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path
227 assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path
227 assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path
228 assert_equal '3a330eb32958', c1[0].from_revision
228 assert_equal '3a330eb32958', c1[0].from_revision
229
229
230 assert_equal 'A', c1[1].action
230 assert_equal 'A', c1[1].action
231 assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path
231 assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path
232 assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path
232 assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path
233
233
234 cs2 = @repository.changesets.find_by_revision('15')
234 cs2 = @repository.changesets.find_by_revision('15')
235 c2 = cs2.filechanges
235 c2 = cs2.filechanges
236 assert_equal 1, c2.size
236 assert_equal 1, c2.size
237
237
238 assert_equal 'A', c2[0].action
238 assert_equal 'A', c2[0].action
239 assert_equal '/README (1)[2]&,%.-3_4', c2[0].path
239 assert_equal '/README (1)[2]&,%.-3_4', c2[0].path
240 assert_equal '/README', c2[0].from_path
240 assert_equal '/README', c2[0].from_path
241 assert_equal '933ca60293d7', c2[0].from_revision
241 assert_equal '933ca60293d7', c2[0].from_revision
242
242
243 cs3 = @repository.changesets.find_by_revision('19')
243 cs3 = @repository.changesets.find_by_revision('19')
244 c3 = cs3.filechanges
244 c3 = cs3.filechanges
245 assert_equal 1, c3.size
245 assert_equal 1, c3.size
246 assert_equal 'A', c3[0].action
246 assert_equal 'A', c3[0].action
247 assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path
247 assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path
248 assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path
248 assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path
249 assert_equal '5d9891a1b425', c3[0].from_revision
249 assert_equal '5d9891a1b425', c3[0].from_revision
250 end
250 end
251
251
252 def test_find_changeset_by_name
252 def test_find_changeset_by_name
253 assert_equal 0, @repository.changesets.count
253 assert_equal 0, @repository.changesets.count
254 @repository.fetch_changesets
254 @repository.fetch_changesets
255 @project.reload
255 @project.reload
256 assert_equal NUM_REV, @repository.changesets.count
256 assert_equal NUM_REV, @repository.changesets.count
257 %w|2 400bb8672109 400|.each do |r|
257 %w|2 400bb8672109 400|.each do |r|
258 assert_equal '2', @repository.find_changeset_by_name(r).revision
258 assert_equal '2', @repository.find_changeset_by_name(r).revision
259 end
259 end
260 end
260 end
261
261
262 def test_find_changeset_by_invalid_name
262 def test_find_changeset_by_invalid_name
263 assert_equal 0, @repository.changesets.count
263 assert_equal 0, @repository.changesets.count
264 @repository.fetch_changesets
264 @repository.fetch_changesets
265 @project.reload
265 @project.reload
266 assert_equal NUM_REV, @repository.changesets.count
266 assert_equal NUM_REV, @repository.changesets.count
267 assert_nil @repository.find_changeset_by_name('100000')
267 assert_nil @repository.find_changeset_by_name('100000')
268 end
268 end
269
269
270 def test_identifier
270 def test_identifier
271 assert_equal 0, @repository.changesets.count
271 assert_equal 0, @repository.changesets.count
272 @repository.fetch_changesets
272 @repository.fetch_changesets
273 @project.reload
273 @project.reload
274 assert_equal NUM_REV, @repository.changesets.count
274 assert_equal NUM_REV, @repository.changesets.count
275 c = @repository.changesets.find_by_revision('2')
275 c = @repository.changesets.find_by_revision('2')
276 assert_equal c.scmid, c.identifier
276 assert_equal c.scmid, c.identifier
277 end
277 end
278
278
279 def test_format_identifier
279 def test_format_identifier
280 assert_equal 0, @repository.changesets.count
280 assert_equal 0, @repository.changesets.count
281 @repository.fetch_changesets
281 @repository.fetch_changesets
282 @project.reload
282 @project.reload
283 assert_equal NUM_REV, @repository.changesets.count
283 assert_equal NUM_REV, @repository.changesets.count
284 c = @repository.changesets.find_by_revision('2')
284 c = @repository.changesets.find_by_revision('2')
285 assert_equal '2:400bb8672109', c.format_identifier
285 assert_equal '2:400bb8672109', c.format_identifier
286 end
286 end
287
287
288 def test_find_changeset_by_empty_name
288 def test_find_changeset_by_empty_name
289 assert_equal 0, @repository.changesets.count
289 assert_equal 0, @repository.changesets.count
290 @repository.fetch_changesets
290 @repository.fetch_changesets
291 @project.reload
291 @project.reload
292 assert_equal NUM_REV, @repository.changesets.count
292 assert_equal NUM_REV, @repository.changesets.count
293 ['', ' ', nil].each do |r|
293 ['', ' ', nil].each do |r|
294 assert_nil @repository.find_changeset_by_name(r)
294 assert_nil @repository.find_changeset_by_name(r)
295 end
295 end
296 end
296 end
297
297
298 def test_parents
298 def test_parents
299 assert_equal 0, @repository.changesets.count
299 assert_equal 0, @repository.changesets.count
300 @repository.fetch_changesets
300 @repository.fetch_changesets
301 @project.reload
301 @project.reload
302 assert_equal NUM_REV, @repository.changesets.count
302 assert_equal NUM_REV, @repository.changesets.count
303 r1 = @repository.changesets.find_by_revision('0')
303 r1 = @repository.changesets.find_by_revision('0')
304 assert_equal [], r1.parents
304 assert_equal [], r1.parents
305 r2 = @repository.changesets.find_by_revision('1')
305 r2 = @repository.changesets.find_by_revision('1')
306 assert_equal 1, r2.parents.length
306 assert_equal 1, r2.parents.length
307 assert_equal "0885933ad4f6",
307 assert_equal "0885933ad4f6",
308 r2.parents[0].identifier
308 r2.parents[0].identifier
309 r3 = @repository.changesets.find_by_revision('30')
309 r3 = @repository.changesets.find_by_revision('30')
310 assert_equal 2, r3.parents.length
310 assert_equal 2, r3.parents.length
311 r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort
311 r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort
312 assert_equal "3a330eb32958", r4[0]
312 assert_equal "3a330eb32958", r4[0]
313 assert_equal "a94b0528f24f", r4[1]
313 assert_equal "a94b0528f24f", r4[1]
314 end
314 end
315
315
316 def test_activities
316 def test_activities
317 c = Changeset.new(:repository => @repository,
317 c = Changeset.new(:repository => @repository,
318 :committed_on => Time.now,
318 :committed_on => Time.now,
319 :revision => '123',
319 :revision => '123',
320 :scmid => 'abc400bb8672',
320 :scmid => 'abc400bb8672',
321 :comments => 'test')
321 :comments => 'test')
322 assert c.event_title.include?('123:abc400bb8672:')
322 assert c.event_title.include?('123:abc400bb8672:')
323 assert_equal 'abc400bb8672', c.event_url[:rev]
323 assert_equal 'abc400bb8672', c.event_url[:rev]
324 end
324 end
325
325
326 def test_previous
326 def test_previous
327 assert_equal 0, @repository.changesets.count
327 assert_equal 0, @repository.changesets.count
328 @repository.fetch_changesets
328 @repository.fetch_changesets
329 @project.reload
329 @project.reload
330 assert_equal NUM_REV, @repository.changesets.count
330 assert_equal NUM_REV, @repository.changesets.count
331 %w|28 3ae45e2d177d 3ae45|.each do |r1|
331 %w|28 3ae45e2d177d 3ae45|.each do |r1|
332 changeset = @repository.find_changeset_by_name(r1)
332 changeset = @repository.find_changeset_by_name(r1)
333 %w|27 7bbf4c738e71 7bbf|.each do |r2|
333 %w|27 7bbf4c738e71 7bbf|.each do |r2|
334 assert_equal @repository.find_changeset_by_name(r2), changeset.previous
334 assert_equal @repository.find_changeset_by_name(r2), changeset.previous
335 end
335 end
336 end
336 end
337 end
337 end
338
338
339 def test_previous_nil
339 def test_previous_nil
340 assert_equal 0, @repository.changesets.count
340 assert_equal 0, @repository.changesets.count
341 @repository.fetch_changesets
341 @repository.fetch_changesets
342 @project.reload
342 @project.reload
343 assert_equal NUM_REV, @repository.changesets.count
343 assert_equal NUM_REV, @repository.changesets.count
344 %w|0 0885933ad4f6 0885|.each do |r1|
344 %w|0 0885933ad4f6 0885|.each do |r1|
345 changeset = @repository.find_changeset_by_name(r1)
345 changeset = @repository.find_changeset_by_name(r1)
346 assert_nil changeset.previous
346 assert_nil changeset.previous
347 end
347 end
348 end
348 end
349
349
350 def test_next
350 def test_next
351 assert_equal 0, @repository.changesets.count
351 assert_equal 0, @repository.changesets.count
352 @repository.fetch_changesets
352 @repository.fetch_changesets
353 @project.reload
353 @project.reload
354 assert_equal NUM_REV, @repository.changesets.count
354 assert_equal NUM_REV, @repository.changesets.count
355 %w|27 7bbf4c738e71 7bbf|.each do |r2|
355 %w|27 7bbf4c738e71 7bbf|.each do |r2|
356 changeset = @repository.find_changeset_by_name(r2)
356 changeset = @repository.find_changeset_by_name(r2)
357 %w|28 3ae45e2d177d 3ae45|.each do |r1|
357 %w|28 3ae45e2d177d 3ae45|.each do |r1|
358 assert_equal @repository.find_changeset_by_name(r1), changeset.next
358 assert_equal @repository.find_changeset_by_name(r1), changeset.next
359 end
359 end
360 end
360 end
361 end
361 end
362
362
363 def test_next_nil
363 def test_next_nil
364 assert_equal 0, @repository.changesets.count
364 assert_equal 0, @repository.changesets.count
365 @repository.fetch_changesets
365 @repository.fetch_changesets
366 @project.reload
366 @project.reload
367 assert_equal NUM_REV, @repository.changesets.count
367 assert_equal NUM_REV, @repository.changesets.count
368 %w|31 31eeee7395c8 31eee|.each do |r1|
368 ["#{NUM_REV - 1}", "2e6d54642923", "2e6d5"].each do |r1|
369 changeset = @repository.find_changeset_by_name(r1)
369 changeset = @repository.find_changeset_by_name(r1)
370 assert_nil changeset.next
370 assert_nil changeset.next
371 end
371 end
372 end
372 end
373 else
373 else
374 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
374 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
375 def test_fake; assert true end
375 def test_fake; assert true end
376 end
376 end
377 end
377 end
General Comments 0
You need to be logged in to leave comments. Login now