##// END OF EJS Templates
Show repository images inline when clicking 'View' (#10362)....
Jean-Philippe Lang -
r9593:234e5d59acf4
parent child
Show More
@@ -1,457 +1,458
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2012 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 'SVG/Graph/Bar'
19 19 require 'SVG/Graph/BarHorizontal'
20 20 require 'digest/sha1'
21 21 require 'redmine/scm/adapters/abstract_adapter'
22 22
23 23 class ChangesetNotFound < Exception; end
24 24 class InvalidRevisionParam < Exception; end
25 25
26 26 class RepositoriesController < ApplicationController
27 27 menu_item :repository
28 28 menu_item :settings, :only => [:new, :create, :edit, :update, :destroy, :committers]
29 29 default_search_scope :changesets
30 30
31 31 before_filter :find_project_by_project_id, :only => [:new, :create]
32 32 before_filter :find_repository, :only => [:edit, :update, :destroy, :committers]
33 33 before_filter :find_project_repository, :except => [:new, :create, :edit, :update, :destroy, :committers]
34 34 before_filter :find_changeset, :only => [:revision, :add_related_issue, :remove_related_issue]
35 35 before_filter :authorize
36 36 accept_rss_auth :revisions
37 37
38 38 rescue_from Redmine::Scm::Adapters::CommandFailed, :with => :show_error_command_failed
39 39
40 40 def new
41 41 scm = params[:repository_scm] || (Redmine::Scm::Base.all & Setting.enabled_scm).first
42 42 @repository = Repository.factory(scm)
43 43 @repository.is_default = @project.repository.nil?
44 44 @repository.project = @project
45 45 render :layout => !request.xhr?
46 46 end
47 47
48 48 def create
49 49 attrs = pickup_extra_info
50 50 @repository = Repository.factory(params[:repository_scm], attrs[:attrs])
51 51 if attrs[:attrs_extra].keys.any?
52 52 @repository.merge_extra_info(attrs[:attrs_extra])
53 53 end
54 54 @repository.project = @project
55 55 if request.post? && @repository.save
56 56 redirect_to settings_project_path(@project, :tab => 'repositories')
57 57 else
58 58 render :action => 'new'
59 59 end
60 60 end
61 61
62 62 def edit
63 63 end
64 64
65 65 def update
66 66 attrs = pickup_extra_info
67 67 @repository.attributes = attrs[:attrs]
68 68 if attrs[:attrs_extra].keys.any?
69 69 @repository.merge_extra_info(attrs[:attrs_extra])
70 70 end
71 71 @repository.project = @project
72 72 if request.put? && @repository.save
73 73 redirect_to settings_project_path(@project, :tab => 'repositories')
74 74 else
75 75 render :action => 'edit'
76 76 end
77 77 end
78 78
79 79 def pickup_extra_info
80 80 p = {}
81 81 p_extra = {}
82 82 params[:repository].each do |k, v|
83 83 if k =~ /^extra_/
84 84 p_extra[k] = v
85 85 else
86 86 p[k] = v
87 87 end
88 88 end
89 89 {:attrs => p, :attrs_extra => p_extra}
90 90 end
91 91 private :pickup_extra_info
92 92
93 93 def committers
94 94 @committers = @repository.committers
95 95 @users = @project.users
96 96 additional_user_ids = @committers.collect(&:last).collect(&:to_i) - @users.collect(&:id)
97 97 @users += User.find_all_by_id(additional_user_ids) unless additional_user_ids.empty?
98 98 @users.compact!
99 99 @users.sort!
100 100 if request.post? && params[:committers].is_a?(Hash)
101 101 # Build a hash with repository usernames as keys and corresponding user ids as values
102 102 @repository.committer_ids = params[:committers].values.inject({}) {|h, c| h[c.first] = c.last; h}
103 103 flash[:notice] = l(:notice_successful_update)
104 104 redirect_to settings_project_path(@project, :tab => 'repositories')
105 105 end
106 106 end
107 107
108 108 def destroy
109 109 @repository.destroy if request.delete?
110 110 redirect_to settings_project_path(@project, :tab => 'repositories')
111 111 end
112 112
113 113 def show
114 114 @repository.fetch_changesets if Setting.autofetch_changesets? && @path.empty?
115 115
116 116 @entries = @repository.entries(@path, @rev)
117 117 @changeset = @repository.find_changeset_by_name(@rev)
118 118 if request.xhr?
119 119 @entries ? render(:partial => 'dir_list_content') : render(:nothing => true)
120 120 else
121 121 (show_error_not_found; return) unless @entries
122 122 @changesets = @repository.latest_changesets(@path, @rev)
123 123 @properties = @repository.properties(@path, @rev)
124 124 @repositories = @project.repositories
125 125 render :action => 'show'
126 126 end
127 127 end
128 128
129 129 alias_method :browse, :show
130 130
131 131 def changes
132 132 @entry = @repository.entry(@path, @rev)
133 133 (show_error_not_found; return) unless @entry
134 134 @changesets = @repository.latest_changesets(@path, @rev, Setting.repository_log_display_limit.to_i)
135 135 @properties = @repository.properties(@path, @rev)
136 136 @changeset = @repository.find_changeset_by_name(@rev)
137 137 end
138 138
139 139 def revisions
140 140 @changeset_count = @repository.changesets.count
141 141 @changeset_pages = Paginator.new self, @changeset_count,
142 142 per_page_option,
143 143 params['page']
144 144 @changesets = @repository.changesets.find(:all,
145 145 :limit => @changeset_pages.items_per_page,
146 146 :offset => @changeset_pages.current.offset,
147 147 :include => [:user, :repository, :parents])
148 148
149 149 respond_to do |format|
150 150 format.html { render :layout => false if request.xhr? }
151 151 format.atom { render_feed(@changesets, :title => "#{@project.name}: #{l(:label_revision_plural)}") }
152 152 end
153 153 end
154 154
155 155 def raw
156 156 entry_and_raw(true)
157 157 end
158 158
159 159 def entry
160 160 entry_and_raw(false)
161 161 end
162 162
163 163 def entry_and_raw(is_raw)
164 164 @entry = @repository.entry(@path, @rev)
165 165 (show_error_not_found; return) unless @entry
166 166
167 167 # If the entry is a dir, show the browser
168 168 (show; return) if @entry.is_dir?
169 169
170 170 @content = @repository.cat(@path, @rev)
171 171 (show_error_not_found; return) unless @content
172 172 if is_raw ||
173 173 (@content.size && @content.size > Setting.file_max_size_displayed.to_i.kilobyte) ||
174 174 ! is_entry_text_data?(@content, @path)
175 175 # Force the download
176 176 send_opt = { :filename => filename_for_content_disposition(@path.split('/').last) }
177 177 send_type = Redmine::MimeType.of(@path)
178 178 send_opt[:type] = send_type.to_s if send_type
179 send_opt[:disposition] = (Redmine::MimeType.is_type?('image', @path) && !is_raw ? 'inline' : 'attachment')
179 180 send_data @content, send_opt
180 181 else
181 182 # Prevent empty lines when displaying a file with Windows style eol
182 183 # TODO: UTF-16
183 184 # Is this needs? AttachmentsController reads file simply.
184 185 @content.gsub!("\r\n", "\n")
185 186 @changeset = @repository.find_changeset_by_name(@rev)
186 187 end
187 188 end
188 189 private :entry_and_raw
189 190
190 191 def is_entry_text_data?(ent, path)
191 192 # UTF-16 contains "\x00".
192 193 # It is very strict that file contains less than 30% of ascii symbols
193 194 # in non Western Europe.
194 195 return true if Redmine::MimeType.is_type?('text', path)
195 196 # Ruby 1.8.6 has a bug of integer divisions.
196 197 # http://apidock.com/ruby/v1_8_6_287/String/is_binary_data%3F
197 198 return false if ent.is_binary_data?
198 199 true
199 200 end
200 201 private :is_entry_text_data?
201 202
202 203 def annotate
203 204 @entry = @repository.entry(@path, @rev)
204 205 (show_error_not_found; return) unless @entry
205 206
206 207 @annotate = @repository.scm.annotate(@path, @rev)
207 208 if @annotate.nil? || @annotate.empty?
208 209 (render_error l(:error_scm_annotate); return)
209 210 end
210 211 ann_buf_size = 0
211 212 @annotate.lines.each do |buf|
212 213 ann_buf_size += buf.size
213 214 end
214 215 if ann_buf_size > Setting.file_max_size_displayed.to_i.kilobyte
215 216 (render_error l(:error_scm_annotate_big_text_file); return)
216 217 end
217 218 @changeset = @repository.find_changeset_by_name(@rev)
218 219 end
219 220
220 221 def revision
221 222 respond_to do |format|
222 223 format.html
223 224 format.js {render :layout => false}
224 225 end
225 226 end
226 227
227 228 # Adds a related issue to a changeset
228 229 # POST /projects/:project_id/repository/(:repository_id/)revisions/:rev/issues
229 230 def add_related_issue
230 231 @issue = @changeset.find_referenced_issue_by_id(params[:issue_id])
231 232 if @issue && (!@issue.visible? || @changeset.issues.include?(@issue))
232 233 @issue = nil
233 234 end
234 235
235 236 if @issue
236 237 @changeset.issues << @issue
237 238 respond_to do |format|
238 239 format.js {
239 240 render :update do |page|
240 241 page.replace_html "related-issues", :partial => "related_issues"
241 242 page.visual_effect :highlight, "related-issue-#{@issue.id}"
242 243 end
243 244 }
244 245 end
245 246 else
246 247 respond_to do |format|
247 248 format.js {
248 249 render :update do |page|
249 250 page.alert(l(:label_issue) + ' ' + l('activerecord.errors.messages.invalid'))
250 251 end
251 252 }
252 253 end
253 254 end
254 255 end
255 256
256 257 # Removes a related issue from a changeset
257 258 # DELETE /projects/:project_id/repository/(:repository_id/)revisions/:rev/issues/:issue_id
258 259 def remove_related_issue
259 260 @issue = Issue.visible.find_by_id(params[:issue_id])
260 261 if @issue
261 262 @changeset.issues.delete(@issue)
262 263 end
263 264
264 265 respond_to do |format|
265 266 format.js {
266 267 render :update do |page|
267 268 page.remove "related-issue-#{@issue.id}"
268 269 end if @issue
269 270 }
270 271 end
271 272 end
272 273
273 274 def diff
274 275 if params[:format] == 'diff'
275 276 @diff = @repository.diff(@path, @rev, @rev_to)
276 277 (show_error_not_found; return) unless @diff
277 278 filename = "changeset_r#{@rev}"
278 279 filename << "_r#{@rev_to}" if @rev_to
279 280 send_data @diff.join, :filename => "#{filename}.diff",
280 281 :type => 'text/x-patch',
281 282 :disposition => 'attachment'
282 283 else
283 284 @diff_type = params[:type] || User.current.pref[:diff_type] || 'inline'
284 285 @diff_type = 'inline' unless %w(inline sbs).include?(@diff_type)
285 286
286 287 # Save diff type as user preference
287 288 if User.current.logged? && @diff_type != User.current.pref[:diff_type]
288 289 User.current.pref[:diff_type] = @diff_type
289 290 User.current.preference.save
290 291 end
291 292 @cache_key = "repositories/diff/#{@repository.id}/" +
292 293 Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}-#{current_language}")
293 294 unless read_fragment(@cache_key)
294 295 @diff = @repository.diff(@path, @rev, @rev_to)
295 296 show_error_not_found unless @diff
296 297 end
297 298
298 299 @changeset = @repository.find_changeset_by_name(@rev)
299 300 @changeset_to = @rev_to ? @repository.find_changeset_by_name(@rev_to) : nil
300 301 @diff_format_revisions = @repository.diff_format_revisions(@changeset, @changeset_to)
301 302 end
302 303 end
303 304
304 305 def stats
305 306 end
306 307
307 308 def graph
308 309 data = nil
309 310 case params[:graph]
310 311 when "commits_per_month"
311 312 data = graph_commits_per_month(@repository)
312 313 when "commits_per_author"
313 314 data = graph_commits_per_author(@repository)
314 315 end
315 316 if data
316 317 headers["Content-Type"] = "image/svg+xml"
317 318 send_data(data, :type => "image/svg+xml", :disposition => "inline")
318 319 else
319 320 render_404
320 321 end
321 322 end
322 323
323 324 private
324 325
325 326 def find_repository
326 327 @repository = Repository.find(params[:id])
327 328 @project = @repository.project
328 329 rescue ActiveRecord::RecordNotFound
329 330 render_404
330 331 end
331 332
332 333 REV_PARAM_RE = %r{\A[a-f0-9]*\Z}i
333 334
334 335 def find_project_repository
335 336 @project = Project.find(params[:id])
336 337 if params[:repository_id].present?
337 338 @repository = @project.repositories.find_by_identifier_param(params[:repository_id])
338 339 else
339 340 @repository = @project.repository
340 341 end
341 342 (render_404; return false) unless @repository
342 343 @path = params[:path].is_a?(Array) ? params[:path].join('/') : params[:path].to_s
343 344 @rev = params[:rev].blank? ? @repository.default_branch : params[:rev].to_s.strip
344 345 @rev_to = params[:rev_to]
345 346
346 347 unless @rev.to_s.match(REV_PARAM_RE) && @rev_to.to_s.match(REV_PARAM_RE)
347 348 if @repository.branches.blank?
348 349 raise InvalidRevisionParam
349 350 end
350 351 end
351 352 rescue ActiveRecord::RecordNotFound
352 353 render_404
353 354 rescue InvalidRevisionParam
354 355 show_error_not_found
355 356 end
356 357
357 358 def find_changeset
358 359 if @rev.present?
359 360 @changeset = @repository.find_changeset_by_name(@rev)
360 361 end
361 362 show_error_not_found unless @changeset
362 363 end
363 364
364 365 def show_error_not_found
365 366 render_error :message => l(:error_scm_not_found), :status => 404
366 367 end
367 368
368 369 # Handler for Redmine::Scm::Adapters::CommandFailed exception
369 370 def show_error_command_failed(exception)
370 371 render_error l(:error_scm_command_failed, exception.message)
371 372 end
372 373
373 374 def graph_commits_per_month(repository)
374 375 @date_to = Date.today
375 376 @date_from = @date_to << 11
376 377 @date_from = Date.civil(@date_from.year, @date_from.month, 1)
377 378 commits_by_day = Changeset.count(
378 379 :all, :group => :commit_date,
379 380 :conditions => ["repository_id = ? AND commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to])
380 381 commits_by_month = [0] * 12
381 382 commits_by_day.each {|c| commits_by_month[(@date_to.month - c.first.to_date.month) % 12] += c.last }
382 383
383 384 changes_by_day = Change.count(
384 385 :all, :group => :commit_date, :include => :changeset,
385 386 :conditions => ["#{Changeset.table_name}.repository_id = ? AND #{Changeset.table_name}.commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to])
386 387 changes_by_month = [0] * 12
387 388 changes_by_day.each {|c| changes_by_month[(@date_to.month - c.first.to_date.month) % 12] += c.last }
388 389
389 390 fields = []
390 391 12.times {|m| fields << month_name(((Date.today.month - 1 - m) % 12) + 1)}
391 392
392 393 graph = SVG::Graph::Bar.new(
393 394 :height => 300,
394 395 :width => 800,
395 396 :fields => fields.reverse,
396 397 :stack => :side,
397 398 :scale_integers => true,
398 399 :step_x_labels => 2,
399 400 :show_data_values => false,
400 401 :graph_title => l(:label_commits_per_month),
401 402 :show_graph_title => true
402 403 )
403 404
404 405 graph.add_data(
405 406 :data => commits_by_month[0..11].reverse,
406 407 :title => l(:label_revision_plural)
407 408 )
408 409
409 410 graph.add_data(
410 411 :data => changes_by_month[0..11].reverse,
411 412 :title => l(:label_change_plural)
412 413 )
413 414
414 415 graph.burn
415 416 end
416 417
417 418 def graph_commits_per_author(repository)
418 419 commits_by_author = Changeset.count(:all, :group => :committer, :conditions => ["repository_id = ?", repository.id])
419 420 commits_by_author.to_a.sort! {|x, y| x.last <=> y.last}
420 421
421 422 changes_by_author = Change.count(:all, :group => :committer, :include => :changeset, :conditions => ["#{Changeset.table_name}.repository_id = ?", repository.id])
422 423 h = changes_by_author.inject({}) {|o, i| o[i.first] = i.last; o}
423 424
424 425 fields = commits_by_author.collect {|r| r.first}
425 426 commits_data = commits_by_author.collect {|r| r.last}
426 427 changes_data = commits_by_author.collect {|r| h[r.first] || 0}
427 428
428 429 fields = fields + [""]*(10 - fields.length) if fields.length<10
429 430 commits_data = commits_data + [0]*(10 - commits_data.length) if commits_data.length<10
430 431 changes_data = changes_data + [0]*(10 - changes_data.length) if changes_data.length<10
431 432
432 433 # Remove email adress in usernames
433 434 fields = fields.collect {|c| c.gsub(%r{<.+@.+>}, '') }
434 435
435 436 graph = SVG::Graph::BarHorizontal.new(
436 437 :height => 400,
437 438 :width => 800,
438 439 :fields => fields,
439 440 :stack => :side,
440 441 :scale_integers => true,
441 442 :show_data_values => false,
442 443 :rotate_y_labels => false,
443 444 :graph_title => l(:label_commits_per_author),
444 445 :show_graph_title => true
445 446 )
446 447 graph.add_data(
447 448 :data => commits_data,
448 449 :title => l(:label_revision_plural)
449 450 )
450 451 graph.add_data(
451 452 :data => changes_data,
452 453 :title => l(:label_change_plural)
453 454 )
454 455 graph.burn
455 456 end
456 457 end
457 458
@@ -1,411 +1,418
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2012 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 70 assert_tag :tag => 'a',
71 71 :attributes => {:href => '/projects/subproject1/repository'},
72 72 :content => 'root'
73 73 end
74 74
75 75 def test_show_non_default
76 76 Repository::Subversion.create(:project => @project,
77 77 :url => self.class.subversion_repository_url,
78 78 :is_default => false, :identifier => 'svn')
79 79
80 80 get :show, :id => PRJ_ID, :repository_id => 'svn'
81 81 assert_response :success
82 82 assert_template 'show'
83 83 assert_select 'tr.dir a[href=/projects/subproject1/repository/svn/show/subversion_test]'
84 84 # Repository menu should link to the main repo
85 85 assert_select '#main-menu a[href=/projects/subproject1/repository]'
86 86 end
87 87
88 88 def test_browse_directory
89 89 assert_equal 0, @repository.changesets.count
90 90 @repository.fetch_changesets
91 91 @project.reload
92 92 assert_equal NUM_REV, @repository.changesets.count
93 93 get :show, :id => PRJ_ID, :path => repository_path_hash(['subversion_test'])[:param]
94 94 assert_response :success
95 95 assert_template 'show'
96 96 assert_not_nil assigns(:entries)
97 97 assert_equal [
98 98 '[folder_with_brackets]', 'folder', '.project',
99 99 'helloworld.c', 'textfile.txt'
100 100 ],
101 101 assigns(:entries).collect(&:name)
102 102 entry = assigns(:entries).detect {|e| e.name == 'helloworld.c'}
103 103 assert_equal 'file', entry.kind
104 104 assert_equal 'subversion_test/helloworld.c', entry.path
105 105 assert_tag :a, :content => 'helloworld.c', :attributes => { :class => /text\-x\-c/ }
106 106 end
107 107
108 108 def test_browse_at_given_revision
109 109 assert_equal 0, @repository.changesets.count
110 110 @repository.fetch_changesets
111 111 @project.reload
112 112 assert_equal NUM_REV, @repository.changesets.count
113 113 get :show, :id => PRJ_ID, :path => repository_path_hash(['subversion_test'])[:param],
114 114 :rev => 4
115 115 assert_response :success
116 116 assert_template 'show'
117 117 assert_not_nil assigns(:entries)
118 118 assert_equal ['folder', '.project', 'helloworld.c', 'helloworld.rb', 'textfile.txt'],
119 119 assigns(:entries).collect(&:name)
120 120 end
121 121
122 122 def test_file_changes
123 123 assert_equal 0, @repository.changesets.count
124 124 @repository.fetch_changesets
125 125 @project.reload
126 126 assert_equal NUM_REV, @repository.changesets.count
127 127 get :changes, :id => PRJ_ID,
128 128 :path => repository_path_hash(['subversion_test', 'folder', 'helloworld.rb'])[:param]
129 129 assert_response :success
130 130 assert_template 'changes'
131 131
132 132 changesets = assigns(:changesets)
133 133 assert_not_nil changesets
134 134 assert_equal %w(6 3 2), changesets.collect(&:revision)
135 135
136 136 # svn properties displayed with svn >= 1.5 only
137 137 if Redmine::Scm::Adapters::SubversionAdapter.client_version_above?([1, 5, 0])
138 138 assert_not_nil assigns(:properties)
139 139 assert_equal 'native', assigns(:properties)['svn:eol-style']
140 140 assert_tag :ul,
141 141 :child => { :tag => 'li',
142 142 :child => { :tag => 'b', :content => 'svn:eol-style' },
143 143 :child => { :tag => 'span', :content => 'native' } }
144 144 end
145 145 end
146 146
147 147 def test_directory_changes
148 148 assert_equal 0, @repository.changesets.count
149 149 @repository.fetch_changesets
150 150 @project.reload
151 151 assert_equal NUM_REV, @repository.changesets.count
152 152 get :changes, :id => PRJ_ID,
153 153 :path => repository_path_hash(['subversion_test', 'folder'])[:param]
154 154 assert_response :success
155 155 assert_template 'changes'
156 156
157 157 changesets = assigns(:changesets)
158 158 assert_not_nil changesets
159 159 assert_equal %w(10 9 7 6 5 2), changesets.collect(&:revision)
160 160 end
161 161
162 162 def test_entry
163 163 assert_equal 0, @repository.changesets.count
164 164 @repository.fetch_changesets
165 165 @project.reload
166 166 assert_equal NUM_REV, @repository.changesets.count
167 167 get :entry, :id => PRJ_ID,
168 168 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
169 169 assert_response :success
170 170 assert_template 'entry'
171 171 end
172 172
173 173 def test_entry_should_send_if_too_big
174 174 assert_equal 0, @repository.changesets.count
175 175 @repository.fetch_changesets
176 176 @project.reload
177 177 assert_equal NUM_REV, @repository.changesets.count
178 178 # no files in the test repo is larger than 1KB...
179 179 with_settings :file_max_size_displayed => 0 do
180 180 get :entry, :id => PRJ_ID,
181 181 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
182 182 assert_response :success
183 183 assert_equal 'attachment; filename="helloworld.c"',
184 184 @response.headers['Content-Disposition']
185 185 end
186 186 end
187 187
188 def test_entry_should_send_images_inline
189 get :entry, :id => PRJ_ID,
190 :path => repository_path_hash(['subversion_test', 'folder', 'subfolder', 'rubylogo.gif'])[:param]
191 assert_response :success
192 assert_equal 'inline; filename="rubylogo.gif"', response.headers['Content-Disposition']
193 end
194
188 195 def test_entry_at_given_revision
189 196 assert_equal 0, @repository.changesets.count
190 197 @repository.fetch_changesets
191 198 @project.reload
192 199 assert_equal NUM_REV, @repository.changesets.count
193 200 get :entry, :id => PRJ_ID,
194 201 :path => repository_path_hash(['subversion_test', 'helloworld.rb'])[:param],
195 202 :rev => 2
196 203 assert_response :success
197 204 assert_template 'entry'
198 205 # this line was removed in r3 and file was moved in r6
199 206 assert_tag :tag => 'td', :attributes => { :class => /line-code/},
200 207 :content => /Here's the code/
201 208 end
202 209
203 210 def test_entry_not_found
204 211 assert_equal 0, @repository.changesets.count
205 212 @repository.fetch_changesets
206 213 @project.reload
207 214 assert_equal NUM_REV, @repository.changesets.count
208 215 get :entry, :id => PRJ_ID,
209 216 :path => repository_path_hash(['subversion_test', 'zzz.c'])[:param]
210 217 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
211 218 :content => /The entry or revision was not found in the repository/
212 219 end
213 220
214 221 def test_entry_download
215 222 assert_equal 0, @repository.changesets.count
216 223 @repository.fetch_changesets
217 224 @project.reload
218 225 assert_equal NUM_REV, @repository.changesets.count
219 226 get :raw, :id => PRJ_ID,
220 227 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
221 228 assert_response :success
222 229 assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition']
223 230 end
224 231
225 232 def test_directory_entry
226 233 assert_equal 0, @repository.changesets.count
227 234 @repository.fetch_changesets
228 235 @project.reload
229 236 assert_equal NUM_REV, @repository.changesets.count
230 237 get :entry, :id => PRJ_ID,
231 238 :path => repository_path_hash(['subversion_test', 'folder'])[:param]
232 239 assert_response :success
233 240 assert_template 'show'
234 241 assert_not_nil assigns(:entry)
235 242 assert_equal 'folder', assigns(:entry).name
236 243 end
237 244
238 245 # TODO: this test needs fixtures.
239 246 def test_revision
240 247 get :revision, :id => 1, :rev => 2
241 248 assert_response :success
242 249 assert_template 'revision'
243 250 assert_tag :tag => 'ul',
244 251 :child => { :tag => 'li',
245 252 # link to the entry at rev 2
246 253 :child => { :tag => 'a',
247 254 :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/test/some/path/in/the/repo'},
248 255 :content => 'repo',
249 256 # link to partial diff
250 257 :sibling => { :tag => 'a',
251 258 :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/test/some/path/in/the/repo' }
252 259 }
253 260 }
254 261 }
255 262 end
256 263
257 264 def test_invalid_revision
258 265 assert_equal 0, @repository.changesets.count
259 266 @repository.fetch_changesets
260 267 @project.reload
261 268 assert_equal NUM_REV, @repository.changesets.count
262 269 get :revision, :id => PRJ_ID, :rev => 'something_weird'
263 270 assert_response 404
264 271 assert_error_tag :content => /was not found/
265 272 end
266 273
267 274 def test_invalid_revision_diff
268 275 get :diff, :id => PRJ_ID, :rev => '1', :rev_to => 'something_weird'
269 276 assert_response 404
270 277 assert_error_tag :content => /was not found/
271 278 end
272 279
273 280 def test_empty_revision
274 281 assert_equal 0, @repository.changesets.count
275 282 @repository.fetch_changesets
276 283 @project.reload
277 284 assert_equal NUM_REV, @repository.changesets.count
278 285 ['', ' ', nil].each do |r|
279 286 get :revision, :id => PRJ_ID, :rev => r
280 287 assert_response 404
281 288 assert_error_tag :content => /was not found/
282 289 end
283 290 end
284 291
285 292 # TODO: this test needs fixtures.
286 293 def test_revision_with_repository_pointing_to_a_subdirectory
287 294 r = Project.find(1).repository
288 295 # Changes repository url to a subdirectory
289 296 r.update_attribute :url, (r.url + '/test/some')
290 297
291 298 get :revision, :id => 1, :rev => 2
292 299 assert_response :success
293 300 assert_template 'revision'
294 301 assert_tag :tag => 'ul',
295 302 :child => { :tag => 'li',
296 303 # link to the entry at rev 2
297 304 :child => { :tag => 'a',
298 305 :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/path/in/the/repo'},
299 306 :content => 'repo',
300 307 # link to partial diff
301 308 :sibling => { :tag => 'a',
302 309 :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/path/in/the/repo' }
303 310 }
304 311 }
305 312 }
306 313 end
307 314
308 315 def test_revision_diff
309 316 assert_equal 0, @repository.changesets.count
310 317 @repository.fetch_changesets
311 318 @project.reload
312 319 assert_equal NUM_REV, @repository.changesets.count
313 320 ['inline', 'sbs'].each do |dt|
314 321 get :diff, :id => PRJ_ID, :rev => 3, :type => dt
315 322 assert_response :success
316 323 assert_template 'diff'
317 324 assert_tag :tag => 'h2',
318 325 :content => / 3/
319 326 end
320 327 end
321 328
322 329 def test_revision_diff_raw_format
323 330 assert_equal 0, @repository.changesets.count
324 331 @repository.fetch_changesets
325 332 @project.reload
326 333 assert_equal NUM_REV, @repository.changesets.count
327 334
328 335 get :diff, :id => PRJ_ID, :rev => 3, :format => 'diff'
329 336 assert_response :success
330 337 assert_equal 'text/x-patch', @response.content_type
331 338 assert_equal 'Index: subversion_test/textfile.txt', @response.body.split(/\r?\n/).first
332 339 end
333 340
334 341 def test_directory_diff
335 342 assert_equal 0, @repository.changesets.count
336 343 @repository.fetch_changesets
337 344 @project.reload
338 345 assert_equal NUM_REV, @repository.changesets.count
339 346 ['inline', 'sbs'].each do |dt|
340 347 get :diff, :id => PRJ_ID, :rev => 6, :rev_to => 2,
341 348 :path => repository_path_hash(['subversion_test', 'folder'])[:param],
342 349 :type => dt
343 350 assert_response :success
344 351 assert_template 'diff'
345 352
346 353 diff = assigns(:diff)
347 354 assert_not_nil diff
348 355 # 2 files modified
349 356 assert_equal 2, Redmine::UnifiedDiff.new(diff).size
350 357 assert_tag :tag => 'h2', :content => /2:6/
351 358 end
352 359 end
353 360
354 361 def test_annotate
355 362 assert_equal 0, @repository.changesets.count
356 363 @repository.fetch_changesets
357 364 @project.reload
358 365 assert_equal NUM_REV, @repository.changesets.count
359 366 get :annotate, :id => PRJ_ID,
360 367 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
361 368 assert_response :success
362 369 assert_template 'annotate'
363 370 end
364 371
365 372 def test_annotate_at_given_revision
366 373 assert_equal 0, @repository.changesets.count
367 374 @repository.fetch_changesets
368 375 @project.reload
369 376 assert_equal NUM_REV, @repository.changesets.count
370 377 get :annotate, :id => PRJ_ID, :rev => 8,
371 378 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
372 379 assert_response :success
373 380 assert_template 'annotate'
374 381 assert_tag :tag => 'h2', :content => /@ 8/
375 382 end
376 383
377 384 def test_destroy_valid_repository
378 385 @request.session[:user_id] = 1 # admin
379 386 assert_equal 0, @repository.changesets.count
380 387 @repository.fetch_changesets
381 388 assert_equal NUM_REV, @repository.changesets.count
382 389
383 390 assert_difference 'Repository.count', -1 do
384 391 delete :destroy, :id => @repository.id
385 392 end
386 393 assert_response 302
387 394 @project.reload
388 395 assert_nil @project.repository
389 396 end
390 397
391 398 def test_destroy_invalid_repository
392 399 @request.session[:user_id] = 1 # admin
393 400 @project.repository.destroy
394 401 @repository = Repository::Subversion.create!(
395 402 :project => @project,
396 403 :url => "file:///invalid")
397 404 @repository.fetch_changesets
398 405 assert_equal 0, @repository.changesets.count
399 406
400 407 assert_difference 'Repository.count', -1 do
401 408 delete :destroy, :id => @repository.id
402 409 end
403 410 assert_response 302
404 411 @project.reload
405 412 assert_nil @project.repository
406 413 end
407 414 else
408 415 puts "Subversion test repository NOT FOUND. Skipping functional tests !!!"
409 416 def test_fake; assert true end
410 417 end
411 418 end
General Comments 0
You need to be logged in to leave comments. Login now