##// END OF EJS Templates
Rails3: test: scm: mercurial: use "repository_path_hash" for path param...
Toshi MARUYAMA -
r8816:9774782cab72
parent child
Show More
@@ -1,513 +1,526
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19
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 = 32
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 => ['images']
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 => ['images'], :rev => r1
114 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param],
115 :rev => r1
115 assert_response :success
116 assert_response :success
116 assert_template 'show'
117 assert_template 'show'
117 assert_not_nil assigns(:entries)
118 assert_not_nil assigns(:entries)
118 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
119 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
119 assert_not_nil assigns(:changesets)
120 assert_not_nil assigns(:changesets)
120 assert assigns(:changesets).size > 0
121 assert assigns(:changesets).size > 0
121 end
122 end
122 end
123 end
123
124
124 def test_show_directory_sql_escape_percent
125 def test_show_directory_sql_escape_percent
125 assert_equal 0, @repository.changesets.count
126 assert_equal 0, @repository.changesets.count
126 @repository.fetch_changesets
127 @repository.fetch_changesets
127 @project.reload
128 @project.reload
128 assert_equal NUM_REV, @repository.changesets.count
129 assert_equal NUM_REV, @repository.changesets.count
129 [13, '13', '3a330eb32958'].each do |r1|
130 [13, '13', '3a330eb32958'].each do |r1|
130 get :show, :id => PRJ_ID, :path => ['sql_escape', 'percent%dir'],
131 get :show, :id => PRJ_ID,
132 :path => repository_path_hash(['sql_escape', 'percent%dir'])[:param],
131 :rev => r1
133 :rev => r1
132 assert_response :success
134 assert_response :success
133 assert_template 'show'
135 assert_template 'show'
134
136
135 assert_not_nil assigns(:entries)
137 assert_not_nil assigns(:entries)
136 assert_equal ['percent%file1.txt', 'percentfile1.txt'],
138 assert_equal ['percent%file1.txt', 'percentfile1.txt'],
137 assigns(:entries).collect(&:name)
139 assigns(:entries).collect(&:name)
138 changesets = assigns(:changesets)
140 changesets = assigns(:changesets)
139 assert_not_nil changesets
141 assert_not_nil changesets
140 assert assigns(:changesets).size > 0
142 assert assigns(:changesets).size > 0
141 assert_equal %w(13 11 10 9), changesets.collect(&:revision)
143 assert_equal %w(13 11 10 9), changesets.collect(&:revision)
142 end
144 end
143 end
145 end
144
146
145 def test_show_directory_latin_1_path
147 def test_show_directory_latin_1_path
146 assert_equal 0, @repository.changesets.count
148 assert_equal 0, @repository.changesets.count
147 @repository.fetch_changesets
149 @repository.fetch_changesets
148 @project.reload
150 @project.reload
149 assert_equal NUM_REV, @repository.changesets.count
151 assert_equal NUM_REV, @repository.changesets.count
150 [21, '21', 'adf805632193'].each do |r1|
152 [21, '21', 'adf805632193'].each do |r1|
151 get :show, :id => PRJ_ID, :path => ['latin-1-dir'], :rev => r1
153 get :show, :id => PRJ_ID,
154 :path => repository_path_hash(['latin-1-dir'])[:param],
155 :rev => r1
152 assert_response :success
156 assert_response :success
153 assert_template 'show'
157 assert_template 'show'
154
158
155 assert_not_nil assigns(:entries)
159 assert_not_nil assigns(:entries)
156 assert_equal ["make-latin-1-file.rb",
160 assert_equal ["make-latin-1-file.rb",
157 "test-#{@char_1}-1.txt",
161 "test-#{@char_1}-1.txt",
158 "test-#{@char_1}-2.txt",
162 "test-#{@char_1}-2.txt",
159 "test-#{@char_1}.txt"], assigns(:entries).collect(&:name)
163 "test-#{@char_1}.txt"], assigns(:entries).collect(&:name)
160 changesets = assigns(:changesets)
164 changesets = assigns(:changesets)
161 assert_not_nil changesets
165 assert_not_nil changesets
162 assert_equal %w(21 20 19 18 17), changesets.collect(&:revision)
166 assert_equal %w(21 20 19 18 17), changesets.collect(&:revision)
163 end
167 end
164 end
168 end
165
169
166 def show_should_show_branch_selection_form
170 def show_should_show_branch_selection_form
167 @repository.fetch_changesets
171 @repository.fetch_changesets
168 @project.reload
172 @project.reload
169 get :show, :id => PRJ_ID
173 get :show, :id => PRJ_ID
170 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'}
171 assert_tag 'select', :attributes => {:name => 'branch'},
175 assert_tag 'select', :attributes => {:name => 'branch'},
172 :child => {:tag => 'option', :attributes => {:value => 'test-branch-01'}},
176 :child => {:tag => 'option', :attributes => {:value => 'test-branch-01'}},
173 :parent => {:tag => 'form', :attributes => {:id => 'revision_selector'}}
177 :parent => {:tag => 'form', :attributes => {:id => 'revision_selector'}}
174 end
178 end
175
179
176 def test_show_branch
180 def test_show_branch
177 assert_equal 0, @repository.changesets.count
181 assert_equal 0, @repository.changesets.count
178 @repository.fetch_changesets
182 @repository.fetch_changesets
179 @project.reload
183 @project.reload
180 assert_equal NUM_REV, @repository.changesets.count
184 assert_equal NUM_REV, @repository.changesets.count
181 [
185 [
182 'default',
186 'default',
183 @branch_char_1,
187 @branch_char_1,
184 'branch (1)[2]&,%.-3_4',
188 'branch (1)[2]&,%.-3_4',
185 @branch_char_0,
189 @branch_char_0,
186 'test_branch.latin-1',
190 'test_branch.latin-1',
187 'test-branch-00',
191 'test-branch-00',
188 ].each do |bra|
192 ].each do |bra|
189 get :show, :id => PRJ_ID, :rev => bra
193 get :show, :id => PRJ_ID, :rev => bra
190 assert_response :success
194 assert_response :success
191 assert_template 'show'
195 assert_template 'show'
192 assert_not_nil assigns(:entries)
196 assert_not_nil assigns(:entries)
193 assert assigns(:entries).size > 0
197 assert assigns(:entries).size > 0
194 assert_not_nil assigns(:changesets)
198 assert_not_nil assigns(:changesets)
195 assert assigns(:changesets).size > 0
199 assert assigns(:changesets).size > 0
196 end
200 end
197 end
201 end
198
202
199 def test_show_tag
203 def test_show_tag
200 assert_equal 0, @repository.changesets.count
204 assert_equal 0, @repository.changesets.count
201 @repository.fetch_changesets
205 @repository.fetch_changesets
202 @project.reload
206 @project.reload
203 assert_equal NUM_REV, @repository.changesets.count
207 assert_equal NUM_REV, @repository.changesets.count
204 [
208 [
205 @tag_char_1,
209 @tag_char_1,
206 'tag_test.00',
210 'tag_test.00',
207 'tag-init-revision'
211 'tag-init-revision'
208 ].each do |tag|
212 ].each do |tag|
209 get :show, :id => PRJ_ID, :rev => tag
213 get :show, :id => PRJ_ID, :rev => tag
210 assert_response :success
214 assert_response :success
211 assert_template 'show'
215 assert_template 'show'
212 assert_not_nil assigns(:entries)
216 assert_not_nil assigns(:entries)
213 assert assigns(:entries).size > 0
217 assert assigns(:entries).size > 0
214 assert_not_nil assigns(:changesets)
218 assert_not_nil assigns(:changesets)
215 assert assigns(:changesets).size > 0
219 assert assigns(:changesets).size > 0
216 end
220 end
217 end
221 end
218
222
219 def test_changes
223 def test_changes
220 get :changes, :id => PRJ_ID, :path => ['images', 'edit.png']
224 get :changes, :id => PRJ_ID,
225 :path => repository_path_hash(['images', 'edit.png'])[:param]
221 assert_response :success
226 assert_response :success
222 assert_template 'changes'
227 assert_template 'changes'
223 assert_tag :tag => 'h2', :content => 'edit.png'
228 assert_tag :tag => 'h2', :content => 'edit.png'
224 end
229 end
225
230
226 def test_entry_show
231 def test_entry_show
227 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
232 get :entry, :id => PRJ_ID,
233 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
228 assert_response :success
234 assert_response :success
229 assert_template 'entry'
235 assert_template 'entry'
230 # Line 10
236 # Line 10
231 assert_tag :tag => 'th',
237 assert_tag :tag => 'th',
232 :content => '10',
238 :content => '10',
233 :attributes => { :class => 'line-num' },
239 :attributes => { :class => 'line-num' },
234 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
240 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
235 end
241 end
236
242
237 def test_entry_show_latin_1_path
243 def test_entry_show_latin_1_path
238 [21, '21', 'adf805632193'].each do |r1|
244 [21, '21', 'adf805632193'].each do |r1|
239 get :entry, :id => PRJ_ID,
245 get :entry, :id => PRJ_ID,
240 :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1
246 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}-2.txt"])[:param],
247 :rev => r1
241 assert_response :success
248 assert_response :success
242 assert_template 'entry'
249 assert_template 'entry'
243 assert_tag :tag => 'th',
250 assert_tag :tag => 'th',
244 :content => '1',
251 :content => '1',
245 :attributes => { :class => 'line-num' },
252 :attributes => { :class => 'line-num' },
246 :sibling => { :tag => 'td',
253 :sibling => { :tag => 'td',
247 :content => /Mercurial is a distributed version control system/ }
254 :content => /Mercurial is a distributed version control system/ }
248 end
255 end
249 end
256 end
250
257
251 def test_entry_show_latin_1_contents
258 def test_entry_show_latin_1_contents
252 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
259 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
253 [27, '27', '7bbf4c738e71'].each do |r1|
260 [27, '27', '7bbf4c738e71'].each do |r1|
254 get :entry, :id => PRJ_ID,
261 get :entry, :id => PRJ_ID,
255 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
262 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
263 :rev => r1
256 assert_response :success
264 assert_response :success
257 assert_template 'entry'
265 assert_template 'entry'
258 assert_tag :tag => 'th',
266 assert_tag :tag => 'th',
259 :content => '1',
267 :content => '1',
260 :attributes => { :class => 'line-num' },
268 :attributes => { :class => 'line-num' },
261 :sibling => { :tag => 'td',
269 :sibling => { :tag => 'td',
262 :content => /test-#{@char_1}.txt/ }
270 :content => /test-#{@char_1}.txt/ }
263 end
271 end
264 end
272 end
265 end
273 end
266
274
267 def test_entry_download
275 def test_entry_download
268 get :entry, :id => PRJ_ID,
276 get :entry, :id => PRJ_ID,
269 :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
277 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
278 :format => 'raw'
270 assert_response :success
279 assert_response :success
271 # File content
280 # File content
272 assert @response.body.include?('WITHOUT ANY WARRANTY')
281 assert @response.body.include?('WITHOUT ANY WARRANTY')
273 end
282 end
274
283
275 def test_entry_binary_force_download
284 def test_entry_binary_force_download
276 get :entry, :id => PRJ_ID, :rev => 1, :path => ['images', 'edit.png']
285 get :entry, :id => PRJ_ID, :rev => 1,
286 :path => repository_path_hash(['images', 'edit.png'])[:param]
277 assert_response :success
287 assert_response :success
278 assert_equal 'image/png', @response.content_type
288 assert_equal 'image/png', @response.content_type
279 end
289 end
280
290
281 def test_directory_entry
291 def test_directory_entry
282 get :entry, :id => PRJ_ID, :path => ['sources']
292 get :entry, :id => PRJ_ID,
293 :path => repository_path_hash(['sources'])[:param]
283 assert_response :success
294 assert_response :success
284 assert_template 'show'
295 assert_template 'show'
285 assert_not_nil assigns(:entry)
296 assert_not_nil assigns(:entry)
286 assert_equal 'sources', assigns(:entry).name
297 assert_equal 'sources', assigns(:entry).name
287 end
298 end
288
299
289 def test_diff
300 def test_diff
290 assert_equal 0, @repository.changesets.count
301 assert_equal 0, @repository.changesets.count
291 @repository.fetch_changesets
302 @repository.fetch_changesets
292 @project.reload
303 @project.reload
293 assert_equal NUM_REV, @repository.changesets.count
304 assert_equal NUM_REV, @repository.changesets.count
294 [4, '4', 'def6d2f1254a'].each do |r1|
305 [4, '4', 'def6d2f1254a'].each do |r1|
295 # Full diff of changeset 4
306 # Full diff of changeset 4
296 ['inline', 'sbs'].each do |dt|
307 ['inline', 'sbs'].each do |dt|
297 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
308 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
298 assert_response :success
309 assert_response :success
299 assert_template 'diff'
310 assert_template 'diff'
300 if @diff_c_support
311 if @diff_c_support
301 # Line 22 removed
312 # Line 22 removed
302 assert_tag :tag => 'th',
313 assert_tag :tag => 'th',
303 :content => '22',
314 :content => '22',
304 :sibling => { :tag => 'td',
315 :sibling => { :tag => 'td',
305 :attributes => { :class => /diff_out/ },
316 :attributes => { :class => /diff_out/ },
306 :content => /def remove/ }
317 :content => /def remove/ }
307 assert_tag :tag => 'h2', :content => /4:def6d2f1254a/
318 assert_tag :tag => 'h2', :content => /4:def6d2f1254a/
308 end
319 end
309 end
320 end
310 end
321 end
311 end
322 end
312
323
313 def test_diff_two_revs
324 def test_diff_two_revs
314 assert_equal 0, @repository.changesets.count
325 assert_equal 0, @repository.changesets.count
315 @repository.fetch_changesets
326 @repository.fetch_changesets
316 @project.reload
327 @project.reload
317 assert_equal NUM_REV, @repository.changesets.count
328 assert_equal NUM_REV, @repository.changesets.count
318 [2, '400bb8672109', '400', 400].each do |r1|
329 [2, '400bb8672109', '400', 400].each do |r1|
319 [4, 'def6d2f1254a'].each do |r2|
330 [4, 'def6d2f1254a'].each do |r2|
320 ['inline', 'sbs'].each do |dt|
331 ['inline', 'sbs'].each do |dt|
321 get :diff,
332 get :diff,
322 :id => PRJ_ID,
333 :id => PRJ_ID,
323 :rev => r1,
334 :rev => r1,
324 :rev_to => r2,
335 :rev_to => r2,
325 :type => dt
336 :type => dt
326 assert_response :success
337 assert_response :success
327 assert_template 'diff'
338 assert_template 'diff'
328 diff = assigns(:diff)
339 diff = assigns(:diff)
329 assert_not_nil diff
340 assert_not_nil diff
330 assert_tag :tag => 'h2',
341 assert_tag :tag => 'h2',
331 :content => /4:def6d2f1254a 2:400bb8672109/
342 :content => /4:def6d2f1254a 2:400bb8672109/
332 end
343 end
333 end
344 end
334 end
345 end
335 end
346 end
336
347
337 def test_diff_latin_1_path
348 def test_diff_latin_1_path
338 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
349 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
339 [21, 'adf805632193'].each do |r1|
350 [21, 'adf805632193'].each do |r1|
340 ['inline', 'sbs'].each do |dt|
351 ['inline', 'sbs'].each do |dt|
341 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
352 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
342 assert_response :success
353 assert_response :success
343 assert_template 'diff'
354 assert_template 'diff'
344 assert_tag :tag => 'thead',
355 assert_tag :tag => 'thead',
345 :descendant => {
356 :descendant => {
346 :tag => 'th',
357 :tag => 'th',
347 :attributes => { :class => 'filename' } ,
358 :attributes => { :class => 'filename' } ,
348 :content => /latin-1-dir\/test-#{@char_1}-2.txt/ ,
359 :content => /latin-1-dir\/test-#{@char_1}-2.txt/ ,
349 },
360 },
350 :sibling => {
361 :sibling => {
351 :tag => 'tbody',
362 :tag => 'tbody',
352 :descendant => {
363 :descendant => {
353 :tag => 'td',
364 :tag => 'td',
354 :attributes => { :class => /diff_in/ },
365 :attributes => { :class => /diff_in/ },
355 :content => /It is written in Python/
366 :content => /It is written in Python/
356 }
367 }
357 }
368 }
358 end
369 end
359 end
370 end
360 end
371 end
361 end
372 end
362
373
363 def test_annotate
374 def test_annotate
364 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
375 get :annotate, :id => PRJ_ID,
376 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
365 assert_response :success
377 assert_response :success
366 assert_template 'annotate'
378 assert_template 'annotate'
367 # Line 23, revision 4:def6d2f1254a
379 # Line 23, revision 4:def6d2f1254a
368 assert_tag :tag => 'th',
380 assert_tag :tag => 'th',
369 :content => '23',
381 :content => '23',
370 :attributes => { :class => 'line-num' },
382 :attributes => { :class => 'line-num' },
371 :sibling =>
383 :sibling =>
372 {
384 {
373 :tag => 'td',
385 :tag => 'td',
374 :attributes => { :class => 'revision' },
386 :attributes => { :class => 'revision' },
375 :child => { :tag => 'a', :content => '4:def6d2f1254a' }
387 :child => { :tag => 'a', :content => '4:def6d2f1254a' }
376 }
388 }
377 assert_tag :tag => 'th',
389 assert_tag :tag => 'th',
378 :content => '23',
390 :content => '23',
379 :attributes => { :class => 'line-num' },
391 :attributes => { :class => 'line-num' },
380 :sibling =>
392 :sibling =>
381 {
393 {
382 :tag => 'td' ,
394 :tag => 'td' ,
383 :content => 'jsmith' ,
395 :content => 'jsmith' ,
384 :attributes => { :class => 'author' },
396 :attributes => { :class => 'author' },
385 }
397 }
386 assert_tag :tag => 'th',
398 assert_tag :tag => 'th',
387 :content => '23',
399 :content => '23',
388 :attributes => { :class => 'line-num' },
400 :attributes => { :class => 'line-num' },
389 :sibling => { :tag => 'td', :content => /watcher =/ }
401 :sibling => { :tag => 'td', :content => /watcher =/ }
390 end
402 end
391
403
392 def test_annotate_not_in_tip
404 def test_annotate_not_in_tip
393 assert_equal 0, @repository.changesets.count
405 assert_equal 0, @repository.changesets.count
394 @repository.fetch_changesets
406 @repository.fetch_changesets
395 @project.reload
407 @project.reload
396 assert_equal NUM_REV, @repository.changesets.count
408 assert_equal NUM_REV, @repository.changesets.count
397
398 get :annotate, :id => PRJ_ID,
409 get :annotate, :id => PRJ_ID,
399 :path => ['sources', 'welcome_controller.rb']
410 :path => repository_path_hash(['sources', 'welcome_controller.rb'])[:param]
400 assert_response 404
411 assert_response 404
401 assert_error_tag :content => /was not found/
412 assert_error_tag :content => /was not found/
402 end
413 end
403
414
404 def test_annotate_at_given_revision
415 def test_annotate_at_given_revision
405 assert_equal 0, @repository.changesets.count
416 assert_equal 0, @repository.changesets.count
406 @repository.fetch_changesets
417 @repository.fetch_changesets
407 @project.reload
418 @project.reload
408 assert_equal NUM_REV, @repository.changesets.count
419 assert_equal NUM_REV, @repository.changesets.count
409 [2, '400bb8672109', '400', 400].each do |r1|
420 [2, '400bb8672109', '400', 400].each do |r1|
410 get :annotate, :id => PRJ_ID, :rev => r1,
421 get :annotate, :id => PRJ_ID, :rev => r1,
411 :path => ['sources', 'watchers_controller.rb']
422 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
412 assert_response :success
423 assert_response :success
413 assert_template 'annotate'
424 assert_template 'annotate'
414 assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/
425 assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/
415 end
426 end
416 end
427 end
417
428
418 def test_annotate_latin_1_path
429 def test_annotate_latin_1_path
419 [21, '21', 'adf805632193'].each do |r1|
430 [21, '21', 'adf805632193'].each do |r1|
420 get :annotate, :id => PRJ_ID,
431 get :annotate, :id => PRJ_ID,
421 :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1
432 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}-2.txt"])[:param],
433 :rev => r1
422 assert_response :success
434 assert_response :success
423 assert_template 'annotate'
435 assert_template 'annotate'
424 assert_tag :tag => 'th',
436 assert_tag :tag => 'th',
425 :content => '1',
437 :content => '1',
426 :attributes => { :class => 'line-num' },
438 :attributes => { :class => 'line-num' },
427 :sibling =>
439 :sibling =>
428 {
440 {
429 :tag => 'td',
441 :tag => 'td',
430 :attributes => { :class => 'revision' },
442 :attributes => { :class => 'revision' },
431 :child => { :tag => 'a', :content => '20:709858aafd1b' }
443 :child => { :tag => 'a', :content => '20:709858aafd1b' }
432 }
444 }
433 assert_tag :tag => 'th',
445 assert_tag :tag => 'th',
434 :content => '1',
446 :content => '1',
435 :attributes => { :class => 'line-num' },
447 :attributes => { :class => 'line-num' },
436 :sibling =>
448 :sibling =>
437 {
449 {
438 :tag => 'td' ,
450 :tag => 'td' ,
439 :content => 'jsmith' ,
451 :content => 'jsmith' ,
440 :attributes => { :class => 'author' },
452 :attributes => { :class => 'author' },
441 }
453 }
442 assert_tag :tag => 'th',
454 assert_tag :tag => 'th',
443 :content => '1',
455 :content => '1',
444 :attributes => { :class => 'line-num' },
456 :attributes => { :class => 'line-num' },
445 :sibling => { :tag => 'td',
457 :sibling => { :tag => 'td',
446 :content => /Mercurial is a distributed version control system/ }
458 :content => /Mercurial is a distributed version control system/ }
447
459
448 end
460 end
449 end
461 end
450
462
451 def test_annotate_latin_1_contents
463 def test_annotate_latin_1_contents
452 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
464 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
453 [27, '7bbf4c738e71'].each do |r1|
465 [27, '7bbf4c738e71'].each do |r1|
454 get :annotate, :id => PRJ_ID,
466 get :annotate, :id => PRJ_ID,
455 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
467 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
468 :rev => r1
456 assert_tag :tag => 'th',
469 assert_tag :tag => 'th',
457 :content => '1',
470 :content => '1',
458 :attributes => { :class => 'line-num' },
471 :attributes => { :class => 'line-num' },
459 :sibling => { :tag => 'td',
472 :sibling => { :tag => 'td',
460 :content => /test-#{@char_1}.txt/ }
473 :content => /test-#{@char_1}.txt/ }
461 end
474 end
462 end
475 end
463 end
476 end
464
477
465 def test_empty_revision
478 def test_empty_revision
466 assert_equal 0, @repository.changesets.count
479 assert_equal 0, @repository.changesets.count
467 @repository.fetch_changesets
480 @repository.fetch_changesets
468 @project.reload
481 @project.reload
469 assert_equal NUM_REV, @repository.changesets.count
482 assert_equal NUM_REV, @repository.changesets.count
470 ['', ' ', nil].each do |r|
483 ['', ' ', nil].each do |r|
471 get :revision, :id => PRJ_ID, :rev => r
484 get :revision, :id => PRJ_ID, :rev => r
472 assert_response 404
485 assert_response 404
473 assert_error_tag :content => /was not found/
486 assert_error_tag :content => /was not found/
474 end
487 end
475 end
488 end
476
489
477 def test_destroy_valid_repository
490 def test_destroy_valid_repository
478 @request.session[:user_id] = 1 # admin
491 @request.session[:user_id] = 1 # admin
479 assert_equal 0, @repository.changesets.count
492 assert_equal 0, @repository.changesets.count
480 @repository.fetch_changesets
493 @repository.fetch_changesets
481 assert_equal NUM_REV, @repository.changesets.count
494 assert_equal NUM_REV, @repository.changesets.count
482
495
483 assert_difference 'Repository.count', -1 do
496 assert_difference 'Repository.count', -1 do
484 delete :destroy, :id => @repository.id
497 delete :destroy, :id => @repository.id
485 end
498 end
486 assert_response 302
499 assert_response 302
487 @project.reload
500 @project.reload
488 assert_nil @project.repository
501 assert_nil @project.repository
489 end
502 end
490
503
491 def test_destroy_invalid_repository
504 def test_destroy_invalid_repository
492 @request.session[:user_id] = 1 # admin
505 @request.session[:user_id] = 1 # admin
493 @project.repository.destroy
506 @project.repository.destroy
494 @repository = Repository::Mercurial.create!(
507 @repository = Repository::Mercurial.create!(
495 :project => Project.find(PRJ_ID),
508 :project => Project.find(PRJ_ID),
496 :url => "/invalid",
509 :url => "/invalid",
497 :path_encoding => 'ISO-8859-1'
510 :path_encoding => 'ISO-8859-1'
498 )
511 )
499 @repository.fetch_changesets
512 @repository.fetch_changesets
500 assert_equal 0, @repository.changesets.count
513 assert_equal 0, @repository.changesets.count
501
514
502 assert_difference 'Repository.count', -1 do
515 assert_difference 'Repository.count', -1 do
503 delete :destroy, :id => @repository.id
516 delete :destroy, :id => @repository.id
504 end
517 end
505 assert_response 302
518 assert_response 302
506 @project.reload
519 @project.reload
507 assert_nil @project.repository
520 assert_nil @project.repository
508 end
521 end
509 else
522 else
510 puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
523 puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
511 def test_fake; assert true end
524 def test_fake; assert true end
512 end
525 end
513 end
526 end
General Comments 0
You need to be logged in to leave comments. Login now