##// END OF EJS Templates
Merged r6073 from trunk....
Jean-Philippe Lang -
r6042:30255b8054d5
parent child
Show More
@@ -1,374 +1,374
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require 'SVG/Graph/Bar'
19 19 require 'SVG/Graph/BarHorizontal'
20 20 require 'digest/sha1'
21 21
22 22 class ChangesetNotFound < Exception; end
23 23 class InvalidRevisionParam < Exception; end
24 24
25 25 class RepositoriesController < ApplicationController
26 26 menu_item :repository
27 27 menu_item :settings, :only => :edit
28 28 default_search_scope :changesets
29 29
30 30 before_filter :find_repository, :except => :edit
31 31 before_filter :find_project, :only => :edit
32 32 before_filter :authorize
33 33 accept_key_auth :revisions
34 34
35 35 rescue_from Redmine::Scm::Adapters::CommandFailed, :with => :show_error_command_failed
36 36
37 37 def edit
38 38 @repository = @project.repository
39 39 if !@repository && !params[:repository_scm].blank?
40 40 @repository = Repository.factory(params[:repository_scm])
41 41 @repository.project = @project if @repository
42 42 end
43 43 if request.post? && @repository
44 44 p1 = params[:repository]
45 45 p = {}
46 46 p_extra = {}
47 47 p1.each do |k, v|
48 48 if k =~ /^extra_/
49 49 p_extra[k] = v
50 50 else
51 51 p[k] = v
52 52 end
53 53 end
54 54 @repository.attributes = p
55 55 @repository.merge_extra_info(p_extra)
56 56 @repository.save
57 57 end
58 58 render(:update) do |page|
59 59 page.replace_html "tab-content-repository",
60 60 :partial => 'projects/settings/repository'
61 61 if @repository && !@project.repository
62 62 @project.reload # needed to reload association
63 63 page.replace_html "main-menu", render_main_menu(@project)
64 64 end
65 65 end
66 66 end
67 67
68 68 def committers
69 69 @committers = @repository.committers
70 70 @users = @project.users
71 71 additional_user_ids = @committers.collect(&:last).collect(&:to_i) - @users.collect(&:id)
72 72 @users += User.find_all_by_id(additional_user_ids) unless additional_user_ids.empty?
73 73 @users.compact!
74 74 @users.sort!
75 75 if request.post? && params[:committers].is_a?(Hash)
76 76 # Build a hash with repository usernames as keys and corresponding user ids as values
77 77 @repository.committer_ids = params[:committers].values.inject({}) {|h, c| h[c.first] = c.last; h}
78 78 flash[:notice] = l(:notice_successful_update)
79 79 redirect_to :action => 'committers', :id => @project
80 80 end
81 81 end
82 82
83 83 def destroy
84 84 @repository.destroy
85 85 redirect_to :controller => 'projects',
86 86 :action => 'settings',
87 87 :id => @project,
88 88 :tab => 'repository'
89 89 end
90 90
91 91 def show
92 92 @repository.fetch_changesets if Setting.autofetch_changesets? && @path.empty?
93 93
94 94 @entries = @repository.entries(@path, @rev)
95 95 @changeset = @repository.find_changeset_by_name(@rev)
96 96 if request.xhr?
97 97 @entries ? render(:partial => 'dir_list_content') : render(:nothing => true)
98 98 else
99 99 (show_error_not_found; return) unless @entries
100 100 @changesets = @repository.latest_changesets(@path, @rev)
101 101 @properties = @repository.properties(@path, @rev)
102 102 render :action => 'show'
103 103 end
104 104 end
105 105
106 106 alias_method :browse, :show
107 107
108 108 def changes
109 109 @entry = @repository.entry(@path, @rev)
110 110 (show_error_not_found; return) unless @entry
111 111 @changesets = @repository.latest_changesets(@path, @rev, Setting.repository_log_display_limit.to_i)
112 112 @properties = @repository.properties(@path, @rev)
113 113 @changeset = @repository.find_changeset_by_name(@rev)
114 114 end
115 115
116 116 def revisions
117 117 @changeset_count = @repository.changesets.count
118 118 @changeset_pages = Paginator.new self, @changeset_count,
119 119 per_page_option,
120 120 params['page']
121 121 @changesets = @repository.changesets.find(:all,
122 122 :limit => @changeset_pages.items_per_page,
123 123 :offset => @changeset_pages.current.offset,
124 124 :include => [:user, :repository])
125 125
126 126 respond_to do |format|
127 127 format.html { render :layout => false if request.xhr? }
128 128 format.atom { render_feed(@changesets, :title => "#{@project.name}: #{l(:label_revision_plural)}") }
129 129 end
130 130 end
131 131
132 132 def entry
133 133 @entry = @repository.entry(@path, @rev)
134 134 (show_error_not_found; return) unless @entry
135 135
136 136 # If the entry is a dir, show the browser
137 137 (show; return) if @entry.is_dir?
138 138
139 139 @content = @repository.cat(@path, @rev)
140 140 (show_error_not_found; return) unless @content
141 141 if 'raw' == params[:format] ||
142 142 (@content.size && @content.size > Setting.file_max_size_displayed.to_i.kilobyte) ||
143 143 ! is_entry_text_data?(@content, @path)
144 144 # Force the download
145 145 send_opt = { :filename => filename_for_content_disposition(@path.split('/').last) }
146 146 send_type = Redmine::MimeType.of(@path)
147 147 send_opt[:type] = send_type.to_s if send_type
148 148 send_data @content, send_opt
149 149 else
150 150 # Prevent empty lines when displaying a file with Windows style eol
151 151 # TODO: UTF-16
152 152 # Is this needs? AttachmentsController reads file simply.
153 153 @content.gsub!("\r\n", "\n")
154 154 @changeset = @repository.find_changeset_by_name(@rev)
155 155 end
156 156 end
157 157
158 158 def is_entry_text_data?(ent, path)
159 159 # UTF-16 contains "\x00".
160 160 # It is very strict that file contains less than 30% of ascii symbols
161 161 # in non Western Europe.
162 162 return true if Redmine::MimeType.is_type?('text', path)
163 163 # Ruby 1.8.6 has a bug of integer divisions.
164 164 # http://apidock.com/ruby/v1_8_6_287/String/is_binary_data%3F
165 165 return false if ent.is_binary_data?
166 166 true
167 167 end
168 168 private :is_entry_text_data?
169 169
170 170 def annotate
171 171 @entry = @repository.entry(@path, @rev)
172 172 (show_error_not_found; return) unless @entry
173 173
174 174 @annotate = @repository.scm.annotate(@path, @rev)
175 175 (render_error l(:error_scm_annotate); return) if @annotate.nil? || @annotate.empty?
176 176 @changeset = @repository.find_changeset_by_name(@rev)
177 177 end
178 178
179 179 def revision
180 180 raise ChangesetNotFound if @rev.blank?
181 181 @changeset = @repository.find_changeset_by_name(@rev)
182 182 raise ChangesetNotFound unless @changeset
183 183
184 184 respond_to do |format|
185 185 format.html
186 186 format.js {render :layout => false}
187 187 end
188 188 rescue ChangesetNotFound
189 189 show_error_not_found
190 190 end
191 191
192 192 def diff
193 193 if params[:format] == 'diff'
194 194 @diff = @repository.diff(@path, @rev, @rev_to)
195 195 (show_error_not_found; return) unless @diff
196 196 filename = "changeset_r#{@rev}"
197 197 filename << "_r#{@rev_to}" if @rev_to
198 198 send_data @diff.join, :filename => "#{filename}.diff",
199 199 :type => 'text/x-patch',
200 200 :disposition => 'attachment'
201 201 else
202 202 @diff_type = params[:type] || User.current.pref[:diff_type] || 'inline'
203 203 @diff_type = 'inline' unless %w(inline sbs).include?(@diff_type)
204 204
205 205 # Save diff type as user preference
206 206 if User.current.logged? && @diff_type != User.current.pref[:diff_type]
207 207 User.current.pref[:diff_type] = @diff_type
208 208 User.current.preference.save
209 209 end
210 210 @cache_key = "repositories/diff/#{@repository.id}/" +
211 Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}")
211 Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}-#{current_language}")
212 212 unless read_fragment(@cache_key)
213 213 @diff = @repository.diff(@path, @rev, @rev_to)
214 214 show_error_not_found unless @diff
215 215 end
216 216
217 217 @changeset = @repository.find_changeset_by_name(@rev)
218 218 @changeset_to = @rev_to ? @repository.find_changeset_by_name(@rev_to) : nil
219 219 @diff_format_revisions = @repository.diff_format_revisions(@changeset, @changeset_to)
220 220 end
221 221 end
222 222
223 223 def stats
224 224 end
225 225
226 226 def graph
227 227 data = nil
228 228 case params[:graph]
229 229 when "commits_per_month"
230 230 data = graph_commits_per_month(@repository)
231 231 when "commits_per_author"
232 232 data = graph_commits_per_author(@repository)
233 233 end
234 234 if data
235 235 headers["Content-Type"] = "image/svg+xml"
236 236 send_data(data, :type => "image/svg+xml", :disposition => "inline")
237 237 else
238 238 render_404
239 239 end
240 240 end
241 241
242 242 private
243 243
244 244 REV_PARAM_RE = %r{\A[a-f0-9]*\Z}i
245 245
246 246 def find_repository
247 247 @project = Project.find(params[:id])
248 248 @repository = @project.repository
249 249 (render_404; return false) unless @repository
250 250 @path = params[:path].join('/') unless params[:path].nil?
251 251 @path ||= ''
252 252 @rev = params[:rev].blank? ? @repository.default_branch : params[:rev].strip
253 253 @rev_to = params[:rev_to]
254 254
255 255 unless @rev.to_s.match(REV_PARAM_RE) && @rev_to.to_s.match(REV_PARAM_RE)
256 256 if @repository.branches.blank?
257 257 raise InvalidRevisionParam
258 258 end
259 259 end
260 260 rescue ActiveRecord::RecordNotFound
261 261 render_404
262 262 rescue InvalidRevisionParam
263 263 show_error_not_found
264 264 end
265 265
266 266 def show_error_not_found
267 267 render_error :message => l(:error_scm_not_found), :status => 404
268 268 end
269 269
270 270 # Handler for Redmine::Scm::Adapters::CommandFailed exception
271 271 def show_error_command_failed(exception)
272 272 render_error l(:error_scm_command_failed, exception.message)
273 273 end
274 274
275 275 def graph_commits_per_month(repository)
276 276 @date_to = Date.today
277 277 @date_from = @date_to << 11
278 278 @date_from = Date.civil(@date_from.year, @date_from.month, 1)
279 279 commits_by_day = repository.changesets.count(
280 280 :all, :group => :commit_date,
281 281 :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to])
282 282 commits_by_month = [0] * 12
283 283 commits_by_day.each {|c| commits_by_month[c.first.to_date.months_ago] += c.last }
284 284
285 285 changes_by_day = repository.changes.count(
286 286 :all, :group => :commit_date,
287 287 :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to])
288 288 changes_by_month = [0] * 12
289 289 changes_by_day.each {|c| changes_by_month[c.first.to_date.months_ago] += c.last }
290 290
291 291 fields = []
292 292 12.times {|m| fields << month_name(((Date.today.month - 1 - m) % 12) + 1)}
293 293
294 294 graph = SVG::Graph::Bar.new(
295 295 :height => 300,
296 296 :width => 800,
297 297 :fields => fields.reverse,
298 298 :stack => :side,
299 299 :scale_integers => true,
300 300 :step_x_labels => 2,
301 301 :show_data_values => false,
302 302 :graph_title => l(:label_commits_per_month),
303 303 :show_graph_title => true
304 304 )
305 305
306 306 graph.add_data(
307 307 :data => commits_by_month[0..11].reverse,
308 308 :title => l(:label_revision_plural)
309 309 )
310 310
311 311 graph.add_data(
312 312 :data => changes_by_month[0..11].reverse,
313 313 :title => l(:label_change_plural)
314 314 )
315 315
316 316 graph.burn
317 317 end
318 318
319 319 def graph_commits_per_author(repository)
320 320 commits_by_author = repository.changesets.count(:all, :group => :committer)
321 321 commits_by_author.to_a.sort! {|x, y| x.last <=> y.last}
322 322
323 323 changes_by_author = repository.changes.count(:all, :group => :committer)
324 324 h = changes_by_author.inject({}) {|o, i| o[i.first] = i.last; o}
325 325
326 326 fields = commits_by_author.collect {|r| r.first}
327 327 commits_data = commits_by_author.collect {|r| r.last}
328 328 changes_data = commits_by_author.collect {|r| h[r.first] || 0}
329 329
330 330 fields = fields + [""]*(10 - fields.length) if fields.length<10
331 331 commits_data = commits_data + [0]*(10 - commits_data.length) if commits_data.length<10
332 332 changes_data = changes_data + [0]*(10 - changes_data.length) if changes_data.length<10
333 333
334 334 # Remove email adress in usernames
335 335 fields = fields.collect {|c| c.gsub(%r{<.+@.+>}, '') }
336 336
337 337 graph = SVG::Graph::BarHorizontal.new(
338 338 :height => 400,
339 339 :width => 800,
340 340 :fields => fields,
341 341 :stack => :side,
342 342 :scale_integers => true,
343 343 :show_data_values => false,
344 344 :rotate_y_labels => false,
345 345 :graph_title => l(:label_commits_per_author),
346 346 :show_graph_title => true
347 347 )
348 348 graph.add_data(
349 349 :data => commits_data,
350 350 :title => l(:label_revision_plural)
351 351 )
352 352 graph.add_data(
353 353 :data => changes_data,
354 354 :title => l(:label_change_plural)
355 355 )
356 356 graph.burn
357 357 end
358 358 end
359 359
360 360 class Date
361 361 def months_ago(date = Date.today)
362 362 (date.year - self.year)*12 + (date.month - self.month)
363 363 end
364 364
365 365 def weeks_ago(date = Date.today)
366 366 (date.year - self.year)*52 + (date.cweek - self.cweek)
367 367 end
368 368 end
369 369
370 370 class String
371 371 def with_leading_slash
372 372 starts_with?('/') ? self : "/#{self}"
373 373 end
374 374 end
@@ -1,339 +1,370
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19 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 RepositoriesGitControllerTest < ActionController::TestCase
25 25 fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :enabled_modules
26 26
27 27 # No '..' in the repository path
28 28 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository'
29 29 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
30 30 PRJ_ID = 3
31 31 CHAR_1_HEX = "\xc3\x9c"
32 32
33 33 def setup
34 34 @ruby19_non_utf8_pass =
35 35 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
36 36
37 37 @controller = RepositoriesController.new
38 38 @request = ActionController::TestRequest.new
39 39 @response = ActionController::TestResponse.new
40 40 User.current = nil
41 41 @repository = Repository::Git.create(
42 42 :project => Project.find(3),
43 43 :url => REPOSITORY_PATH,
44 44 :path_encoding => 'ISO-8859-1'
45 45 )
46 46 assert @repository
47 47 @char_1 = CHAR_1_HEX.dup
48 48 if @char_1.respond_to?(:force_encoding)
49 49 @char_1.force_encoding('UTF-8')
50 50 end
51
52 Setting.default_language = 'en'
51 53 end
52 54
53 55 if File.directory?(REPOSITORY_PATH)
54 56 def test_browse_root
55 57 @repository.fetch_changesets
56 58 @repository.reload
57 59 get :show, :id => PRJ_ID
58 60 assert_response :success
59 61 assert_template 'show'
60 62 assert_not_nil assigns(:entries)
61 63 assert_equal 9, assigns(:entries).size
62 64 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
63 65 assert assigns(:entries).detect {|e| e.name == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir'}
64 66 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
65 67 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
66 68 assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'}
67 69 assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'}
68 70 assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'}
69 71 assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'}
70 72 assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'}
71 73 assert_not_nil assigns(:changesets)
72 74 assigns(:changesets).size > 0
73 75 end
74 76
75 77 def test_browse_branch
76 78 @repository.fetch_changesets
77 79 @repository.reload
78 80 get :show, :id => PRJ_ID, :rev => 'test_branch'
79 81 assert_response :success
80 82 assert_template 'show'
81 83 assert_not_nil assigns(:entries)
82 84 assert_equal 4, assigns(:entries).size
83 85 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
84 86 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
85 87 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
86 88 assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'}
87 89 assert_not_nil assigns(:changesets)
88 90 assigns(:changesets).size > 0
89 91 end
90 92
91 93 def test_browse_tag
92 94 @repository.fetch_changesets
93 95 @repository.reload
94 96 [
95 97 "tag00.lightweight",
96 98 "tag01.annotated",
97 99 ].each do |t1|
98 100 get :show, :id => PRJ_ID, :rev => t1
99 101 assert_response :success
100 102 assert_template 'show'
101 103 assert_not_nil assigns(:entries)
102 104 assigns(:entries).size > 0
103 105 assert_not_nil assigns(:changesets)
104 106 assigns(:changesets).size > 0
105 107 end
106 108 end
107 109
108 110 def test_browse_directory
109 111 @repository.fetch_changesets
110 112 @repository.reload
111 113 get :show, :id => PRJ_ID, :path => ['images']
112 114 assert_response :success
113 115 assert_template 'show'
114 116 assert_not_nil assigns(:entries)
115 117 assert_equal ['edit.png'], assigns(:entries).collect(&:name)
116 118 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
117 119 assert_not_nil entry
118 120 assert_equal 'file', entry.kind
119 121 assert_equal 'images/edit.png', entry.path
120 122 assert_not_nil assigns(:changesets)
121 123 assigns(:changesets).size > 0
122 124 end
123 125
124 126 def test_browse_at_given_revision
125 127 @repository.fetch_changesets
126 128 @repository.reload
127 129 get :show, :id => PRJ_ID, :path => ['images'],
128 130 :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
129 131 assert_response :success
130 132 assert_template 'show'
131 133 assert_not_nil assigns(:entries)
132 134 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
133 135 assert_not_nil assigns(:changesets)
134 136 assigns(:changesets).size > 0
135 137 end
136 138
137 139 def test_changes
138 140 get :changes, :id => PRJ_ID, :path => ['images', 'edit.png']
139 141 assert_response :success
140 142 assert_template 'changes'
141 143 assert_tag :tag => 'h2', :content => 'edit.png'
142 144 end
143 145
144 146 def test_entry_show
145 147 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
146 148 assert_response :success
147 149 assert_template 'entry'
148 150 # Line 19
149 151 assert_tag :tag => 'th',
150 152 :content => '11',
151 153 :attributes => { :class => 'line-num' },
152 154 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
153 155 end
154 156
155 157 def test_entry_show_latin_1
156 158 if @ruby19_non_utf8_pass
157 159 puts_ruby19_non_utf8_pass()
158 160 else
159 161 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
160 162 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
161 163 get :entry, :id => PRJ_ID,
162 164 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
163 165 assert_response :success
164 166 assert_template 'entry'
165 167 assert_tag :tag => 'th',
166 168 :content => '1',
167 169 :attributes => { :class => 'line-num' },
168 170 :sibling => { :tag => 'td',
169 171 :content => /test-#{@char_1}.txt/ }
170 172 end
171 173 end
172 174 end
173 175 end
174 176
175 177 def test_entry_download
176 178 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'],
177 179 :format => 'raw'
178 180 assert_response :success
179 181 # File content
180 182 assert @response.body.include?('WITHOUT ANY WARRANTY')
181 183 end
182 184
183 185 def test_directory_entry
184 186 get :entry, :id => PRJ_ID, :path => ['sources']
185 187 assert_response :success
186 188 assert_template 'show'
187 189 assert_not_nil assigns(:entry)
188 190 assert_equal 'sources', assigns(:entry).name
189 191 end
190 192
191 193 def test_diff
192 194 @repository.fetch_changesets
193 195 @repository.reload
194 196 # Full diff of changeset 2f9c0091
195 197 get :diff, :id => PRJ_ID, :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
196 198 assert_response :success
197 199 assert_template 'diff'
198 200 # Line 22 removed
199 201 assert_tag :tag => 'th',
200 202 :content => /22/,
201 203 :sibling => { :tag => 'td',
202 204 :attributes => { :class => /diff_out/ },
203 205 :content => /def remove/ }
204 206 assert_tag :tag => 'h2', :content => /2f9c0091/
205 207 end
206 208
209 def test_diff_truncated
210 @repository.fetch_changesets
211 @repository.reload
212 Setting.diff_max_lines_displayed = 5
213
214 # Truncated diff of changeset 2f9c0091
215 with_cache do
216 get :diff, :id => PRJ_ID, :type => 'inline',
217 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
218 assert_response :success
219 assert @response.body.include?("... This diff was truncated")
220
221 Setting.default_language = 'fr'
222 get :diff, :id => PRJ_ID, :type => 'inline',
223 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
224 assert_response :success
225 assert ! @response.body.include?("... This diff was truncated")
226 assert @response.body.include?("... Ce diff")
227 end
228 end
229
207 230 def test_diff_two_revs
208 231 @repository.fetch_changesets
209 232 @repository.reload
210 233 get :diff, :id => PRJ_ID,
211 234 :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
212 235 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
213 236 assert_response :success
214 237 assert_template 'diff'
215 238 diff = assigns(:diff)
216 239 assert_not_nil diff
217 240 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
218 241 end
219 242
220 243 def test_diff_latin_1
221 244 if @ruby19_non_utf8_pass
222 245 puts_ruby19_non_utf8_pass()
223 246 else
224 247 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
225 248 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
226 249 get :diff, :id => PRJ_ID, :rev => r1
227 250 assert_response :success
228 251 assert_template 'diff'
229 252 assert_tag :tag => 'thead',
230 253 :descendant => {
231 254 :tag => 'th',
232 255 :attributes => { :class => 'filename' } ,
233 256 :content => /latin-1-dir\/test-#{@char_1}.txt/ ,
234 257 },
235 258 :sibling => {
236 259 :tag => 'tbody',
237 260 :descendant => {
238 261 :tag => 'td',
239 262 :attributes => { :class => /diff_in/ },
240 263 :content => /test-#{@char_1}.txt/
241 264 }
242 265 }
243 266 end
244 267 end
245 268 end
246 269 end
247 270
248 271 def test_annotate
249 272 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
250 273 assert_response :success
251 274 assert_template 'annotate'
252 275 # Line 23, changeset 2f9c0091
253 276 assert_tag :tag => 'th', :content => '24',
254 277 :sibling => {
255 278 :tag => 'td',
256 279 :child => {
257 280 :tag => 'a',
258 281 :content => /2f9c0091c754a91af7a9c478e36556b4bde8dcf7/
259 282 }
260 283 },
261 284 :sibling => { :tag => 'td', :content => /jsmith/ }
262 285 assert_tag :tag => 'th', :content => '24',
263 286 :sibling => {
264 287 :tag => 'td',
265 288 :child => {
266 289 :tag => 'a',
267 290 :content => /2f9c0091c754a91af7a9c478e36556b4bde8dcf7/
268 291 }
269 292 },
270 293 :sibling => { :tag => 'td', :content => /watcher =/ }
271 294 end
272 295
273 296 def test_annotate_at_given_revision
274 297 @repository.fetch_changesets
275 298 @repository.reload
276 299 get :annotate, :id => PRJ_ID, :rev => 'deff7',
277 300 :path => ['sources', 'watchers_controller.rb']
278 301 assert_response :success
279 302 assert_template 'annotate'
280 303 assert_tag :tag => 'h2', :content => /@ deff712f/
281 304 end
282 305
283 306 def test_annotate_binary_file
284 307 get :annotate, :id => PRJ_ID, :path => ['images', 'edit.png']
285 308 assert_response 500
286 309 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
287 310 :content => /cannot be annotated/
288 311 end
289 312
290 313 def test_annotate_latin_1
291 314 if @ruby19_non_utf8_pass
292 315 puts_ruby19_non_utf8_pass()
293 316 else
294 317 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
295 318 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
296 319 get :annotate, :id => PRJ_ID,
297 320 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
298 321 assert_tag :tag => 'th',
299 322 :content => '1',
300 323 :attributes => { :class => 'line-num' },
301 324 :sibling => { :tag => 'td',
302 325 :content => /test-#{@char_1}.txt/ }
303 326 end
304 327 end
305 328 end
306 329 end
307 330
308 331 def test_revision
309 332 @repository.fetch_changesets
310 333 @repository.reload
311 334 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
312 335 get :revision, :id => PRJ_ID, :rev => r
313 336 assert_response :success
314 337 assert_template 'revision'
315 338 end
316 339 end
317 340
318 341 def test_empty_revision
319 342 @repository.fetch_changesets
320 343 @repository.reload
321 344 ['', ' ', nil].each do |r|
322 345 get :revision, :id => PRJ_ID, :rev => r
323 346 assert_response 404
324 347 assert_error_tag :content => /was not found/
325 348 end
326 349 end
327 350
328 351 private
329 352
330 353 def puts_ruby19_non_utf8_pass
331 354 puts "TODO: This test fails in Ruby 1.9 " +
332 355 "and Encoding.default_external is not UTF-8. " +
333 356 "Current value is '#{Encoding.default_external.to_s}'"
334 357 end
335 358 else
336 359 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
337 360 def test_fake; assert true end
338 361 end
362
363 private
364 def with_cache(&block)
365 before = ActionController::Base.perform_caching
366 ActionController::Base.perform_caching = true
367 block.call
368 ActionController::Base.perform_caching = before
369 end
339 370 end
General Comments 0
You need to be logged in to leave comments. Login now