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