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