##// END OF EJS Templates
scm: fix broken main repository 'root' link...
Toshi MARUYAMA -
r9430:d658ab22d60e
parent child
Show More
@@ -1,29 +1,31
1 1 <%= link_to(@repository.identifier.present? ? h(@repository.identifier) : 'root',
2 :action => 'show', :id => @project, :repository_id => @repository.identifier_param, :path => '', :rev => @rev) %>
2 :action => 'show', :id => @project,
3 :repository_id => @repository.identifier_param,
4 :path => nil, :rev => @rev) %>
3 5 <%
4 6 dirs = path.split('/')
5 7 if 'file' == kind
6 8 filename = dirs.pop
7 9 end
8 10 link_path = ''
9 11 dirs.each do |dir|
10 12 next if dir.blank?
11 13 link_path << '/' unless link_path.empty?
12 14 link_path << "#{dir}"
13 15 %>
14 16 / <%= link_to h(dir), :action => 'show', :id => @project, :repository_id => @repository.identifier_param,
15 17 :path => to_path_param(link_path), :rev => @rev %>
16 18 <% end %>
17 19 <% if filename %>
18 20 / <%= link_to h(filename),
19 21 :action => 'changes', :id => @project, :repository_id => @repository.identifier_param,
20 22 :path => to_path_param("#{link_path}/#{filename}"), :rev => @rev %>
21 23 <% end %>
22 24 <%
23 25 # @rev is revsion or Git and Mercurial branch or tag.
24 26 # For Mercurial *tip*, @rev and @changeset are nil.
25 27 rev_text = @changeset.nil? ? @rev : format_revision(@changeset)
26 28 %>
27 29 <%= "@ #{h rev_text}" unless rev_text.blank? %>
28 30
29 31 <% html_title(with_leading_slash(path)) -%>
@@ -1,409 +1,412
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19
20 20 class RepositoriesSubversionControllerTest < ActionController::TestCase
21 21 tests RepositoriesController
22 22
23 23 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules,
24 24 :repositories, :issues, :issue_statuses, :changesets, :changes,
25 25 :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers
26 26
27 27 PRJ_ID = 3
28 28 NUM_REV = 11
29 29
30 30 def setup
31 31 Setting.default_language = 'en'
32 32 User.current = nil
33 33
34 34 @project = Project.find(PRJ_ID)
35 35 @repository = Repository::Subversion.create(:project => @project,
36 36 :url => self.class.subversion_repository_url)
37 37 assert @repository
38 38 end
39 39
40 40 if repository_configured?('subversion')
41 41 def test_new
42 42 @request.session[:user_id] = 1
43 43 @project.repository.destroy
44 44 get :new, :project_id => 'subproject1', :repository_scm => 'Subversion'
45 45 assert_response :success
46 46 assert_template 'new'
47 47 assert_kind_of Repository::Subversion, assigns(:repository)
48 48 assert assigns(:repository).new_record?
49 49 end
50 50
51 51 def test_show
52 52 assert_equal 0, @repository.changesets.count
53 53 @repository.fetch_changesets
54 54 @project.reload
55 55 assert_equal NUM_REV, @repository.changesets.count
56 56 get :show, :id => PRJ_ID
57 57 assert_response :success
58 58 assert_template 'show'
59 59 assert_not_nil assigns(:entries)
60 60 assert_not_nil assigns(:changesets)
61 61
62 62 entry = assigns(:entries).detect {|e| e.name == 'subversion_test'}
63 63 assert_not_nil entry
64 64 assert_equal 'dir', entry.kind
65 65 assert_select 'tr.dir a[href=/projects/subproject1/repository/show/subversion_test]'
66 66
67 67 assert_tag 'input', :attributes => {:name => 'rev'}
68 68 assert_tag 'a', :content => 'Statistics'
69 69 assert_tag 'a', :content => 'Atom'
70 assert_tag :tag => 'a',
71 :attributes => {:href => '/projects/subproject1/repository'},
72 :content => 'root'
70 73 end
71 74
72 75 def test_show_non_default
73 76 Repository::Subversion.create(:project => @project,
74 77 :url => self.class.subversion_repository_url,
75 78 :is_default => false, :identifier => 'svn')
76 79
77 80 get :show, :id => PRJ_ID, :repository_id => 'svn'
78 81 assert_response :success
79 82 assert_template 'show'
80 83 assert_select 'tr.dir a[href=/projects/subproject1/repository/svn/show/subversion_test]'
81 84 # Repository menu should link to the main repo
82 85 assert_select '#main-menu a[href=/projects/subproject1/repository]'
83 86 end
84 87
85 88 def test_browse_directory
86 89 assert_equal 0, @repository.changesets.count
87 90 @repository.fetch_changesets
88 91 @project.reload
89 92 assert_equal NUM_REV, @repository.changesets.count
90 93 get :show, :id => PRJ_ID, :path => repository_path_hash(['subversion_test'])[:param]
91 94 assert_response :success
92 95 assert_template 'show'
93 96 assert_not_nil assigns(:entries)
94 97 assert_equal [
95 98 '[folder_with_brackets]', 'folder', '.project',
96 99 'helloworld.c', 'textfile.txt'
97 100 ],
98 101 assigns(:entries).collect(&:name)
99 102 entry = assigns(:entries).detect {|e| e.name == 'helloworld.c'}
100 103 assert_equal 'file', entry.kind
101 104 assert_equal 'subversion_test/helloworld.c', entry.path
102 105 assert_tag :a, :content => 'helloworld.c', :attributes => { :class => /text\-x\-c/ }
103 106 end
104 107
105 108 def test_browse_at_given_revision
106 109 assert_equal 0, @repository.changesets.count
107 110 @repository.fetch_changesets
108 111 @project.reload
109 112 assert_equal NUM_REV, @repository.changesets.count
110 113 get :show, :id => PRJ_ID, :path => repository_path_hash(['subversion_test'])[:param],
111 114 :rev => 4
112 115 assert_response :success
113 116 assert_template 'show'
114 117 assert_not_nil assigns(:entries)
115 118 assert_equal ['folder', '.project', 'helloworld.c', 'helloworld.rb', 'textfile.txt'],
116 119 assigns(:entries).collect(&:name)
117 120 end
118 121
119 122 def test_file_changes
120 123 assert_equal 0, @repository.changesets.count
121 124 @repository.fetch_changesets
122 125 @project.reload
123 126 assert_equal NUM_REV, @repository.changesets.count
124 127 get :changes, :id => PRJ_ID,
125 128 :path => repository_path_hash(['subversion_test', 'folder', 'helloworld.rb'])[:param]
126 129 assert_response :success
127 130 assert_template 'changes'
128 131
129 132 changesets = assigns(:changesets)
130 133 assert_not_nil changesets
131 134 assert_equal %w(6 3 2), changesets.collect(&:revision)
132 135
133 136 # svn properties displayed with svn >= 1.5 only
134 137 if Redmine::Scm::Adapters::SubversionAdapter.client_version_above?([1, 5, 0])
135 138 assert_not_nil assigns(:properties)
136 139 assert_equal 'native', assigns(:properties)['svn:eol-style']
137 140 assert_tag :ul,
138 141 :child => { :tag => 'li',
139 142 :child => { :tag => 'b', :content => 'svn:eol-style' },
140 143 :child => { :tag => 'span', :content => 'native' } }
141 144 end
142 145 end
143 146
144 147 def test_directory_changes
145 148 assert_equal 0, @repository.changesets.count
146 149 @repository.fetch_changesets
147 150 @project.reload
148 151 assert_equal NUM_REV, @repository.changesets.count
149 152 get :changes, :id => PRJ_ID,
150 153 :path => repository_path_hash(['subversion_test', 'folder'])[:param]
151 154 assert_response :success
152 155 assert_template 'changes'
153 156
154 157 changesets = assigns(:changesets)
155 158 assert_not_nil changesets
156 159 assert_equal %w(10 9 7 6 5 2), changesets.collect(&:revision)
157 160 end
158 161
159 162 def test_entry
160 163 assert_equal 0, @repository.changesets.count
161 164 @repository.fetch_changesets
162 165 @project.reload
163 166 assert_equal NUM_REV, @repository.changesets.count
164 167 get :entry, :id => PRJ_ID,
165 168 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
166 169 assert_response :success
167 170 assert_template 'entry'
168 171 end
169 172
170 173 def test_entry_should_send_if_too_big
171 174 assert_equal 0, @repository.changesets.count
172 175 @repository.fetch_changesets
173 176 @project.reload
174 177 assert_equal NUM_REV, @repository.changesets.count
175 178 # no files in the test repo is larger than 1KB...
176 179 with_settings :file_max_size_displayed => 0 do
177 180 get :entry, :id => PRJ_ID,
178 181 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
179 182 assert_response :success
180 183 assert_equal 'attachment; filename="helloworld.c"',
181 184 @response.headers['Content-Disposition']
182 185 end
183 186 end
184 187
185 188 def test_entry_at_given_revision
186 189 assert_equal 0, @repository.changesets.count
187 190 @repository.fetch_changesets
188 191 @project.reload
189 192 assert_equal NUM_REV, @repository.changesets.count
190 193 get :entry, :id => PRJ_ID,
191 194 :path => repository_path_hash(['subversion_test', 'helloworld.rb'])[:param],
192 195 :rev => 2
193 196 assert_response :success
194 197 assert_template 'entry'
195 198 # this line was removed in r3 and file was moved in r6
196 199 assert_tag :tag => 'td', :attributes => { :class => /line-code/},
197 200 :content => /Here's the code/
198 201 end
199 202
200 203 def test_entry_not_found
201 204 assert_equal 0, @repository.changesets.count
202 205 @repository.fetch_changesets
203 206 @project.reload
204 207 assert_equal NUM_REV, @repository.changesets.count
205 208 get :entry, :id => PRJ_ID,
206 209 :path => repository_path_hash(['subversion_test', 'zzz.c'])[:param]
207 210 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
208 211 :content => /The entry or revision was not found in the repository/
209 212 end
210 213
211 214 def test_entry_download
212 215 assert_equal 0, @repository.changesets.count
213 216 @repository.fetch_changesets
214 217 @project.reload
215 218 assert_equal NUM_REV, @repository.changesets.count
216 219 get :entry, :id => PRJ_ID,
217 220 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param],
218 221 :format => 'raw'
219 222 assert_response :success
220 223 assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition']
221 224 end
222 225
223 226 def test_directory_entry
224 227 assert_equal 0, @repository.changesets.count
225 228 @repository.fetch_changesets
226 229 @project.reload
227 230 assert_equal NUM_REV, @repository.changesets.count
228 231 get :entry, :id => PRJ_ID,
229 232 :path => repository_path_hash(['subversion_test', 'folder'])[:param]
230 233 assert_response :success
231 234 assert_template 'show'
232 235 assert_not_nil assigns(:entry)
233 236 assert_equal 'folder', assigns(:entry).name
234 237 end
235 238
236 239 # TODO: this test needs fixtures.
237 240 def test_revision
238 241 get :revision, :id => 1, :rev => 2
239 242 assert_response :success
240 243 assert_template 'revision'
241 244 assert_tag :tag => 'ul',
242 245 :child => { :tag => 'li',
243 246 # link to the entry at rev 2
244 247 :child => { :tag => 'a',
245 248 :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/test/some/path/in/the/repo'},
246 249 :content => 'repo',
247 250 # link to partial diff
248 251 :sibling => { :tag => 'a',
249 252 :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/test/some/path/in/the/repo' }
250 253 }
251 254 }
252 255 }
253 256 end
254 257
255 258 def test_invalid_revision
256 259 assert_equal 0, @repository.changesets.count
257 260 @repository.fetch_changesets
258 261 @project.reload
259 262 assert_equal NUM_REV, @repository.changesets.count
260 263 get :revision, :id => PRJ_ID, :rev => 'something_weird'
261 264 assert_response 404
262 265 assert_error_tag :content => /was not found/
263 266 end
264 267
265 268 def test_invalid_revision_diff
266 269 get :diff, :id => PRJ_ID, :rev => '1', :rev_to => 'something_weird'
267 270 assert_response 404
268 271 assert_error_tag :content => /was not found/
269 272 end
270 273
271 274 def test_empty_revision
272 275 assert_equal 0, @repository.changesets.count
273 276 @repository.fetch_changesets
274 277 @project.reload
275 278 assert_equal NUM_REV, @repository.changesets.count
276 279 ['', ' ', nil].each do |r|
277 280 get :revision, :id => PRJ_ID, :rev => r
278 281 assert_response 404
279 282 assert_error_tag :content => /was not found/
280 283 end
281 284 end
282 285
283 286 # TODO: this test needs fixtures.
284 287 def test_revision_with_repository_pointing_to_a_subdirectory
285 288 r = Project.find(1).repository
286 289 # Changes repository url to a subdirectory
287 290 r.update_attribute :url, (r.url + '/test/some')
288 291
289 292 get :revision, :id => 1, :rev => 2
290 293 assert_response :success
291 294 assert_template 'revision'
292 295 assert_tag :tag => 'ul',
293 296 :child => { :tag => 'li',
294 297 # link to the entry at rev 2
295 298 :child => { :tag => 'a',
296 299 :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/path/in/the/repo'},
297 300 :content => 'repo',
298 301 # link to partial diff
299 302 :sibling => { :tag => 'a',
300 303 :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/path/in/the/repo' }
301 304 }
302 305 }
303 306 }
304 307 end
305 308
306 309 def test_revision_diff
307 310 assert_equal 0, @repository.changesets.count
308 311 @repository.fetch_changesets
309 312 @project.reload
310 313 assert_equal NUM_REV, @repository.changesets.count
311 314 ['inline', 'sbs'].each do |dt|
312 315 get :diff, :id => PRJ_ID, :rev => 3, :type => dt
313 316 assert_response :success
314 317 assert_template 'diff'
315 318 assert_tag :tag => 'h2',
316 319 :content => / 3/
317 320 end
318 321 end
319 322
320 323 def test_revision_diff_raw_format
321 324 assert_equal 0, @repository.changesets.count
322 325 @repository.fetch_changesets
323 326 @project.reload
324 327 assert_equal NUM_REV, @repository.changesets.count
325 328
326 329 get :diff, :id => PRJ_ID, :rev => 3, :format => 'diff'
327 330 assert_response :success
328 331 assert_equal 'text/x-patch', @response.content_type
329 332 assert_equal 'Index: subversion_test/textfile.txt', @response.body.split(/\r?\n/).first
330 333 end
331 334
332 335 def test_directory_diff
333 336 assert_equal 0, @repository.changesets.count
334 337 @repository.fetch_changesets
335 338 @project.reload
336 339 assert_equal NUM_REV, @repository.changesets.count
337 340 ['inline', 'sbs'].each do |dt|
338 341 get :diff, :id => PRJ_ID, :rev => 6, :rev_to => 2,
339 342 :path => repository_path_hash(['subversion_test', 'folder'])[:param],
340 343 :type => dt
341 344 assert_response :success
342 345 assert_template 'diff'
343 346
344 347 diff = assigns(:diff)
345 348 assert_not_nil diff
346 349 # 2 files modified
347 350 assert_equal 2, Redmine::UnifiedDiff.new(diff).size
348 351 assert_tag :tag => 'h2', :content => /2:6/
349 352 end
350 353 end
351 354
352 355 def test_annotate
353 356 assert_equal 0, @repository.changesets.count
354 357 @repository.fetch_changesets
355 358 @project.reload
356 359 assert_equal NUM_REV, @repository.changesets.count
357 360 get :annotate, :id => PRJ_ID,
358 361 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
359 362 assert_response :success
360 363 assert_template 'annotate'
361 364 end
362 365
363 366 def test_annotate_at_given_revision
364 367 assert_equal 0, @repository.changesets.count
365 368 @repository.fetch_changesets
366 369 @project.reload
367 370 assert_equal NUM_REV, @repository.changesets.count
368 371 get :annotate, :id => PRJ_ID, :rev => 8,
369 372 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
370 373 assert_response :success
371 374 assert_template 'annotate'
372 375 assert_tag :tag => 'h2', :content => /@ 8/
373 376 end
374 377
375 378 def test_destroy_valid_repository
376 379 @request.session[:user_id] = 1 # admin
377 380 assert_equal 0, @repository.changesets.count
378 381 @repository.fetch_changesets
379 382 assert_equal NUM_REV, @repository.changesets.count
380 383
381 384 assert_difference 'Repository.count', -1 do
382 385 delete :destroy, :id => @repository.id
383 386 end
384 387 assert_response 302
385 388 @project.reload
386 389 assert_nil @project.repository
387 390 end
388 391
389 392 def test_destroy_invalid_repository
390 393 @request.session[:user_id] = 1 # admin
391 394 @project.repository.destroy
392 395 @repository = Repository::Subversion.create!(
393 396 :project => @project,
394 397 :url => "file:///invalid")
395 398 @repository.fetch_changesets
396 399 assert_equal 0, @repository.changesets.count
397 400
398 401 assert_difference 'Repository.count', -1 do
399 402 delete :destroy, :id => @repository.id
400 403 end
401 404 assert_response 302
402 405 @project.reload
403 406 assert_nil @project.repository
404 407 end
405 408 else
406 409 puts "Subversion test repository NOT FOUND. Skipping functional tests !!!"
407 410 def test_fake; assert true end
408 411 end
409 412 end
General Comments 0
You need to be logged in to leave comments. Login now