##// END OF EJS Templates
Don't repeat revision on annotate view....
Jean-Philippe Lang -
r9922:65524cc1cc63
parent child
Show More
@@ -1,36 +1,36
1 <%= call_hook(:view_repositories_show_contextual, { :repository => @repository, :project => @project }) %>
1 <%= call_hook(:view_repositories_show_contextual, { :repository => @repository, :project => @project }) %>
2
2
3 <div class="contextual">
3 <div class="contextual">
4 <%= render :partial => 'navigation' %>
4 <%= render :partial => 'navigation' %>
5 </div>
5 </div>
6
6
7 <h2><%= render :partial => 'breadcrumbs', :locals => { :path => @path, :kind => 'file', :revision => @rev } %></h2>
7 <h2><%= render :partial => 'breadcrumbs', :locals => { :path => @path, :kind => 'file', :revision => @rev } %></h2>
8
8
9 <%= render :partial => 'link_to_functions' %>
9 <%= render :partial => 'link_to_functions' %>
10
10
11 <% colors = Hash.new {|k,v| k[v] = (k.size % 12) } %>
11 <% colors = Hash.new {|k,v| k[v] = (k.size % 12) } %>
12
12
13 <div class="autoscroll">
13 <div class="autoscroll">
14 <table class="filecontent annotate syntaxhl">
14 <table class="filecontent annotate syntaxhl">
15 <tbody>
15 <tbody>
16 <% line_num = 1 %>
16 <% line_num = 1; previous_revision = nil %>
17 <% syntax_highlight_lines(@path, Redmine::CodesetUtil.to_utf8_by_setting(@annotate.content)).each do |line| %>
17 <% syntax_highlight_lines(@path, Redmine::CodesetUtil.to_utf8_by_setting(@annotate.content)).each do |line| %>
18 <% revision = @annotate.revisions[line_num - 1] %>
18 <% revision = @annotate.revisions[line_num - 1] %>
19 <tr class="bloc-<%= revision.nil? ? 0 : colors[revision.identifier || revision.revision] %>">
19 <tr class="bloc-<%= revision.nil? ? 0 : colors[revision.identifier || revision.revision] %>">
20 <th class="line-num" id="L<%= line_num %>"><a href="#L<%= line_num %>"><%= line_num %></a></th>
20 <th class="line-num" id="L<%= line_num %>"><a href="#L<%= line_num %>"><%= line_num %></a></th>
21 <td class="revision">
21 <td class="revision">
22 <%= (revision.identifier ? link_to_revision(revision, @repository) : format_revision(revision)) if revision %></td>
22 <%= (revision.identifier ? link_to_revision(revision, @repository) : format_revision(revision)) if revision && revision != previous_revision %></td>
23 <td class="author"><%= h(revision.author.to_s.split('<').first) if revision %></td>
23 <td class="author"><%= h(revision.author.to_s.split('<').first) if revision && revision != previous_revision %></td>
24 <td class="line-code"><pre><%= line.html_safe %></pre></td>
24 <td class="line-code"><pre><%= line.html_safe %></pre></td>
25 </tr>
25 </tr>
26 <% line_num += 1 %>
26 <% line_num += 1; previous_revision = revision %>
27 <% end %>
27 <% end %>
28 </tbody>
28 </tbody>
29 </table>
29 </table>
30 </div>
30 </div>
31
31
32 <% html_title(l(:button_annotate)) -%>
32 <% html_title(l(:button_annotate)) -%>
33
33
34 <% content_for :header_tags do %>
34 <% content_for :header_tags do %>
35 <%= stylesheet_link_tag 'scm' %>
35 <%= stylesheet_link_tag 'scm' %>
36 <% end %>
36 <% end %>
@@ -1,398 +1,410
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
2 # Copyright (C) 2006-2012 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 'cgi'
18 require 'cgi'
19
19
20 module Redmine
20 module Redmine
21 module Scm
21 module Scm
22 module Adapters
22 module Adapters
23 class CommandFailed < StandardError #:nodoc:
23 class CommandFailed < StandardError #:nodoc:
24 end
24 end
25
25
26 class AbstractAdapter #:nodoc:
26 class AbstractAdapter #:nodoc:
27
27
28 # raised if scm command exited with error, e.g. unknown revision.
28 # raised if scm command exited with error, e.g. unknown revision.
29 class ScmCommandAborted < CommandFailed; end
29 class ScmCommandAborted < CommandFailed; end
30
30
31 class << self
31 class << self
32 def client_command
32 def client_command
33 ""
33 ""
34 end
34 end
35
35
36 def shell_quote_command
36 def shell_quote_command
37 if Redmine::Platform.mswin? && RUBY_PLATFORM == 'java'
37 if Redmine::Platform.mswin? && RUBY_PLATFORM == 'java'
38 client_command
38 client_command
39 else
39 else
40 shell_quote(client_command)
40 shell_quote(client_command)
41 end
41 end
42 end
42 end
43
43
44 # Returns the version of the scm client
44 # Returns the version of the scm client
45 # Eg: [1, 5, 0] or [] if unknown
45 # Eg: [1, 5, 0] or [] if unknown
46 def client_version
46 def client_version
47 []
47 []
48 end
48 end
49
49
50 # Returns the version string of the scm client
50 # Returns the version string of the scm client
51 # Eg: '1.5.0' or 'Unknown version' if unknown
51 # Eg: '1.5.0' or 'Unknown version' if unknown
52 def client_version_string
52 def client_version_string
53 v = client_version || 'Unknown version'
53 v = client_version || 'Unknown version'
54 v.is_a?(Array) ? v.join('.') : v.to_s
54 v.is_a?(Array) ? v.join('.') : v.to_s
55 end
55 end
56
56
57 # Returns true if the current client version is above
57 # Returns true if the current client version is above
58 # or equals the given one
58 # or equals the given one
59 # If option is :unknown is set to true, it will return
59 # If option is :unknown is set to true, it will return
60 # true if the client version is unknown
60 # true if the client version is unknown
61 def client_version_above?(v, options={})
61 def client_version_above?(v, options={})
62 ((client_version <=> v) >= 0) || (client_version.empty? && options[:unknown])
62 ((client_version <=> v) >= 0) || (client_version.empty? && options[:unknown])
63 end
63 end
64
64
65 def client_available
65 def client_available
66 true
66 true
67 end
67 end
68
68
69 def shell_quote(str)
69 def shell_quote(str)
70 if Redmine::Platform.mswin?
70 if Redmine::Platform.mswin?
71 '"' + str.gsub(/"/, '\\"') + '"'
71 '"' + str.gsub(/"/, '\\"') + '"'
72 else
72 else
73 "'" + str.gsub(/'/, "'\"'\"'") + "'"
73 "'" + str.gsub(/'/, "'\"'\"'") + "'"
74 end
74 end
75 end
75 end
76 end
76 end
77
77
78 def initialize(url, root_url=nil, login=nil, password=nil,
78 def initialize(url, root_url=nil, login=nil, password=nil,
79 path_encoding=nil)
79 path_encoding=nil)
80 @url = url
80 @url = url
81 @login = login if login && !login.empty?
81 @login = login if login && !login.empty?
82 @password = (password || "") if @login
82 @password = (password || "") if @login
83 @root_url = root_url.blank? ? retrieve_root_url : root_url
83 @root_url = root_url.blank? ? retrieve_root_url : root_url
84 end
84 end
85
85
86 def adapter_name
86 def adapter_name
87 'Abstract'
87 'Abstract'
88 end
88 end
89
89
90 def supports_cat?
90 def supports_cat?
91 true
91 true
92 end
92 end
93
93
94 def supports_annotate?
94 def supports_annotate?
95 respond_to?('annotate')
95 respond_to?('annotate')
96 end
96 end
97
97
98 def root_url
98 def root_url
99 @root_url
99 @root_url
100 end
100 end
101
101
102 def url
102 def url
103 @url
103 @url
104 end
104 end
105
105
106 def path_encoding
106 def path_encoding
107 nil
107 nil
108 end
108 end
109
109
110 # get info about the svn repository
110 # get info about the svn repository
111 def info
111 def info
112 return nil
112 return nil
113 end
113 end
114
114
115 # Returns the entry identified by path and revision identifier
115 # Returns the entry identified by path and revision identifier
116 # or nil if entry doesn't exist in the repository
116 # or nil if entry doesn't exist in the repository
117 def entry(path=nil, identifier=nil)
117 def entry(path=nil, identifier=nil)
118 parts = path.to_s.split(%r{[\/\\]}).select {|n| !n.blank?}
118 parts = path.to_s.split(%r{[\/\\]}).select {|n| !n.blank?}
119 search_path = parts[0..-2].join('/')
119 search_path = parts[0..-2].join('/')
120 search_name = parts[-1]
120 search_name = parts[-1]
121 if search_path.blank? && search_name.blank?
121 if search_path.blank? && search_name.blank?
122 # Root entry
122 # Root entry
123 Entry.new(:path => '', :kind => 'dir')
123 Entry.new(:path => '', :kind => 'dir')
124 else
124 else
125 # Search for the entry in the parent directory
125 # Search for the entry in the parent directory
126 es = entries(search_path, identifier)
126 es = entries(search_path, identifier)
127 es ? es.detect {|e| e.name == search_name} : nil
127 es ? es.detect {|e| e.name == search_name} : nil
128 end
128 end
129 end
129 end
130
130
131 # Returns an Entries collection
131 # Returns an Entries collection
132 # or nil if the given path doesn't exist in the repository
132 # or nil if the given path doesn't exist in the repository
133 def entries(path=nil, identifier=nil, options={})
133 def entries(path=nil, identifier=nil, options={})
134 return nil
134 return nil
135 end
135 end
136
136
137 def branches
137 def branches
138 return nil
138 return nil
139 end
139 end
140
140
141 def tags
141 def tags
142 return nil
142 return nil
143 end
143 end
144
144
145 def default_branch
145 def default_branch
146 return nil
146 return nil
147 end
147 end
148
148
149 def properties(path, identifier=nil)
149 def properties(path, identifier=nil)
150 return nil
150 return nil
151 end
151 end
152
152
153 def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={})
153 def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={})
154 return nil
154 return nil
155 end
155 end
156
156
157 def diff(path, identifier_from, identifier_to=nil)
157 def diff(path, identifier_from, identifier_to=nil)
158 return nil
158 return nil
159 end
159 end
160
160
161 def cat(path, identifier=nil)
161 def cat(path, identifier=nil)
162 return nil
162 return nil
163 end
163 end
164
164
165 def with_leading_slash(path)
165 def with_leading_slash(path)
166 path ||= ''
166 path ||= ''
167 (path[0,1]!="/") ? "/#{path}" : path
167 (path[0,1]!="/") ? "/#{path}" : path
168 end
168 end
169
169
170 def with_trailling_slash(path)
170 def with_trailling_slash(path)
171 path ||= ''
171 path ||= ''
172 (path[-1,1] == "/") ? path : "#{path}/"
172 (path[-1,1] == "/") ? path : "#{path}/"
173 end
173 end
174
174
175 def without_leading_slash(path)
175 def without_leading_slash(path)
176 path ||= ''
176 path ||= ''
177 path.gsub(%r{^/+}, '')
177 path.gsub(%r{^/+}, '')
178 end
178 end
179
179
180 def without_trailling_slash(path)
180 def without_trailling_slash(path)
181 path ||= ''
181 path ||= ''
182 (path[-1,1] == "/") ? path[0..-2] : path
182 (path[-1,1] == "/") ? path[0..-2] : path
183 end
183 end
184
184
185 def shell_quote(str)
185 def shell_quote(str)
186 self.class.shell_quote(str)
186 self.class.shell_quote(str)
187 end
187 end
188
188
189 private
189 private
190 def retrieve_root_url
190 def retrieve_root_url
191 info = self.info
191 info = self.info
192 info ? info.root_url : nil
192 info ? info.root_url : nil
193 end
193 end
194
194
195 def target(path, sq=true)
195 def target(path, sq=true)
196 path ||= ''
196 path ||= ''
197 base = path.match(/^\//) ? root_url : url
197 base = path.match(/^\//) ? root_url : url
198 str = "#{base}/#{path}".gsub(/[?<>\*]/, '')
198 str = "#{base}/#{path}".gsub(/[?<>\*]/, '')
199 if sq
199 if sq
200 str = shell_quote(str)
200 str = shell_quote(str)
201 end
201 end
202 str
202 str
203 end
203 end
204
204
205 def logger
205 def logger
206 self.class.logger
206 self.class.logger
207 end
207 end
208
208
209 def shellout(cmd, options = {}, &block)
209 def shellout(cmd, options = {}, &block)
210 self.class.shellout(cmd, options, &block)
210 self.class.shellout(cmd, options, &block)
211 end
211 end
212
212
213 def self.logger
213 def self.logger
214 Rails.logger
214 Rails.logger
215 end
215 end
216
216
217 def self.shellout(cmd, options = {}, &block)
217 def self.shellout(cmd, options = {}, &block)
218 if logger && logger.debug?
218 if logger && logger.debug?
219 logger.debug "Shelling out: #{strip_credential(cmd)}"
219 logger.debug "Shelling out: #{strip_credential(cmd)}"
220 end
220 end
221 if Rails.env == 'development'
221 if Rails.env == 'development'
222 # Capture stderr when running in dev environment
222 # Capture stderr when running in dev environment
223 cmd = "#{cmd} 2>>#{shell_quote(Rails.root.join('log/scm.stderr.log').to_s)}"
223 cmd = "#{cmd} 2>>#{shell_quote(Rails.root.join('log/scm.stderr.log').to_s)}"
224 end
224 end
225 begin
225 begin
226 mode = "r+"
226 mode = "r+"
227 IO.popen(cmd, mode) do |io|
227 IO.popen(cmd, mode) do |io|
228 io.set_encoding("ASCII-8BIT") if io.respond_to?(:set_encoding)
228 io.set_encoding("ASCII-8BIT") if io.respond_to?(:set_encoding)
229 io.close_write unless options[:write_stdin]
229 io.close_write unless options[:write_stdin]
230 block.call(io) if block_given?
230 block.call(io) if block_given?
231 end
231 end
232 ## If scm command does not exist,
232 ## If scm command does not exist,
233 ## Linux JRuby 1.6.2 (ruby-1.8.7-p330) raises java.io.IOException
233 ## Linux JRuby 1.6.2 (ruby-1.8.7-p330) raises java.io.IOException
234 ## in production environment.
234 ## in production environment.
235 # rescue Errno::ENOENT => e
235 # rescue Errno::ENOENT => e
236 rescue Exception => e
236 rescue Exception => e
237 msg = strip_credential(e.message)
237 msg = strip_credential(e.message)
238 # The command failed, log it and re-raise
238 # The command failed, log it and re-raise
239 logmsg = "SCM command failed, "
239 logmsg = "SCM command failed, "
240 logmsg += "make sure that your SCM command (e.g. svn) is "
240 logmsg += "make sure that your SCM command (e.g. svn) is "
241 logmsg += "in PATH (#{ENV['PATH']})\n"
241 logmsg += "in PATH (#{ENV['PATH']})\n"
242 logmsg += "You can configure your scm commands in config/configuration.yml.\n"
242 logmsg += "You can configure your scm commands in config/configuration.yml.\n"
243 logmsg += "#{strip_credential(cmd)}\n"
243 logmsg += "#{strip_credential(cmd)}\n"
244 logmsg += "with: #{msg}"
244 logmsg += "with: #{msg}"
245 logger.error(logmsg)
245 logger.error(logmsg)
246 raise CommandFailed.new(msg)
246 raise CommandFailed.new(msg)
247 end
247 end
248 end
248 end
249
249
250 # Hides username/password in a given command
250 # Hides username/password in a given command
251 def self.strip_credential(cmd)
251 def self.strip_credential(cmd)
252 q = (Redmine::Platform.mswin? ? '"' : "'")
252 q = (Redmine::Platform.mswin? ? '"' : "'")
253 cmd.to_s.gsub(/(\-\-(password|username))\s+(#{q}[^#{q}]+#{q}|[^#{q}]\S+)/, '\\1 xxxx')
253 cmd.to_s.gsub(/(\-\-(password|username))\s+(#{q}[^#{q}]+#{q}|[^#{q}]\S+)/, '\\1 xxxx')
254 end
254 end
255
255
256 def strip_credential(cmd)
256 def strip_credential(cmd)
257 self.class.strip_credential(cmd)
257 self.class.strip_credential(cmd)
258 end
258 end
259
259
260 def scm_iconv(to, from, str)
260 def scm_iconv(to, from, str)
261 return nil if str.nil?
261 return nil if str.nil?
262 return str if to == from
262 return str if to == from
263 begin
263 begin
264 Iconv.conv(to, from, str)
264 Iconv.conv(to, from, str)
265 rescue Iconv::Failure => err
265 rescue Iconv::Failure => err
266 logger.error("failed to convert from #{from} to #{to}. #{err}")
266 logger.error("failed to convert from #{from} to #{to}. #{err}")
267 nil
267 nil
268 end
268 end
269 end
269 end
270
270
271 def parse_xml(xml)
271 def parse_xml(xml)
272 if RUBY_PLATFORM == 'java'
272 if RUBY_PLATFORM == 'java'
273 xml = xml.sub(%r{<\?xml[^>]*\?>}, '')
273 xml = xml.sub(%r{<\?xml[^>]*\?>}, '')
274 end
274 end
275 ActiveSupport::XmlMini.parse(xml)
275 ActiveSupport::XmlMini.parse(xml)
276 end
276 end
277 end
277 end
278
278
279 class Entries < Array
279 class Entries < Array
280 def sort_by_name
280 def sort_by_name
281 dup.sort! {|x,y|
281 dup.sort! {|x,y|
282 if x.kind == y.kind
282 if x.kind == y.kind
283 x.name.to_s <=> y.name.to_s
283 x.name.to_s <=> y.name.to_s
284 else
284 else
285 x.kind <=> y.kind
285 x.kind <=> y.kind
286 end
286 end
287 }
287 }
288 end
288 end
289
289
290 def revisions
290 def revisions
291 revisions ||= Revisions.new(collect{|entry| entry.lastrev}.compact)
291 revisions ||= Revisions.new(collect{|entry| entry.lastrev}.compact)
292 end
292 end
293 end
293 end
294
294
295 class Info
295 class Info
296 attr_accessor :root_url, :lastrev
296 attr_accessor :root_url, :lastrev
297 def initialize(attributes={})
297 def initialize(attributes={})
298 self.root_url = attributes[:root_url] if attributes[:root_url]
298 self.root_url = attributes[:root_url] if attributes[:root_url]
299 self.lastrev = attributes[:lastrev]
299 self.lastrev = attributes[:lastrev]
300 end
300 end
301 end
301 end
302
302
303 class Entry
303 class Entry
304 attr_accessor :name, :path, :kind, :size, :lastrev, :changeset
304 attr_accessor :name, :path, :kind, :size, :lastrev, :changeset
305
305
306 def initialize(attributes={})
306 def initialize(attributes={})
307 self.name = attributes[:name] if attributes[:name]
307 self.name = attributes[:name] if attributes[:name]
308 self.path = attributes[:path] if attributes[:path]
308 self.path = attributes[:path] if attributes[:path]
309 self.kind = attributes[:kind] if attributes[:kind]
309 self.kind = attributes[:kind] if attributes[:kind]
310 self.size = attributes[:size].to_i if attributes[:size]
310 self.size = attributes[:size].to_i if attributes[:size]
311 self.lastrev = attributes[:lastrev]
311 self.lastrev = attributes[:lastrev]
312 end
312 end
313
313
314 def is_file?
314 def is_file?
315 'file' == self.kind
315 'file' == self.kind
316 end
316 end
317
317
318 def is_dir?
318 def is_dir?
319 'dir' == self.kind
319 'dir' == self.kind
320 end
320 end
321
321
322 def is_text?
322 def is_text?
323 Redmine::MimeType.is_type?('text', name)
323 Redmine::MimeType.is_type?('text', name)
324 end
324 end
325
325
326 def author
326 def author
327 if changeset
327 if changeset
328 changeset.author.to_s
328 changeset.author.to_s
329 elsif lastrev
329 elsif lastrev
330 Redmine::CodesetUtil.replace_invalid_utf8(lastrev.author.to_s.split('<').first)
330 Redmine::CodesetUtil.replace_invalid_utf8(lastrev.author.to_s.split('<').first)
331 end
331 end
332 end
332 end
333 end
333 end
334
334
335 class Revisions < Array
335 class Revisions < Array
336 def latest
336 def latest
337 sort {|x,y|
337 sort {|x,y|
338 unless x.time.nil? or y.time.nil?
338 unless x.time.nil? or y.time.nil?
339 x.time <=> y.time
339 x.time <=> y.time
340 else
340 else
341 0
341 0
342 end
342 end
343 }.last
343 }.last
344 end
344 end
345 end
345 end
346
346
347 class Revision
347 class Revision
348 attr_accessor :scmid, :name, :author, :time, :message,
348 attr_accessor :scmid, :name, :author, :time, :message,
349 :paths, :revision, :branch, :identifier,
349 :paths, :revision, :branch, :identifier,
350 :parents
350 :parents
351
351
352 def initialize(attributes={})
352 def initialize(attributes={})
353 self.identifier = attributes[:identifier]
353 self.identifier = attributes[:identifier]
354 self.scmid = attributes[:scmid]
354 self.scmid = attributes[:scmid]
355 self.name = attributes[:name] || self.identifier
355 self.name = attributes[:name] || self.identifier
356 self.author = attributes[:author]
356 self.author = attributes[:author]
357 self.time = attributes[:time]
357 self.time = attributes[:time]
358 self.message = attributes[:message] || ""
358 self.message = attributes[:message] || ""
359 self.paths = attributes[:paths]
359 self.paths = attributes[:paths]
360 self.revision = attributes[:revision]
360 self.revision = attributes[:revision]
361 self.branch = attributes[:branch]
361 self.branch = attributes[:branch]
362 self.parents = attributes[:parents]
362 self.parents = attributes[:parents]
363 end
363 end
364
364
365 # Returns the readable identifier.
365 # Returns the readable identifier.
366 def format_identifier
366 def format_identifier
367 self.identifier.to_s
367 self.identifier.to_s
368 end
368 end
369
370 def ==(other)
371 if other.nil?
372 false
373 elsif scmid.present?
374 scmid == other.scmid
375 elsif identifier.present?
376 identifier == other.identifier
377 elsif revision.present?
378 revision == other.revision
379 end
380 end
369 end
381 end
370
382
371 class Annotate
383 class Annotate
372 attr_reader :lines, :revisions
384 attr_reader :lines, :revisions
373
385
374 def initialize
386 def initialize
375 @lines = []
387 @lines = []
376 @revisions = []
388 @revisions = []
377 end
389 end
378
390
379 def add_line(line, revision)
391 def add_line(line, revision)
380 @lines << line
392 @lines << line
381 @revisions << revision
393 @revisions << revision
382 end
394 end
383
395
384 def content
396 def content
385 content = lines.join("\n")
397 content = lines.join("\n")
386 end
398 end
387
399
388 def empty?
400 def empty?
389 lines.empty?
401 lines.empty?
390 end
402 end
391 end
403 end
392
404
393 class Branch < String
405 class Branch < String
394 attr_accessor :revision, :scmid
406 attr_accessor :revision, :scmid
395 end
407 end
396 end
408 end
397 end
409 end
398 end
410 end
@@ -1,289 +1,289
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
2 # Copyright (C) 2006-2012 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 RepositoriesCvsControllerTest < ActionController::TestCase
20 class RepositoriesCvsControllerTest < ActionController::TestCase
21 tests RepositoriesController
21 tests RepositoriesController
22
22
23 fixtures :projects, :users, :roles, :members, :member_roles,
23 fixtures :projects, :users, :roles, :members, :member_roles,
24 :repositories, :enabled_modules
24 :repositories, :enabled_modules
25
25
26 REPOSITORY_PATH = Rails.root.join('tmp/test/cvs_repository').to_s
26 REPOSITORY_PATH = Rails.root.join('tmp/test/cvs_repository').to_s
27 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
27 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
28 # CVS module
28 # CVS module
29 MODULE_NAME = 'test'
29 MODULE_NAME = 'test'
30 PRJ_ID = 3
30 PRJ_ID = 3
31 NUM_REV = 7
31 NUM_REV = 7
32
32
33 def setup
33 def setup
34 Setting.default_language = 'en'
34 Setting.default_language = 'en'
35 User.current = nil
35 User.current = nil
36
36
37 @project = Project.find(PRJ_ID)
37 @project = Project.find(PRJ_ID)
38 @repository = Repository::Cvs.create(:project => Project.find(PRJ_ID),
38 @repository = Repository::Cvs.create(:project => Project.find(PRJ_ID),
39 :root_url => REPOSITORY_PATH,
39 :root_url => REPOSITORY_PATH,
40 :url => MODULE_NAME,
40 :url => MODULE_NAME,
41 :log_encoding => 'UTF-8')
41 :log_encoding => 'UTF-8')
42 assert @repository
42 assert @repository
43 end
43 end
44
44
45 if File.directory?(REPOSITORY_PATH)
45 if File.directory?(REPOSITORY_PATH)
46 def test_get_new
46 def test_get_new
47 @request.session[:user_id] = 1
47 @request.session[:user_id] = 1
48 @project.repository.destroy
48 @project.repository.destroy
49 get :new, :project_id => 'subproject1', :repository_scm => 'Cvs'
49 get :new, :project_id => 'subproject1', :repository_scm => 'Cvs'
50 assert_response :success
50 assert_response :success
51 assert_template 'new'
51 assert_template 'new'
52 assert_kind_of Repository::Cvs, assigns(:repository)
52 assert_kind_of Repository::Cvs, assigns(:repository)
53 assert assigns(:repository).new_record?
53 assert assigns(:repository).new_record?
54 end
54 end
55
55
56 def test_browse_root
56 def test_browse_root
57 assert_equal 0, @repository.changesets.count
57 assert_equal 0, @repository.changesets.count
58 @repository.fetch_changesets
58 @repository.fetch_changesets
59 @project.reload
59 @project.reload
60 assert_equal NUM_REV, @repository.changesets.count
60 assert_equal NUM_REV, @repository.changesets.count
61 get :show, :id => PRJ_ID
61 get :show, :id => PRJ_ID
62 assert_response :success
62 assert_response :success
63 assert_template 'show'
63 assert_template 'show'
64 assert_not_nil assigns(:entries)
64 assert_not_nil assigns(:entries)
65 assert_equal 3, assigns(:entries).size
65 assert_equal 3, assigns(:entries).size
66
66
67 entry = assigns(:entries).detect {|e| e.name == 'images'}
67 entry = assigns(:entries).detect {|e| e.name == 'images'}
68 assert_equal 'dir', entry.kind
68 assert_equal 'dir', entry.kind
69
69
70 entry = assigns(:entries).detect {|e| e.name == 'README'}
70 entry = assigns(:entries).detect {|e| e.name == 'README'}
71 assert_equal 'file', entry.kind
71 assert_equal 'file', entry.kind
72
72
73 assert_not_nil assigns(:changesets)
73 assert_not_nil assigns(:changesets)
74 assert assigns(:changesets).size > 0
74 assert assigns(:changesets).size > 0
75 end
75 end
76
76
77 def test_browse_directory
77 def test_browse_directory
78 assert_equal 0, @repository.changesets.count
78 assert_equal 0, @repository.changesets.count
79 @repository.fetch_changesets
79 @repository.fetch_changesets
80 @project.reload
80 @project.reload
81 assert_equal NUM_REV, @repository.changesets.count
81 assert_equal NUM_REV, @repository.changesets.count
82 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param]
82 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param]
83 assert_response :success
83 assert_response :success
84 assert_template 'show'
84 assert_template 'show'
85 assert_not_nil assigns(:entries)
85 assert_not_nil assigns(:entries)
86 assert_equal ['add.png', 'delete.png', 'edit.png'], assigns(:entries).collect(&:name)
86 assert_equal ['add.png', 'delete.png', 'edit.png'], assigns(:entries).collect(&:name)
87 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
87 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
88 assert_not_nil entry
88 assert_not_nil entry
89 assert_equal 'file', entry.kind
89 assert_equal 'file', entry.kind
90 assert_equal 'images/edit.png', entry.path
90 assert_equal 'images/edit.png', entry.path
91 end
91 end
92
92
93 def test_browse_at_given_revision
93 def test_browse_at_given_revision
94 assert_equal 0, @repository.changesets.count
94 assert_equal 0, @repository.changesets.count
95 @repository.fetch_changesets
95 @repository.fetch_changesets
96 @project.reload
96 @project.reload
97 assert_equal NUM_REV, @repository.changesets.count
97 assert_equal NUM_REV, @repository.changesets.count
98 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param],
98 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param],
99 :rev => 1
99 :rev => 1
100 assert_response :success
100 assert_response :success
101 assert_template 'show'
101 assert_template 'show'
102 assert_not_nil assigns(:entries)
102 assert_not_nil assigns(:entries)
103 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
103 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
104 end
104 end
105
105
106 def test_entry
106 def test_entry
107 assert_equal 0, @repository.changesets.count
107 assert_equal 0, @repository.changesets.count
108 @repository.fetch_changesets
108 @repository.fetch_changesets
109 @project.reload
109 @project.reload
110 assert_equal NUM_REV, @repository.changesets.count
110 assert_equal NUM_REV, @repository.changesets.count
111 get :entry, :id => PRJ_ID,
111 get :entry, :id => PRJ_ID,
112 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
112 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
113 assert_response :success
113 assert_response :success
114 assert_template 'entry'
114 assert_template 'entry'
115 assert_no_tag :tag => 'td',
115 assert_no_tag :tag => 'td',
116 :attributes => { :class => /line-code/},
116 :attributes => { :class => /line-code/},
117 :content => /before_filter/
117 :content => /before_filter/
118 end
118 end
119
119
120 def test_entry_at_given_revision
120 def test_entry_at_given_revision
121 # changesets must be loaded
121 # changesets must be loaded
122 assert_equal 0, @repository.changesets.count
122 assert_equal 0, @repository.changesets.count
123 @repository.fetch_changesets
123 @repository.fetch_changesets
124 @project.reload
124 @project.reload
125 assert_equal NUM_REV, @repository.changesets.count
125 assert_equal NUM_REV, @repository.changesets.count
126 get :entry, :id => PRJ_ID,
126 get :entry, :id => PRJ_ID,
127 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
127 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
128 :rev => 2
128 :rev => 2
129 assert_response :success
129 assert_response :success
130 assert_template 'entry'
130 assert_template 'entry'
131 # this line was removed in r3
131 # this line was removed in r3
132 assert_tag :tag => 'td',
132 assert_tag :tag => 'td',
133 :attributes => { :class => /line-code/},
133 :attributes => { :class => /line-code/},
134 :content => /before_filter/
134 :content => /before_filter/
135 end
135 end
136
136
137 def test_entry_not_found
137 def test_entry_not_found
138 assert_equal 0, @repository.changesets.count
138 assert_equal 0, @repository.changesets.count
139 @repository.fetch_changesets
139 @repository.fetch_changesets
140 @project.reload
140 @project.reload
141 assert_equal NUM_REV, @repository.changesets.count
141 assert_equal NUM_REV, @repository.changesets.count
142 get :entry, :id => PRJ_ID,
142 get :entry, :id => PRJ_ID,
143 :path => repository_path_hash(['sources', 'zzz.c'])[:param]
143 :path => repository_path_hash(['sources', 'zzz.c'])[:param]
144 assert_tag :tag => 'p',
144 assert_tag :tag => 'p',
145 :attributes => { :id => /errorExplanation/ },
145 :attributes => { :id => /errorExplanation/ },
146 :content => /The entry or revision was not found in the repository/
146 :content => /The entry or revision was not found in the repository/
147 end
147 end
148
148
149 def test_entry_download
149 def test_entry_download
150 assert_equal 0, @repository.changesets.count
150 assert_equal 0, @repository.changesets.count
151 @repository.fetch_changesets
151 @repository.fetch_changesets
152 @project.reload
152 @project.reload
153 assert_equal NUM_REV, @repository.changesets.count
153 assert_equal NUM_REV, @repository.changesets.count
154 get :entry, :id => PRJ_ID,
154 get :entry, :id => PRJ_ID,
155 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
155 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
156 :format => 'raw'
156 :format => 'raw'
157 assert_response :success
157 assert_response :success
158 end
158 end
159
159
160 def test_directory_entry
160 def test_directory_entry
161 assert_equal 0, @repository.changesets.count
161 assert_equal 0, @repository.changesets.count
162 @repository.fetch_changesets
162 @repository.fetch_changesets
163 @project.reload
163 @project.reload
164 assert_equal NUM_REV, @repository.changesets.count
164 assert_equal NUM_REV, @repository.changesets.count
165 get :entry, :id => PRJ_ID,
165 get :entry, :id => PRJ_ID,
166 :path => repository_path_hash(['sources'])[:param]
166 :path => repository_path_hash(['sources'])[:param]
167 assert_response :success
167 assert_response :success
168 assert_template 'show'
168 assert_template 'show'
169 assert_not_nil assigns(:entry)
169 assert_not_nil assigns(:entry)
170 assert_equal 'sources', assigns(:entry).name
170 assert_equal 'sources', assigns(:entry).name
171 end
171 end
172
172
173 def test_diff
173 def test_diff
174 assert_equal 0, @repository.changesets.count
174 assert_equal 0, @repository.changesets.count
175 @repository.fetch_changesets
175 @repository.fetch_changesets
176 @project.reload
176 @project.reload
177 assert_equal NUM_REV, @repository.changesets.count
177 assert_equal NUM_REV, @repository.changesets.count
178 ['inline', 'sbs'].each do |dt|
178 ['inline', 'sbs'].each do |dt|
179 get :diff, :id => PRJ_ID, :rev => 3, :type => dt
179 get :diff, :id => PRJ_ID, :rev => 3, :type => dt
180 assert_response :success
180 assert_response :success
181 assert_template 'diff'
181 assert_template 'diff'
182 assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_out' },
182 assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_out' },
183 :content => /before_filter :require_login/
183 :content => /before_filter :require_login/
184 assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' },
184 assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' },
185 :content => /with one change/
185 :content => /with one change/
186 end
186 end
187 end
187 end
188
188
189 def test_diff_new_files
189 def test_diff_new_files
190 assert_equal 0, @repository.changesets.count
190 assert_equal 0, @repository.changesets.count
191 @repository.fetch_changesets
191 @repository.fetch_changesets
192 @project.reload
192 @project.reload
193 assert_equal NUM_REV, @repository.changesets.count
193 assert_equal NUM_REV, @repository.changesets.count
194 ['inline', 'sbs'].each do |dt|
194 ['inline', 'sbs'].each do |dt|
195 get :diff, :id => PRJ_ID, :rev => 1, :type => dt
195 get :diff, :id => PRJ_ID, :rev => 1, :type => dt
196 assert_response :success
196 assert_response :success
197 assert_template 'diff'
197 assert_template 'diff'
198 assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' },
198 assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' },
199 :content => /watched.remove_watcher/
199 :content => /watched.remove_watcher/
200 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
200 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
201 :content => /test\/README/
201 :content => /test\/README/
202 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
202 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
203 :content => /test\/images\/delete.png /
203 :content => /test\/images\/delete.png /
204 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
204 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
205 :content => /test\/images\/edit.png/
205 :content => /test\/images\/edit.png/
206 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
206 assert_tag :tag => 'th', :attributes => { :class => 'filename' },
207 :content => /test\/sources\/watchers_controller.rb/
207 :content => /test\/sources\/watchers_controller.rb/
208 end
208 end
209 end
209 end
210
210
211 def test_annotate
211 def test_annotate
212 assert_equal 0, @repository.changesets.count
212 assert_equal 0, @repository.changesets.count
213 @repository.fetch_changesets
213 @repository.fetch_changesets
214 @project.reload
214 @project.reload
215 assert_equal NUM_REV, @repository.changesets.count
215 assert_equal NUM_REV, @repository.changesets.count
216 get :annotate, :id => PRJ_ID,
216 get :annotate, :id => PRJ_ID,
217 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
217 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
218 assert_response :success
218 assert_response :success
219 assert_template 'annotate'
219 assert_template 'annotate'
220 # 1.1 line
220 # 1.1 line
221 assert_tag :tag => 'th',
221 assert_tag :tag => 'th',
222 :attributes => { :class => 'line-num' },
222 :attributes => { :class => 'line-num' },
223 :content => '18',
223 :content => '21',
224 :sibling => {
224 :sibling => {
225 :tag => 'td',
225 :tag => 'td',
226 :attributes => { :class => 'revision' },
226 :attributes => { :class => 'revision' },
227 :content => /1.1/,
227 :content => /1.1/,
228 :sibling => {
228 :sibling => {
229 :tag => 'td',
229 :tag => 'td',
230 :attributes => { :class => 'author' },
230 :attributes => { :class => 'author' },
231 :content => /LANG/
231 :content => /LANG/
232 }
232 }
233 }
233 }
234 # 1.2 line
234 # 1.2 line
235 assert_tag :tag => 'th',
235 assert_tag :tag => 'th',
236 :attributes => { :class => 'line-num' },
236 :attributes => { :class => 'line-num' },
237 :content => '32',
237 :content => '32',
238 :sibling => {
238 :sibling => {
239 :tag => 'td',
239 :tag => 'td',
240 :attributes => { :class => 'revision' },
240 :attributes => { :class => 'revision' },
241 :content => /1.2/,
241 :content => /1.2/,
242 :sibling => {
242 :sibling => {
243 :tag => 'td',
243 :tag => 'td',
244 :attributes => { :class => 'author' },
244 :attributes => { :class => 'author' },
245 :content => /LANG/
245 :content => /LANG/
246 }
246 }
247 }
247 }
248 end
248 end
249
249
250 def test_destroy_valid_repository
250 def test_destroy_valid_repository
251 @request.session[:user_id] = 1 # admin
251 @request.session[:user_id] = 1 # admin
252 assert_equal 0, @repository.changesets.count
252 assert_equal 0, @repository.changesets.count
253 @repository.fetch_changesets
253 @repository.fetch_changesets
254 @project.reload
254 @project.reload
255 assert_equal NUM_REV, @repository.changesets.count
255 assert_equal NUM_REV, @repository.changesets.count
256
256
257 assert_difference 'Repository.count', -1 do
257 assert_difference 'Repository.count', -1 do
258 delete :destroy, :id => @repository.id
258 delete :destroy, :id => @repository.id
259 end
259 end
260 assert_response 302
260 assert_response 302
261 @project.reload
261 @project.reload
262 assert_nil @project.repository
262 assert_nil @project.repository
263 end
263 end
264
264
265 def test_destroy_invalid_repository
265 def test_destroy_invalid_repository
266 @request.session[:user_id] = 1 # admin
266 @request.session[:user_id] = 1 # admin
267 @project.repository.destroy
267 @project.repository.destroy
268 @repository = Repository::Cvs.create!(
268 @repository = Repository::Cvs.create!(
269 :project => Project.find(PRJ_ID),
269 :project => Project.find(PRJ_ID),
270 :root_url => "/invalid",
270 :root_url => "/invalid",
271 :url => MODULE_NAME,
271 :url => MODULE_NAME,
272 :log_encoding => 'UTF-8'
272 :log_encoding => 'UTF-8'
273 )
273 )
274 @repository.fetch_changesets
274 @repository.fetch_changesets
275 @project.reload
275 @project.reload
276 assert_equal 0, @repository.changesets.count
276 assert_equal 0, @repository.changesets.count
277
277
278 assert_difference 'Repository.count', -1 do
278 assert_difference 'Repository.count', -1 do
279 delete :destroy, :id => @repository.id
279 delete :destroy, :id => @repository.id
280 end
280 end
281 assert_response 302
281 assert_response 302
282 @project.reload
282 @project.reload
283 assert_nil @project.repository
283 assert_nil @project.repository
284 end
284 end
285 else
285 else
286 puts "CVS test repository NOT FOUND. Skipping functional tests !!!"
286 puts "CVS test repository NOT FOUND. Skipping functional tests !!!"
287 def test_fake; assert true end
287 def test_fake; assert true end
288 end
288 end
289 end
289 end
@@ -1,547 +1,547
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
2 # Copyright (C) 2006-2012 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 RepositoriesGitControllerTest < ActionController::TestCase
20 class RepositoriesGitControllerTest < ActionController::TestCase
21 tests RepositoriesController
21 tests RepositoriesController
22
22
23 fixtures :projects, :users, :roles, :members, :member_roles,
23 fixtures :projects, :users, :roles, :members, :member_roles,
24 :repositories, :enabled_modules
24 :repositories, :enabled_modules
25
25
26 REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
26 REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
27 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
27 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
28 PRJ_ID = 3
28 PRJ_ID = 3
29 CHAR_1_HEX = "\xc3\x9c"
29 CHAR_1_HEX = "\xc3\x9c"
30 NUM_REV = 28
30 NUM_REV = 28
31
31
32 ## Git, Mercurial and CVS path encodings are binary.
32 ## Git, Mercurial and CVS path encodings are binary.
33 ## Subversion supports URL encoding for path.
33 ## Subversion supports URL encoding for path.
34 ## Redmine Mercurial adapter and extension use URL encoding.
34 ## Redmine Mercurial adapter and extension use URL encoding.
35 ## Git accepts only binary path in command line parameter.
35 ## Git accepts only binary path in command line parameter.
36 ## So, there is no way to use binary command line parameter in JRuby.
36 ## So, there is no way to use binary command line parameter in JRuby.
37 JRUBY_SKIP = (RUBY_PLATFORM == 'java')
37 JRUBY_SKIP = (RUBY_PLATFORM == 'java')
38 JRUBY_SKIP_STR = "TODO: This test fails in JRuby"
38 JRUBY_SKIP_STR = "TODO: This test fails in JRuby"
39
39
40 def setup
40 def setup
41 @ruby19_non_utf8_pass =
41 @ruby19_non_utf8_pass =
42 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
42 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
43
43
44 User.current = nil
44 User.current = nil
45 @project = Project.find(PRJ_ID)
45 @project = Project.find(PRJ_ID)
46 @repository = Repository::Git.create(
46 @repository = Repository::Git.create(
47 :project => @project,
47 :project => @project,
48 :url => REPOSITORY_PATH,
48 :url => REPOSITORY_PATH,
49 :path_encoding => 'ISO-8859-1'
49 :path_encoding => 'ISO-8859-1'
50 )
50 )
51 assert @repository
51 assert @repository
52 @char_1 = CHAR_1_HEX.dup
52 @char_1 = CHAR_1_HEX.dup
53 if @char_1.respond_to?(:force_encoding)
53 if @char_1.respond_to?(:force_encoding)
54 @char_1.force_encoding('UTF-8')
54 @char_1.force_encoding('UTF-8')
55 end
55 end
56
56
57 Setting.default_language = 'en'
57 Setting.default_language = 'en'
58 end
58 end
59
59
60 def test_create_and_update
60 def test_create_and_update
61 @request.session[:user_id] = 1
61 @request.session[:user_id] = 1
62 assert_difference 'Repository.count' do
62 assert_difference 'Repository.count' do
63 post :create, :project_id => 'subproject1',
63 post :create, :project_id => 'subproject1',
64 :repository_scm => 'Git',
64 :repository_scm => 'Git',
65 :repository => {
65 :repository => {
66 :url => '/test',
66 :url => '/test',
67 :is_default => '0',
67 :is_default => '0',
68 :identifier => 'test-create',
68 :identifier => 'test-create',
69 :extra_report_last_commit => '1',
69 :extra_report_last_commit => '1',
70 }
70 }
71 end
71 end
72 assert_response 302
72 assert_response 302
73 repository = Repository.first(:order => 'id DESC')
73 repository = Repository.first(:order => 'id DESC')
74 assert_kind_of Repository::Git, repository
74 assert_kind_of Repository::Git, repository
75 assert_equal '/test', repository.url
75 assert_equal '/test', repository.url
76 assert_equal true, repository.extra_report_last_commit
76 assert_equal true, repository.extra_report_last_commit
77
77
78 put :update, :id => repository.id,
78 put :update, :id => repository.id,
79 :repository => {
79 :repository => {
80 :extra_report_last_commit => '0'
80 :extra_report_last_commit => '0'
81 }
81 }
82 assert_response 302
82 assert_response 302
83 repo2 = Repository.find(repository.id)
83 repo2 = Repository.find(repository.id)
84 assert_equal false, repo2.extra_report_last_commit
84 assert_equal false, repo2.extra_report_last_commit
85 end
85 end
86
86
87 if File.directory?(REPOSITORY_PATH)
87 if File.directory?(REPOSITORY_PATH)
88 ## Ruby uses ANSI api to fork a process on Windows.
88 ## Ruby uses ANSI api to fork a process on Windows.
89 ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem
89 ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem
90 ## and these are incompatible with ASCII.
90 ## and these are incompatible with ASCII.
91 ## Git for Windows (msysGit) changed internal API from ANSI to Unicode in 1.7.10
91 ## Git for Windows (msysGit) changed internal API from ANSI to Unicode in 1.7.10
92 ## http://code.google.com/p/msysgit/issues/detail?id=80
92 ## http://code.google.com/p/msysgit/issues/detail?id=80
93 ## So, Latin-1 path tests fail on Japanese Windows
93 ## So, Latin-1 path tests fail on Japanese Windows
94 WINDOWS_PASS = (Redmine::Platform.mswin? &&
94 WINDOWS_PASS = (Redmine::Platform.mswin? &&
95 Redmine::Scm::Adapters::GitAdapter.client_version_above?([1, 7, 10]))
95 Redmine::Scm::Adapters::GitAdapter.client_version_above?([1, 7, 10]))
96 WINDOWS_SKIP_STR = "TODO: This test fails in Git for Windows above 1.7.10"
96 WINDOWS_SKIP_STR = "TODO: This test fails in Git for Windows above 1.7.10"
97
97
98 def test_get_new
98 def test_get_new
99 @request.session[:user_id] = 1
99 @request.session[:user_id] = 1
100 @project.repository.destroy
100 @project.repository.destroy
101 get :new, :project_id => 'subproject1', :repository_scm => 'Git'
101 get :new, :project_id => 'subproject1', :repository_scm => 'Git'
102 assert_response :success
102 assert_response :success
103 assert_template 'new'
103 assert_template 'new'
104 assert_kind_of Repository::Git, assigns(:repository)
104 assert_kind_of Repository::Git, assigns(:repository)
105 assert assigns(:repository).new_record?
105 assert assigns(:repository).new_record?
106 end
106 end
107
107
108 def test_browse_root
108 def test_browse_root
109 assert_equal 0, @repository.changesets.count
109 assert_equal 0, @repository.changesets.count
110 @repository.fetch_changesets
110 @repository.fetch_changesets
111 @project.reload
111 @project.reload
112 assert_equal NUM_REV, @repository.changesets.count
112 assert_equal NUM_REV, @repository.changesets.count
113
113
114 get :show, :id => PRJ_ID
114 get :show, :id => PRJ_ID
115 assert_response :success
115 assert_response :success
116 assert_template 'show'
116 assert_template 'show'
117 assert_not_nil assigns(:entries)
117 assert_not_nil assigns(:entries)
118 assert_equal 9, assigns(:entries).size
118 assert_equal 9, assigns(:entries).size
119 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
119 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
120 assert assigns(:entries).detect {|e| e.name == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir'}
120 assert assigns(:entries).detect {|e| e.name == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir'}
121 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
121 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
122 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
122 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
123 assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'}
123 assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'}
124 assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'}
124 assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'}
125 assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'}
125 assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'}
126 assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'}
126 assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'}
127 assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'}
127 assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'}
128 assert_not_nil assigns(:changesets)
128 assert_not_nil assigns(:changesets)
129 assert assigns(:changesets).size > 0
129 assert assigns(:changesets).size > 0
130 end
130 end
131
131
132 def test_browse_branch
132 def test_browse_branch
133 assert_equal 0, @repository.changesets.count
133 assert_equal 0, @repository.changesets.count
134 @repository.fetch_changesets
134 @repository.fetch_changesets
135 @project.reload
135 @project.reload
136 assert_equal NUM_REV, @repository.changesets.count
136 assert_equal NUM_REV, @repository.changesets.count
137 get :show, :id => PRJ_ID, :rev => 'test_branch'
137 get :show, :id => PRJ_ID, :rev => 'test_branch'
138 assert_response :success
138 assert_response :success
139 assert_template 'show'
139 assert_template 'show'
140 assert_not_nil assigns(:entries)
140 assert_not_nil assigns(:entries)
141 assert_equal 4, assigns(:entries).size
141 assert_equal 4, assigns(:entries).size
142 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
142 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
143 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
143 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
144 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
144 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
145 assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'}
145 assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'}
146 assert_not_nil assigns(:changesets)
146 assert_not_nil assigns(:changesets)
147 assert assigns(:changesets).size > 0
147 assert assigns(:changesets).size > 0
148 end
148 end
149
149
150 def test_browse_tag
150 def test_browse_tag
151 assert_equal 0, @repository.changesets.count
151 assert_equal 0, @repository.changesets.count
152 @repository.fetch_changesets
152 @repository.fetch_changesets
153 @project.reload
153 @project.reload
154 assert_equal NUM_REV, @repository.changesets.count
154 assert_equal NUM_REV, @repository.changesets.count
155 [
155 [
156 "tag00.lightweight",
156 "tag00.lightweight",
157 "tag01.annotated",
157 "tag01.annotated",
158 ].each do |t1|
158 ].each do |t1|
159 get :show, :id => PRJ_ID, :rev => t1
159 get :show, :id => PRJ_ID, :rev => t1
160 assert_response :success
160 assert_response :success
161 assert_template 'show'
161 assert_template 'show'
162 assert_not_nil assigns(:entries)
162 assert_not_nil assigns(:entries)
163 assert assigns(:entries).size > 0
163 assert assigns(:entries).size > 0
164 assert_not_nil assigns(:changesets)
164 assert_not_nil assigns(:changesets)
165 assert assigns(:changesets).size > 0
165 assert assigns(:changesets).size > 0
166 end
166 end
167 end
167 end
168
168
169 def test_browse_directory
169 def test_browse_directory
170 assert_equal 0, @repository.changesets.count
170 assert_equal 0, @repository.changesets.count
171 @repository.fetch_changesets
171 @repository.fetch_changesets
172 @project.reload
172 @project.reload
173 assert_equal NUM_REV, @repository.changesets.count
173 assert_equal NUM_REV, @repository.changesets.count
174 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param]
174 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param]
175 assert_response :success
175 assert_response :success
176 assert_template 'show'
176 assert_template 'show'
177 assert_not_nil assigns(:entries)
177 assert_not_nil assigns(:entries)
178 assert_equal ['edit.png'], assigns(:entries).collect(&:name)
178 assert_equal ['edit.png'], assigns(:entries).collect(&:name)
179 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
179 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
180 assert_not_nil entry
180 assert_not_nil entry
181 assert_equal 'file', entry.kind
181 assert_equal 'file', entry.kind
182 assert_equal 'images/edit.png', entry.path
182 assert_equal 'images/edit.png', entry.path
183 assert_not_nil assigns(:changesets)
183 assert_not_nil assigns(:changesets)
184 assert assigns(:changesets).size > 0
184 assert assigns(:changesets).size > 0
185 end
185 end
186
186
187 def test_browse_at_given_revision
187 def test_browse_at_given_revision
188 assert_equal 0, @repository.changesets.count
188 assert_equal 0, @repository.changesets.count
189 @repository.fetch_changesets
189 @repository.fetch_changesets
190 @project.reload
190 @project.reload
191 assert_equal NUM_REV, @repository.changesets.count
191 assert_equal NUM_REV, @repository.changesets.count
192 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param],
192 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param],
193 :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
193 :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
194 assert_response :success
194 assert_response :success
195 assert_template 'show'
195 assert_template 'show'
196 assert_not_nil assigns(:entries)
196 assert_not_nil assigns(:entries)
197 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
197 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
198 assert_not_nil assigns(:changesets)
198 assert_not_nil assigns(:changesets)
199 assert assigns(:changesets).size > 0
199 assert assigns(:changesets).size > 0
200 end
200 end
201
201
202 def test_changes
202 def test_changes
203 get :changes, :id => PRJ_ID,
203 get :changes, :id => PRJ_ID,
204 :path => repository_path_hash(['images', 'edit.png'])[:param]
204 :path => repository_path_hash(['images', 'edit.png'])[:param]
205 assert_response :success
205 assert_response :success
206 assert_template 'changes'
206 assert_template 'changes'
207 assert_tag :tag => 'h2', :content => 'edit.png'
207 assert_tag :tag => 'h2', :content => 'edit.png'
208 end
208 end
209
209
210 def test_entry_show
210 def test_entry_show
211 get :entry, :id => PRJ_ID,
211 get :entry, :id => PRJ_ID,
212 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
212 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
213 assert_response :success
213 assert_response :success
214 assert_template 'entry'
214 assert_template 'entry'
215 # Line 19
215 # Line 19
216 assert_tag :tag => 'th',
216 assert_tag :tag => 'th',
217 :content => '11',
217 :content => '11',
218 :attributes => { :class => 'line-num' },
218 :attributes => { :class => 'line-num' },
219 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
219 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
220 end
220 end
221
221
222 def test_entry_show_latin_1
222 def test_entry_show_latin_1
223 if @ruby19_non_utf8_pass
223 if @ruby19_non_utf8_pass
224 puts_ruby19_non_utf8_pass()
224 puts_ruby19_non_utf8_pass()
225 elsif WINDOWS_PASS
225 elsif WINDOWS_PASS
226 puts WINDOWS_SKIP_STR
226 puts WINDOWS_SKIP_STR
227 elsif JRUBY_SKIP
227 elsif JRUBY_SKIP
228 puts JRUBY_SKIP_STR
228 puts JRUBY_SKIP_STR
229 else
229 else
230 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
230 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
231 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
231 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
232 get :entry, :id => PRJ_ID,
232 get :entry, :id => PRJ_ID,
233 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
233 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
234 :rev => r1
234 :rev => r1
235 assert_response :success
235 assert_response :success
236 assert_template 'entry'
236 assert_template 'entry'
237 assert_tag :tag => 'th',
237 assert_tag :tag => 'th',
238 :content => '1',
238 :content => '1',
239 :attributes => { :class => 'line-num' },
239 :attributes => { :class => 'line-num' },
240 :sibling => { :tag => 'td',
240 :sibling => { :tag => 'td',
241 :content => /test-#{@char_1}.txt/ }
241 :content => /test-#{@char_1}.txt/ }
242 end
242 end
243 end
243 end
244 end
244 end
245 end
245 end
246
246
247 def test_entry_download
247 def test_entry_download
248 get :entry, :id => PRJ_ID,
248 get :entry, :id => PRJ_ID,
249 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
249 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
250 :format => 'raw'
250 :format => 'raw'
251 assert_response :success
251 assert_response :success
252 # File content
252 # File content
253 assert @response.body.include?('WITHOUT ANY WARRANTY')
253 assert @response.body.include?('WITHOUT ANY WARRANTY')
254 end
254 end
255
255
256 def test_directory_entry
256 def test_directory_entry
257 get :entry, :id => PRJ_ID,
257 get :entry, :id => PRJ_ID,
258 :path => repository_path_hash(['sources'])[:param]
258 :path => repository_path_hash(['sources'])[:param]
259 assert_response :success
259 assert_response :success
260 assert_template 'show'
260 assert_template 'show'
261 assert_not_nil assigns(:entry)
261 assert_not_nil assigns(:entry)
262 assert_equal 'sources', assigns(:entry).name
262 assert_equal 'sources', assigns(:entry).name
263 end
263 end
264
264
265 def test_diff
265 def test_diff
266 assert_equal 0, @repository.changesets.count
266 assert_equal 0, @repository.changesets.count
267 @repository.fetch_changesets
267 @repository.fetch_changesets
268 @project.reload
268 @project.reload
269 assert_equal NUM_REV, @repository.changesets.count
269 assert_equal NUM_REV, @repository.changesets.count
270 # Full diff of changeset 2f9c0091
270 # Full diff of changeset 2f9c0091
271 ['inline', 'sbs'].each do |dt|
271 ['inline', 'sbs'].each do |dt|
272 get :diff,
272 get :diff,
273 :id => PRJ_ID,
273 :id => PRJ_ID,
274 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
274 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
275 :type => dt
275 :type => dt
276 assert_response :success
276 assert_response :success
277 assert_template 'diff'
277 assert_template 'diff'
278 # Line 22 removed
278 # Line 22 removed
279 assert_tag :tag => 'th',
279 assert_tag :tag => 'th',
280 :content => /22/,
280 :content => /22/,
281 :sibling => { :tag => 'td',
281 :sibling => { :tag => 'td',
282 :attributes => { :class => /diff_out/ },
282 :attributes => { :class => /diff_out/ },
283 :content => /def remove/ }
283 :content => /def remove/ }
284 assert_tag :tag => 'h2', :content => /2f9c0091/
284 assert_tag :tag => 'h2', :content => /2f9c0091/
285 end
285 end
286 end
286 end
287
287
288 def test_diff_truncated
288 def test_diff_truncated
289 assert_equal 0, @repository.changesets.count
289 assert_equal 0, @repository.changesets.count
290 @repository.fetch_changesets
290 @repository.fetch_changesets
291 @project.reload
291 @project.reload
292 assert_equal NUM_REV, @repository.changesets.count
292 assert_equal NUM_REV, @repository.changesets.count
293
293
294 with_settings :diff_max_lines_displayed => 5 do
294 with_settings :diff_max_lines_displayed => 5 do
295 # Truncated diff of changeset 2f9c0091
295 # Truncated diff of changeset 2f9c0091
296 with_cache do
296 with_cache do
297 get :diff, :id => PRJ_ID, :type => 'inline',
297 get :diff, :id => PRJ_ID, :type => 'inline',
298 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
298 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
299 assert_response :success
299 assert_response :success
300 assert @response.body.include?("... This diff was truncated")
300 assert @response.body.include?("... This diff was truncated")
301
301
302 Setting.default_language = 'fr'
302 Setting.default_language = 'fr'
303 get :diff, :id => PRJ_ID, :type => 'inline',
303 get :diff, :id => PRJ_ID, :type => 'inline',
304 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
304 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
305 assert_response :success
305 assert_response :success
306 assert ! @response.body.include?("... This diff was truncated")
306 assert ! @response.body.include?("... This diff was truncated")
307 assert @response.body.include?("... Ce diff")
307 assert @response.body.include?("... Ce diff")
308 end
308 end
309 end
309 end
310 end
310 end
311
311
312 def test_diff_two_revs
312 def test_diff_two_revs
313 assert_equal 0, @repository.changesets.count
313 assert_equal 0, @repository.changesets.count
314 @repository.fetch_changesets
314 @repository.fetch_changesets
315 @project.reload
315 @project.reload
316 assert_equal NUM_REV, @repository.changesets.count
316 assert_equal NUM_REV, @repository.changesets.count
317 ['inline', 'sbs'].each do |dt|
317 ['inline', 'sbs'].each do |dt|
318 get :diff,
318 get :diff,
319 :id => PRJ_ID,
319 :id => PRJ_ID,
320 :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
320 :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
321 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
321 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
322 :type => dt
322 :type => dt
323 assert_response :success
323 assert_response :success
324 assert_template 'diff'
324 assert_template 'diff'
325 diff = assigns(:diff)
325 diff = assigns(:diff)
326 assert_not_nil diff
326 assert_not_nil diff
327 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
327 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
328 end
328 end
329 end
329 end
330
330
331 def test_diff_latin_1
331 def test_diff_latin_1
332 if @ruby19_non_utf8_pass
332 if @ruby19_non_utf8_pass
333 puts_ruby19_non_utf8_pass()
333 puts_ruby19_non_utf8_pass()
334 else
334 else
335 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
335 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
336 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
336 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
337 ['inline', 'sbs'].each do |dt|
337 ['inline', 'sbs'].each do |dt|
338 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
338 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
339 assert_response :success
339 assert_response :success
340 assert_template 'diff'
340 assert_template 'diff'
341 assert_tag :tag => 'thead',
341 assert_tag :tag => 'thead',
342 :descendant => {
342 :descendant => {
343 :tag => 'th',
343 :tag => 'th',
344 :attributes => { :class => 'filename' } ,
344 :attributes => { :class => 'filename' } ,
345 :content => /latin-1-dir\/test-#{@char_1}.txt/ ,
345 :content => /latin-1-dir\/test-#{@char_1}.txt/ ,
346 },
346 },
347 :sibling => {
347 :sibling => {
348 :tag => 'tbody',
348 :tag => 'tbody',
349 :descendant => {
349 :descendant => {
350 :tag => 'td',
350 :tag => 'td',
351 :attributes => { :class => /diff_in/ },
351 :attributes => { :class => /diff_in/ },
352 :content => /test-#{@char_1}.txt/
352 :content => /test-#{@char_1}.txt/
353 }
353 }
354 }
354 }
355 end
355 end
356 end
356 end
357 end
357 end
358 end
358 end
359 end
359 end
360
360
361 def test_save_diff_type
361 def test_save_diff_type
362 @request.session[:user_id] = 1 # admin
362 @request.session[:user_id] = 1 # admin
363 user = User.find(1)
363 user = User.find(1)
364 get :diff,
364 get :diff,
365 :id => PRJ_ID,
365 :id => PRJ_ID,
366 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
366 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
367 assert_response :success
367 assert_response :success
368 assert_template 'diff'
368 assert_template 'diff'
369 user.reload
369 user.reload
370 assert_equal "inline", user.pref[:diff_type]
370 assert_equal "inline", user.pref[:diff_type]
371 get :diff,
371 get :diff,
372 :id => PRJ_ID,
372 :id => PRJ_ID,
373 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
373 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
374 :type => 'sbs'
374 :type => 'sbs'
375 assert_response :success
375 assert_response :success
376 assert_template 'diff'
376 assert_template 'diff'
377 user.reload
377 user.reload
378 assert_equal "sbs", user.pref[:diff_type]
378 assert_equal "sbs", user.pref[:diff_type]
379 end
379 end
380
380
381 def test_annotate
381 def test_annotate
382 get :annotate, :id => PRJ_ID,
382 get :annotate, :id => PRJ_ID,
383 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
383 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
384 assert_response :success
384 assert_response :success
385 assert_template 'annotate'
385 assert_template 'annotate'
386 # Line 24, changeset 2f9c0091
386 # Line 23, changeset 2f9c0091
387 assert_tag :tag => 'th', :content => '24',
387 assert_tag :tag => 'th', :content => '23',
388 :sibling => {
388 :sibling => {
389 :tag => 'td',
389 :tag => 'td',
390 :child => {
390 :child => {
391 :tag => 'a',
391 :tag => 'a',
392 :content => /2f9c0091/
392 :content => /2f9c0091/
393 }
393 }
394 }
394 }
395 assert_tag :tag => 'th', :content => '24',
395 assert_tag :tag => 'th', :content => '23',
396 :sibling => { :tag => 'td', :content => /jsmith/ }
396 :sibling => { :tag => 'td', :content => /jsmith/ }
397 assert_tag :tag => 'th', :content => '24',
397 assert_tag :tag => 'th', :content => '23',
398 :sibling => {
398 :sibling => {
399 :tag => 'td',
399 :tag => 'td',
400 :child => {
400 :child => {
401 :tag => 'a',
401 :tag => 'a',
402 :content => /2f9c0091/
402 :content => /2f9c0091/
403 }
403 }
404 }
404 }
405 assert_tag :tag => 'th', :content => '24',
405 assert_tag :tag => 'th', :content => '23',
406 :sibling => { :tag => 'td', :content => /watcher =/ }
406 :sibling => { :tag => 'td', :content => /remove_watcher/ }
407 end
407 end
408
408
409 def test_annotate_at_given_revision
409 def test_annotate_at_given_revision
410 assert_equal 0, @repository.changesets.count
410 assert_equal 0, @repository.changesets.count
411 @repository.fetch_changesets
411 @repository.fetch_changesets
412 @project.reload
412 @project.reload
413 assert_equal NUM_REV, @repository.changesets.count
413 assert_equal NUM_REV, @repository.changesets.count
414 get :annotate, :id => PRJ_ID, :rev => 'deff7',
414 get :annotate, :id => PRJ_ID, :rev => 'deff7',
415 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
415 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
416 assert_response :success
416 assert_response :success
417 assert_template 'annotate'
417 assert_template 'annotate'
418 assert_tag :tag => 'h2', :content => /@ deff712f/
418 assert_tag :tag => 'h2', :content => /@ deff712f/
419 end
419 end
420
420
421 def test_annotate_binary_file
421 def test_annotate_binary_file
422 get :annotate, :id => PRJ_ID,
422 get :annotate, :id => PRJ_ID,
423 :path => repository_path_hash(['images', 'edit.png'])[:param]
423 :path => repository_path_hash(['images', 'edit.png'])[:param]
424 assert_response 500
424 assert_response 500
425 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
425 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
426 :content => /cannot be annotated/
426 :content => /cannot be annotated/
427 end
427 end
428
428
429 def test_annotate_error_when_too_big
429 def test_annotate_error_when_too_big
430 with_settings :file_max_size_displayed => 1 do
430 with_settings :file_max_size_displayed => 1 do
431 get :annotate, :id => PRJ_ID,
431 get :annotate, :id => PRJ_ID,
432 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
432 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
433 :rev => 'deff712f'
433 :rev => 'deff712f'
434 assert_response 500
434 assert_response 500
435 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
435 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
436 :content => /exceeds the maximum text file size/
436 :content => /exceeds the maximum text file size/
437
437
438 get :annotate, :id => PRJ_ID,
438 get :annotate, :id => PRJ_ID,
439 :path => repository_path_hash(['README'])[:param],
439 :path => repository_path_hash(['README'])[:param],
440 :rev => '7234cb2'
440 :rev => '7234cb2'
441 assert_response :success
441 assert_response :success
442 assert_template 'annotate'
442 assert_template 'annotate'
443 end
443 end
444 end
444 end
445
445
446 def test_annotate_latin_1
446 def test_annotate_latin_1
447 if @ruby19_non_utf8_pass
447 if @ruby19_non_utf8_pass
448 puts_ruby19_non_utf8_pass()
448 puts_ruby19_non_utf8_pass()
449 elsif WINDOWS_PASS
449 elsif WINDOWS_PASS
450 puts WINDOWS_SKIP_STR
450 puts WINDOWS_SKIP_STR
451 elsif JRUBY_SKIP
451 elsif JRUBY_SKIP
452 puts JRUBY_SKIP_STR
452 puts JRUBY_SKIP_STR
453 else
453 else
454 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
454 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
455 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
455 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
456 get :annotate, :id => PRJ_ID,
456 get :annotate, :id => PRJ_ID,
457 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
457 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
458 :rev => r1
458 :rev => r1
459 assert_tag :tag => 'th',
459 assert_tag :tag => 'th',
460 :content => '1',
460 :content => '1',
461 :attributes => { :class => 'line-num' },
461 :attributes => { :class => 'line-num' },
462 :sibling => { :tag => 'td',
462 :sibling => { :tag => 'td',
463 :content => /test-#{@char_1}.txt/ }
463 :content => /test-#{@char_1}.txt/ }
464 end
464 end
465 end
465 end
466 end
466 end
467 end
467 end
468
468
469 def test_revision
469 def test_revision
470 assert_equal 0, @repository.changesets.count
470 assert_equal 0, @repository.changesets.count
471 @repository.fetch_changesets
471 @repository.fetch_changesets
472 @project.reload
472 @project.reload
473 assert_equal NUM_REV, @repository.changesets.count
473 assert_equal NUM_REV, @repository.changesets.count
474 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
474 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
475 get :revision, :id => PRJ_ID, :rev => r
475 get :revision, :id => PRJ_ID, :rev => r
476 assert_response :success
476 assert_response :success
477 assert_template 'revision'
477 assert_template 'revision'
478 end
478 end
479 end
479 end
480
480
481 def test_empty_revision
481 def test_empty_revision
482 assert_equal 0, @repository.changesets.count
482 assert_equal 0, @repository.changesets.count
483 @repository.fetch_changesets
483 @repository.fetch_changesets
484 @project.reload
484 @project.reload
485 assert_equal NUM_REV, @repository.changesets.count
485 assert_equal NUM_REV, @repository.changesets.count
486 ['', ' ', nil].each do |r|
486 ['', ' ', nil].each do |r|
487 get :revision, :id => PRJ_ID, :rev => r
487 get :revision, :id => PRJ_ID, :rev => r
488 assert_response 404
488 assert_response 404
489 assert_error_tag :content => /was not found/
489 assert_error_tag :content => /was not found/
490 end
490 end
491 end
491 end
492
492
493 def test_destroy_valid_repository
493 def test_destroy_valid_repository
494 @request.session[:user_id] = 1 # admin
494 @request.session[:user_id] = 1 # admin
495 assert_equal 0, @repository.changesets.count
495 assert_equal 0, @repository.changesets.count
496 @repository.fetch_changesets
496 @repository.fetch_changesets
497 @project.reload
497 @project.reload
498 assert_equal NUM_REV, @repository.changesets.count
498 assert_equal NUM_REV, @repository.changesets.count
499
499
500 assert_difference 'Repository.count', -1 do
500 assert_difference 'Repository.count', -1 do
501 delete :destroy, :id => @repository.id
501 delete :destroy, :id => @repository.id
502 end
502 end
503 assert_response 302
503 assert_response 302
504 @project.reload
504 @project.reload
505 assert_nil @project.repository
505 assert_nil @project.repository
506 end
506 end
507
507
508 def test_destroy_invalid_repository
508 def test_destroy_invalid_repository
509 @request.session[:user_id] = 1 # admin
509 @request.session[:user_id] = 1 # admin
510 @project.repository.destroy
510 @project.repository.destroy
511 @repository = Repository::Git.create!(
511 @repository = Repository::Git.create!(
512 :project => @project,
512 :project => @project,
513 :url => "/invalid",
513 :url => "/invalid",
514 :path_encoding => 'ISO-8859-1'
514 :path_encoding => 'ISO-8859-1'
515 )
515 )
516 @repository.fetch_changesets
516 @repository.fetch_changesets
517 @repository.reload
517 @repository.reload
518 assert_equal 0, @repository.changesets.count
518 assert_equal 0, @repository.changesets.count
519
519
520 assert_difference 'Repository.count', -1 do
520 assert_difference 'Repository.count', -1 do
521 delete :destroy, :id => @repository.id
521 delete :destroy, :id => @repository.id
522 end
522 end
523 assert_response 302
523 assert_response 302
524 @project.reload
524 @project.reload
525 assert_nil @project.repository
525 assert_nil @project.repository
526 end
526 end
527
527
528 private
528 private
529
529
530 def puts_ruby19_non_utf8_pass
530 def puts_ruby19_non_utf8_pass
531 puts "TODO: This test fails in Ruby 1.9 " +
531 puts "TODO: This test fails in Ruby 1.9 " +
532 "and Encoding.default_external is not UTF-8. " +
532 "and Encoding.default_external is not UTF-8. " +
533 "Current value is '#{Encoding.default_external.to_s}'"
533 "Current value is '#{Encoding.default_external.to_s}'"
534 end
534 end
535 else
535 else
536 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
536 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
537 def test_fake; assert true end
537 def test_fake; assert true end
538 end
538 end
539
539
540 private
540 private
541 def with_cache(&block)
541 def with_cache(&block)
542 before = ActionController::Base.perform_caching
542 before = ActionController::Base.perform_caching
543 ActionController::Base.perform_caching = true
543 ActionController::Base.perform_caching = true
544 block.call
544 block.call
545 ActionController::Base.perform_caching = before
545 ActionController::Base.perform_caching = before
546 end
546 end
547 end
547 end
@@ -1,526 +1,526
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
2 # Copyright (C) 2006-2012 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 RepositoriesMercurialControllerTest < ActionController::TestCase
20 class RepositoriesMercurialControllerTest < ActionController::TestCase
21 tests RepositoriesController
21 tests RepositoriesController
22
22
23 fixtures :projects, :users, :roles, :members, :member_roles,
23 fixtures :projects, :users, :roles, :members, :member_roles,
24 :repositories, :enabled_modules
24 :repositories, :enabled_modules
25
25
26 REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s
26 REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s
27 CHAR_1_HEX = "\xc3\x9c"
27 CHAR_1_HEX = "\xc3\x9c"
28 PRJ_ID = 3
28 PRJ_ID = 3
29 NUM_REV = 32
29 NUM_REV = 32
30
30
31 ruby19_non_utf8_pass =
31 ruby19_non_utf8_pass =
32 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
32 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
33
33
34 def setup
34 def setup
35 User.current = nil
35 User.current = nil
36 @project = Project.find(PRJ_ID)
36 @project = Project.find(PRJ_ID)
37 @repository = Repository::Mercurial.create(
37 @repository = Repository::Mercurial.create(
38 :project => @project,
38 :project => @project,
39 :url => REPOSITORY_PATH,
39 :url => REPOSITORY_PATH,
40 :path_encoding => 'ISO-8859-1'
40 :path_encoding => 'ISO-8859-1'
41 )
41 )
42 assert @repository
42 assert @repository
43 @diff_c_support = true
43 @diff_c_support = true
44 @char_1 = CHAR_1_HEX.dup
44 @char_1 = CHAR_1_HEX.dup
45 @tag_char_1 = "tag-#{CHAR_1_HEX}-00"
45 @tag_char_1 = "tag-#{CHAR_1_HEX}-00"
46 @branch_char_0 = "branch-#{CHAR_1_HEX}-00"
46 @branch_char_0 = "branch-#{CHAR_1_HEX}-00"
47 @branch_char_1 = "branch-#{CHAR_1_HEX}-01"
47 @branch_char_1 = "branch-#{CHAR_1_HEX}-01"
48 if @char_1.respond_to?(:force_encoding)
48 if @char_1.respond_to?(:force_encoding)
49 @char_1.force_encoding('UTF-8')
49 @char_1.force_encoding('UTF-8')
50 @tag_char_1.force_encoding('UTF-8')
50 @tag_char_1.force_encoding('UTF-8')
51 @branch_char_0.force_encoding('UTF-8')
51 @branch_char_0.force_encoding('UTF-8')
52 @branch_char_1.force_encoding('UTF-8')
52 @branch_char_1.force_encoding('UTF-8')
53 end
53 end
54 end
54 end
55
55
56 if ruby19_non_utf8_pass
56 if ruby19_non_utf8_pass
57 puts "TODO: Mercurial functional test fails in Ruby 1.9 " +
57 puts "TODO: Mercurial functional test fails in Ruby 1.9 " +
58 "and Encoding.default_external is not UTF-8. " +
58 "and Encoding.default_external is not UTF-8. " +
59 "Current value is '#{Encoding.default_external.to_s}'"
59 "Current value is '#{Encoding.default_external.to_s}'"
60 def test_fake; assert true end
60 def test_fake; assert true end
61 elsif File.directory?(REPOSITORY_PATH)
61 elsif File.directory?(REPOSITORY_PATH)
62
62
63 def test_get_new
63 def test_get_new
64 @request.session[:user_id] = 1
64 @request.session[:user_id] = 1
65 @project.repository.destroy
65 @project.repository.destroy
66 get :new, :project_id => 'subproject1', :repository_scm => 'Mercurial'
66 get :new, :project_id => 'subproject1', :repository_scm => 'Mercurial'
67 assert_response :success
67 assert_response :success
68 assert_template 'new'
68 assert_template 'new'
69 assert_kind_of Repository::Mercurial, assigns(:repository)
69 assert_kind_of Repository::Mercurial, assigns(:repository)
70 assert assigns(:repository).new_record?
70 assert assigns(:repository).new_record?
71 end
71 end
72
72
73 def test_show_root
73 def test_show_root
74 assert_equal 0, @repository.changesets.count
74 assert_equal 0, @repository.changesets.count
75 @repository.fetch_changesets
75 @repository.fetch_changesets
76 @project.reload
76 @project.reload
77 assert_equal NUM_REV, @repository.changesets.count
77 assert_equal NUM_REV, @repository.changesets.count
78 get :show, :id => PRJ_ID
78 get :show, :id => PRJ_ID
79 assert_response :success
79 assert_response :success
80 assert_template 'show'
80 assert_template 'show'
81 assert_not_nil assigns(:entries)
81 assert_not_nil assigns(:entries)
82 assert_equal 4, assigns(:entries).size
82 assert_equal 4, assigns(:entries).size
83 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
83 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
84 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
84 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
85 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
85 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
86 assert_not_nil assigns(:changesets)
86 assert_not_nil assigns(:changesets)
87 assert assigns(:changesets).size > 0
87 assert assigns(:changesets).size > 0
88 end
88 end
89
89
90 def test_show_directory
90 def test_show_directory
91 assert_equal 0, @repository.changesets.count
91 assert_equal 0, @repository.changesets.count
92 @repository.fetch_changesets
92 @repository.fetch_changesets
93 @project.reload
93 @project.reload
94 assert_equal NUM_REV, @repository.changesets.count
94 assert_equal NUM_REV, @repository.changesets.count
95 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param]
95 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param]
96 assert_response :success
96 assert_response :success
97 assert_template 'show'
97 assert_template 'show'
98 assert_not_nil assigns(:entries)
98 assert_not_nil assigns(:entries)
99 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
99 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
100 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
100 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
101 assert_not_nil entry
101 assert_not_nil entry
102 assert_equal 'file', entry.kind
102 assert_equal 'file', entry.kind
103 assert_equal 'images/edit.png', entry.path
103 assert_equal 'images/edit.png', entry.path
104 assert_not_nil assigns(:changesets)
104 assert_not_nil assigns(:changesets)
105 assert assigns(:changesets).size > 0
105 assert assigns(:changesets).size > 0
106 end
106 end
107
107
108 def test_show_at_given_revision
108 def test_show_at_given_revision
109 assert_equal 0, @repository.changesets.count
109 assert_equal 0, @repository.changesets.count
110 @repository.fetch_changesets
110 @repository.fetch_changesets
111 @project.reload
111 @project.reload
112 assert_equal NUM_REV, @repository.changesets.count
112 assert_equal NUM_REV, @repository.changesets.count
113 [0, '0', '0885933ad4f6'].each do |r1|
113 [0, '0', '0885933ad4f6'].each do |r1|
114 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param],
114 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param],
115 :rev => r1
115 :rev => r1
116 assert_response :success
116 assert_response :success
117 assert_template 'show'
117 assert_template 'show'
118 assert_not_nil assigns(:entries)
118 assert_not_nil assigns(:entries)
119 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
119 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
120 assert_not_nil assigns(:changesets)
120 assert_not_nil assigns(:changesets)
121 assert assigns(:changesets).size > 0
121 assert assigns(:changesets).size > 0
122 end
122 end
123 end
123 end
124
124
125 def test_show_directory_sql_escape_percent
125 def test_show_directory_sql_escape_percent
126 assert_equal 0, @repository.changesets.count
126 assert_equal 0, @repository.changesets.count
127 @repository.fetch_changesets
127 @repository.fetch_changesets
128 @project.reload
128 @project.reload
129 assert_equal NUM_REV, @repository.changesets.count
129 assert_equal NUM_REV, @repository.changesets.count
130 [13, '13', '3a330eb32958'].each do |r1|
130 [13, '13', '3a330eb32958'].each do |r1|
131 get :show, :id => PRJ_ID,
131 get :show, :id => PRJ_ID,
132 :path => repository_path_hash(['sql_escape', 'percent%dir'])[:param],
132 :path => repository_path_hash(['sql_escape', 'percent%dir'])[:param],
133 :rev => r1
133 :rev => r1
134 assert_response :success
134 assert_response :success
135 assert_template 'show'
135 assert_template 'show'
136
136
137 assert_not_nil assigns(:entries)
137 assert_not_nil assigns(:entries)
138 assert_equal ['percent%file1.txt', 'percentfile1.txt'],
138 assert_equal ['percent%file1.txt', 'percentfile1.txt'],
139 assigns(:entries).collect(&:name)
139 assigns(:entries).collect(&:name)
140 changesets = assigns(:changesets)
140 changesets = assigns(:changesets)
141 assert_not_nil changesets
141 assert_not_nil changesets
142 assert assigns(:changesets).size > 0
142 assert assigns(:changesets).size > 0
143 assert_equal %w(13 11 10 9), changesets.collect(&:revision)
143 assert_equal %w(13 11 10 9), changesets.collect(&:revision)
144 end
144 end
145 end
145 end
146
146
147 def test_show_directory_latin_1_path
147 def test_show_directory_latin_1_path
148 assert_equal 0, @repository.changesets.count
148 assert_equal 0, @repository.changesets.count
149 @repository.fetch_changesets
149 @repository.fetch_changesets
150 @project.reload
150 @project.reload
151 assert_equal NUM_REV, @repository.changesets.count
151 assert_equal NUM_REV, @repository.changesets.count
152 [21, '21', 'adf805632193'].each do |r1|
152 [21, '21', 'adf805632193'].each do |r1|
153 get :show, :id => PRJ_ID,
153 get :show, :id => PRJ_ID,
154 :path => repository_path_hash(['latin-1-dir'])[:param],
154 :path => repository_path_hash(['latin-1-dir'])[:param],
155 :rev => r1
155 :rev => r1
156 assert_response :success
156 assert_response :success
157 assert_template 'show'
157 assert_template 'show'
158
158
159 assert_not_nil assigns(:entries)
159 assert_not_nil assigns(:entries)
160 assert_equal ["make-latin-1-file.rb",
160 assert_equal ["make-latin-1-file.rb",
161 "test-#{@char_1}-1.txt",
161 "test-#{@char_1}-1.txt",
162 "test-#{@char_1}-2.txt",
162 "test-#{@char_1}-2.txt",
163 "test-#{@char_1}.txt"], assigns(:entries).collect(&:name)
163 "test-#{@char_1}.txt"], assigns(:entries).collect(&:name)
164 changesets = assigns(:changesets)
164 changesets = assigns(:changesets)
165 assert_not_nil changesets
165 assert_not_nil changesets
166 assert_equal %w(21 20 19 18 17), changesets.collect(&:revision)
166 assert_equal %w(21 20 19 18 17), changesets.collect(&:revision)
167 end
167 end
168 end
168 end
169
169
170 def show_should_show_branch_selection_form
170 def show_should_show_branch_selection_form
171 @repository.fetch_changesets
171 @repository.fetch_changesets
172 @project.reload
172 @project.reload
173 get :show, :id => PRJ_ID
173 get :show, :id => PRJ_ID
174 assert_tag 'form', :attributes => {:id => 'revision_selector', :action => '/projects/subproject1/repository/show'}
174 assert_tag 'form', :attributes => {:id => 'revision_selector', :action => '/projects/subproject1/repository/show'}
175 assert_tag 'select', :attributes => {:name => 'branch'},
175 assert_tag 'select', :attributes => {:name => 'branch'},
176 :child => {:tag => 'option', :attributes => {:value => 'test-branch-01'}},
176 :child => {:tag => 'option', :attributes => {:value => 'test-branch-01'}},
177 :parent => {:tag => 'form', :attributes => {:id => 'revision_selector'}}
177 :parent => {:tag => 'form', :attributes => {:id => 'revision_selector'}}
178 end
178 end
179
179
180 def test_show_branch
180 def test_show_branch
181 assert_equal 0, @repository.changesets.count
181 assert_equal 0, @repository.changesets.count
182 @repository.fetch_changesets
182 @repository.fetch_changesets
183 @project.reload
183 @project.reload
184 assert_equal NUM_REV, @repository.changesets.count
184 assert_equal NUM_REV, @repository.changesets.count
185 [
185 [
186 'default',
186 'default',
187 @branch_char_1,
187 @branch_char_1,
188 'branch (1)[2]&,%.-3_4',
188 'branch (1)[2]&,%.-3_4',
189 @branch_char_0,
189 @branch_char_0,
190 'test_branch.latin-1',
190 'test_branch.latin-1',
191 'test-branch-00',
191 'test-branch-00',
192 ].each do |bra|
192 ].each do |bra|
193 get :show, :id => PRJ_ID, :rev => bra
193 get :show, :id => PRJ_ID, :rev => bra
194 assert_response :success
194 assert_response :success
195 assert_template 'show'
195 assert_template 'show'
196 assert_not_nil assigns(:entries)
196 assert_not_nil assigns(:entries)
197 assert assigns(:entries).size > 0
197 assert assigns(:entries).size > 0
198 assert_not_nil assigns(:changesets)
198 assert_not_nil assigns(:changesets)
199 assert assigns(:changesets).size > 0
199 assert assigns(:changesets).size > 0
200 end
200 end
201 end
201 end
202
202
203 def test_show_tag
203 def test_show_tag
204 assert_equal 0, @repository.changesets.count
204 assert_equal 0, @repository.changesets.count
205 @repository.fetch_changesets
205 @repository.fetch_changesets
206 @project.reload
206 @project.reload
207 assert_equal NUM_REV, @repository.changesets.count
207 assert_equal NUM_REV, @repository.changesets.count
208 [
208 [
209 @tag_char_1,
209 @tag_char_1,
210 'tag_test.00',
210 'tag_test.00',
211 'tag-init-revision'
211 'tag-init-revision'
212 ].each do |tag|
212 ].each do |tag|
213 get :show, :id => PRJ_ID, :rev => tag
213 get :show, :id => PRJ_ID, :rev => tag
214 assert_response :success
214 assert_response :success
215 assert_template 'show'
215 assert_template 'show'
216 assert_not_nil assigns(:entries)
216 assert_not_nil assigns(:entries)
217 assert assigns(:entries).size > 0
217 assert assigns(:entries).size > 0
218 assert_not_nil assigns(:changesets)
218 assert_not_nil assigns(:changesets)
219 assert assigns(:changesets).size > 0
219 assert assigns(:changesets).size > 0
220 end
220 end
221 end
221 end
222
222
223 def test_changes
223 def test_changes
224 get :changes, :id => PRJ_ID,
224 get :changes, :id => PRJ_ID,
225 :path => repository_path_hash(['images', 'edit.png'])[:param]
225 :path => repository_path_hash(['images', 'edit.png'])[:param]
226 assert_response :success
226 assert_response :success
227 assert_template 'changes'
227 assert_template 'changes'
228 assert_tag :tag => 'h2', :content => 'edit.png'
228 assert_tag :tag => 'h2', :content => 'edit.png'
229 end
229 end
230
230
231 def test_entry_show
231 def test_entry_show
232 get :entry, :id => PRJ_ID,
232 get :entry, :id => PRJ_ID,
233 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
233 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
234 assert_response :success
234 assert_response :success
235 assert_template 'entry'
235 assert_template 'entry'
236 # Line 10
236 # Line 10
237 assert_tag :tag => 'th',
237 assert_tag :tag => 'th',
238 :content => '10',
238 :content => '10',
239 :attributes => { :class => 'line-num' },
239 :attributes => { :class => 'line-num' },
240 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
240 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
241 end
241 end
242
242
243 def test_entry_show_latin_1_path
243 def test_entry_show_latin_1_path
244 [21, '21', 'adf805632193'].each do |r1|
244 [21, '21', 'adf805632193'].each do |r1|
245 get :entry, :id => PRJ_ID,
245 get :entry, :id => PRJ_ID,
246 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}-2.txt"])[:param],
246 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}-2.txt"])[:param],
247 :rev => r1
247 :rev => r1
248 assert_response :success
248 assert_response :success
249 assert_template 'entry'
249 assert_template 'entry'
250 assert_tag :tag => 'th',
250 assert_tag :tag => 'th',
251 :content => '1',
251 :content => '1',
252 :attributes => { :class => 'line-num' },
252 :attributes => { :class => 'line-num' },
253 :sibling => { :tag => 'td',
253 :sibling => { :tag => 'td',
254 :content => /Mercurial is a distributed version control system/ }
254 :content => /Mercurial is a distributed version control system/ }
255 end
255 end
256 end
256 end
257
257
258 def test_entry_show_latin_1_contents
258 def test_entry_show_latin_1_contents
259 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
259 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
260 [27, '27', '7bbf4c738e71'].each do |r1|
260 [27, '27', '7bbf4c738e71'].each do |r1|
261 get :entry, :id => PRJ_ID,
261 get :entry, :id => PRJ_ID,
262 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
262 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
263 :rev => r1
263 :rev => r1
264 assert_response :success
264 assert_response :success
265 assert_template 'entry'
265 assert_template 'entry'
266 assert_tag :tag => 'th',
266 assert_tag :tag => 'th',
267 :content => '1',
267 :content => '1',
268 :attributes => { :class => 'line-num' },
268 :attributes => { :class => 'line-num' },
269 :sibling => { :tag => 'td',
269 :sibling => { :tag => 'td',
270 :content => /test-#{@char_1}.txt/ }
270 :content => /test-#{@char_1}.txt/ }
271 end
271 end
272 end
272 end
273 end
273 end
274
274
275 def test_entry_download
275 def test_entry_download
276 get :entry, :id => PRJ_ID,
276 get :entry, :id => PRJ_ID,
277 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
277 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
278 :format => 'raw'
278 :format => 'raw'
279 assert_response :success
279 assert_response :success
280 # File content
280 # File content
281 assert @response.body.include?('WITHOUT ANY WARRANTY')
281 assert @response.body.include?('WITHOUT ANY WARRANTY')
282 end
282 end
283
283
284 def test_entry_binary_force_download
284 def test_entry_binary_force_download
285 get :entry, :id => PRJ_ID, :rev => 1,
285 get :entry, :id => PRJ_ID, :rev => 1,
286 :path => repository_path_hash(['images', 'edit.png'])[:param]
286 :path => repository_path_hash(['images', 'edit.png'])[:param]
287 assert_response :success
287 assert_response :success
288 assert_equal 'image/png', @response.content_type
288 assert_equal 'image/png', @response.content_type
289 end
289 end
290
290
291 def test_directory_entry
291 def test_directory_entry
292 get :entry, :id => PRJ_ID,
292 get :entry, :id => PRJ_ID,
293 :path => repository_path_hash(['sources'])[:param]
293 :path => repository_path_hash(['sources'])[:param]
294 assert_response :success
294 assert_response :success
295 assert_template 'show'
295 assert_template 'show'
296 assert_not_nil assigns(:entry)
296 assert_not_nil assigns(:entry)
297 assert_equal 'sources', assigns(:entry).name
297 assert_equal 'sources', assigns(:entry).name
298 end
298 end
299
299
300 def test_diff
300 def test_diff
301 assert_equal 0, @repository.changesets.count
301 assert_equal 0, @repository.changesets.count
302 @repository.fetch_changesets
302 @repository.fetch_changesets
303 @project.reload
303 @project.reload
304 assert_equal NUM_REV, @repository.changesets.count
304 assert_equal NUM_REV, @repository.changesets.count
305 [4, '4', 'def6d2f1254a'].each do |r1|
305 [4, '4', 'def6d2f1254a'].each do |r1|
306 # Full diff of changeset 4
306 # Full diff of changeset 4
307 ['inline', 'sbs'].each do |dt|
307 ['inline', 'sbs'].each do |dt|
308 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
308 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
309 assert_response :success
309 assert_response :success
310 assert_template 'diff'
310 assert_template 'diff'
311 if @diff_c_support
311 if @diff_c_support
312 # Line 22 removed
312 # Line 22 removed
313 assert_tag :tag => 'th',
313 assert_tag :tag => 'th',
314 :content => '22',
314 :content => '22',
315 :sibling => { :tag => 'td',
315 :sibling => { :tag => 'td',
316 :attributes => { :class => /diff_out/ },
316 :attributes => { :class => /diff_out/ },
317 :content => /def remove/ }
317 :content => /def remove/ }
318 assert_tag :tag => 'h2', :content => /4:def6d2f1254a/
318 assert_tag :tag => 'h2', :content => /4:def6d2f1254a/
319 end
319 end
320 end
320 end
321 end
321 end
322 end
322 end
323
323
324 def test_diff_two_revs
324 def test_diff_two_revs
325 assert_equal 0, @repository.changesets.count
325 assert_equal 0, @repository.changesets.count
326 @repository.fetch_changesets
326 @repository.fetch_changesets
327 @project.reload
327 @project.reload
328 assert_equal NUM_REV, @repository.changesets.count
328 assert_equal NUM_REV, @repository.changesets.count
329 [2, '400bb8672109', '400', 400].each do |r1|
329 [2, '400bb8672109', '400', 400].each do |r1|
330 [4, 'def6d2f1254a'].each do |r2|
330 [4, 'def6d2f1254a'].each do |r2|
331 ['inline', 'sbs'].each do |dt|
331 ['inline', 'sbs'].each do |dt|
332 get :diff,
332 get :diff,
333 :id => PRJ_ID,
333 :id => PRJ_ID,
334 :rev => r1,
334 :rev => r1,
335 :rev_to => r2,
335 :rev_to => r2,
336 :type => dt
336 :type => dt
337 assert_response :success
337 assert_response :success
338 assert_template 'diff'
338 assert_template 'diff'
339 diff = assigns(:diff)
339 diff = assigns(:diff)
340 assert_not_nil diff
340 assert_not_nil diff
341 assert_tag :tag => 'h2',
341 assert_tag :tag => 'h2',
342 :content => /4:def6d2f1254a 2:400bb8672109/
342 :content => /4:def6d2f1254a 2:400bb8672109/
343 end
343 end
344 end
344 end
345 end
345 end
346 end
346 end
347
347
348 def test_diff_latin_1_path
348 def test_diff_latin_1_path
349 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
349 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
350 [21, 'adf805632193'].each do |r1|
350 [21, 'adf805632193'].each do |r1|
351 ['inline', 'sbs'].each do |dt|
351 ['inline', 'sbs'].each do |dt|
352 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
352 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
353 assert_response :success
353 assert_response :success
354 assert_template 'diff'
354 assert_template 'diff'
355 assert_tag :tag => 'thead',
355 assert_tag :tag => 'thead',
356 :descendant => {
356 :descendant => {
357 :tag => 'th',
357 :tag => 'th',
358 :attributes => { :class => 'filename' } ,
358 :attributes => { :class => 'filename' } ,
359 :content => /latin-1-dir\/test-#{@char_1}-2.txt/ ,
359 :content => /latin-1-dir\/test-#{@char_1}-2.txt/ ,
360 },
360 },
361 :sibling => {
361 :sibling => {
362 :tag => 'tbody',
362 :tag => 'tbody',
363 :descendant => {
363 :descendant => {
364 :tag => 'td',
364 :tag => 'td',
365 :attributes => { :class => /diff_in/ },
365 :attributes => { :class => /diff_in/ },
366 :content => /It is written in Python/
366 :content => /It is written in Python/
367 }
367 }
368 }
368 }
369 end
369 end
370 end
370 end
371 end
371 end
372 end
372 end
373
373
374 def test_annotate
374 def test_annotate
375 get :annotate, :id => PRJ_ID,
375 get :annotate, :id => PRJ_ID,
376 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
376 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
377 assert_response :success
377 assert_response :success
378 assert_template 'annotate'
378 assert_template 'annotate'
379 # Line 23, revision 4:def6d2f1254a
379 # Line 22, revision 4:def6d2f1254a
380 assert_tag :tag => 'th',
380 assert_tag :tag => 'th',
381 :content => '23',
381 :content => '22',
382 :attributes => { :class => 'line-num' },
382 :attributes => { :class => 'line-num' },
383 :sibling =>
383 :sibling =>
384 {
384 {
385 :tag => 'td',
385 :tag => 'td',
386 :attributes => { :class => 'revision' },
386 :attributes => { :class => 'revision' },
387 :child => { :tag => 'a', :content => '4:def6d2f1254a' }
387 :child => { :tag => 'a', :content => '4:def6d2f1254a' }
388 }
388 }
389 assert_tag :tag => 'th',
389 assert_tag :tag => 'th',
390 :content => '23',
390 :content => '22',
391 :attributes => { :class => 'line-num' },
391 :attributes => { :class => 'line-num' },
392 :sibling =>
392 :sibling =>
393 {
393 {
394 :tag => 'td' ,
394 :tag => 'td' ,
395 :content => 'jsmith' ,
395 :content => 'jsmith' ,
396 :attributes => { :class => 'author' },
396 :attributes => { :class => 'author' },
397 }
397 }
398 assert_tag :tag => 'th',
398 assert_tag :tag => 'th',
399 :content => '23',
399 :content => '22',
400 :attributes => { :class => 'line-num' },
400 :attributes => { :class => 'line-num' },
401 :sibling => { :tag => 'td', :content => /watcher =/ }
401 :sibling => { :tag => 'td', :content => /remove_watcher/ }
402 end
402 end
403
403
404 def test_annotate_not_in_tip
404 def test_annotate_not_in_tip
405 assert_equal 0, @repository.changesets.count
405 assert_equal 0, @repository.changesets.count
406 @repository.fetch_changesets
406 @repository.fetch_changesets
407 @project.reload
407 @project.reload
408 assert_equal NUM_REV, @repository.changesets.count
408 assert_equal NUM_REV, @repository.changesets.count
409 get :annotate, :id => PRJ_ID,
409 get :annotate, :id => PRJ_ID,
410 :path => repository_path_hash(['sources', 'welcome_controller.rb'])[:param]
410 :path => repository_path_hash(['sources', 'welcome_controller.rb'])[:param]
411 assert_response 404
411 assert_response 404
412 assert_error_tag :content => /was not found/
412 assert_error_tag :content => /was not found/
413 end
413 end
414
414
415 def test_annotate_at_given_revision
415 def test_annotate_at_given_revision
416 assert_equal 0, @repository.changesets.count
416 assert_equal 0, @repository.changesets.count
417 @repository.fetch_changesets
417 @repository.fetch_changesets
418 @project.reload
418 @project.reload
419 assert_equal NUM_REV, @repository.changesets.count
419 assert_equal NUM_REV, @repository.changesets.count
420 [2, '400bb8672109', '400', 400].each do |r1|
420 [2, '400bb8672109', '400', 400].each do |r1|
421 get :annotate, :id => PRJ_ID, :rev => r1,
421 get :annotate, :id => PRJ_ID, :rev => r1,
422 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
422 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
423 assert_response :success
423 assert_response :success
424 assert_template 'annotate'
424 assert_template 'annotate'
425 assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/
425 assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/
426 end
426 end
427 end
427 end
428
428
429 def test_annotate_latin_1_path
429 def test_annotate_latin_1_path
430 [21, '21', 'adf805632193'].each do |r1|
430 [21, '21', 'adf805632193'].each do |r1|
431 get :annotate, :id => PRJ_ID,
431 get :annotate, :id => PRJ_ID,
432 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}-2.txt"])[:param],
432 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}-2.txt"])[:param],
433 :rev => r1
433 :rev => r1
434 assert_response :success
434 assert_response :success
435 assert_template 'annotate'
435 assert_template 'annotate'
436 assert_tag :tag => 'th',
436 assert_tag :tag => 'th',
437 :content => '1',
437 :content => '1',
438 :attributes => { :class => 'line-num' },
438 :attributes => { :class => 'line-num' },
439 :sibling =>
439 :sibling =>
440 {
440 {
441 :tag => 'td',
441 :tag => 'td',
442 :attributes => { :class => 'revision' },
442 :attributes => { :class => 'revision' },
443 :child => { :tag => 'a', :content => '20:709858aafd1b' }
443 :child => { :tag => 'a', :content => '20:709858aafd1b' }
444 }
444 }
445 assert_tag :tag => 'th',
445 assert_tag :tag => 'th',
446 :content => '1',
446 :content => '1',
447 :attributes => { :class => 'line-num' },
447 :attributes => { :class => 'line-num' },
448 :sibling =>
448 :sibling =>
449 {
449 {
450 :tag => 'td' ,
450 :tag => 'td' ,
451 :content => 'jsmith' ,
451 :content => 'jsmith' ,
452 :attributes => { :class => 'author' },
452 :attributes => { :class => 'author' },
453 }
453 }
454 assert_tag :tag => 'th',
454 assert_tag :tag => 'th',
455 :content => '1',
455 :content => '1',
456 :attributes => { :class => 'line-num' },
456 :attributes => { :class => 'line-num' },
457 :sibling => { :tag => 'td',
457 :sibling => { :tag => 'td',
458 :content => /Mercurial is a distributed version control system/ }
458 :content => /Mercurial is a distributed version control system/ }
459
459
460 end
460 end
461 end
461 end
462
462
463 def test_annotate_latin_1_contents
463 def test_annotate_latin_1_contents
464 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
464 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
465 [27, '7bbf4c738e71'].each do |r1|
465 [27, '7bbf4c738e71'].each do |r1|
466 get :annotate, :id => PRJ_ID,
466 get :annotate, :id => PRJ_ID,
467 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
467 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
468 :rev => r1
468 :rev => r1
469 assert_tag :tag => 'th',
469 assert_tag :tag => 'th',
470 :content => '1',
470 :content => '1',
471 :attributes => { :class => 'line-num' },
471 :attributes => { :class => 'line-num' },
472 :sibling => { :tag => 'td',
472 :sibling => { :tag => 'td',
473 :content => /test-#{@char_1}.txt/ }
473 :content => /test-#{@char_1}.txt/ }
474 end
474 end
475 end
475 end
476 end
476 end
477
477
478 def test_empty_revision
478 def test_empty_revision
479 assert_equal 0, @repository.changesets.count
479 assert_equal 0, @repository.changesets.count
480 @repository.fetch_changesets
480 @repository.fetch_changesets
481 @project.reload
481 @project.reload
482 assert_equal NUM_REV, @repository.changesets.count
482 assert_equal NUM_REV, @repository.changesets.count
483 ['', ' ', nil].each do |r|
483 ['', ' ', nil].each do |r|
484 get :revision, :id => PRJ_ID, :rev => r
484 get :revision, :id => PRJ_ID, :rev => r
485 assert_response 404
485 assert_response 404
486 assert_error_tag :content => /was not found/
486 assert_error_tag :content => /was not found/
487 end
487 end
488 end
488 end
489
489
490 def test_destroy_valid_repository
490 def test_destroy_valid_repository
491 @request.session[:user_id] = 1 # admin
491 @request.session[:user_id] = 1 # admin
492 assert_equal 0, @repository.changesets.count
492 assert_equal 0, @repository.changesets.count
493 @repository.fetch_changesets
493 @repository.fetch_changesets
494 assert_equal NUM_REV, @repository.changesets.count
494 assert_equal NUM_REV, @repository.changesets.count
495
495
496 assert_difference 'Repository.count', -1 do
496 assert_difference 'Repository.count', -1 do
497 delete :destroy, :id => @repository.id
497 delete :destroy, :id => @repository.id
498 end
498 end
499 assert_response 302
499 assert_response 302
500 @project.reload
500 @project.reload
501 assert_nil @project.repository
501 assert_nil @project.repository
502 end
502 end
503
503
504 def test_destroy_invalid_repository
504 def test_destroy_invalid_repository
505 @request.session[:user_id] = 1 # admin
505 @request.session[:user_id] = 1 # admin
506 @project.repository.destroy
506 @project.repository.destroy
507 @repository = Repository::Mercurial.create!(
507 @repository = Repository::Mercurial.create!(
508 :project => Project.find(PRJ_ID),
508 :project => Project.find(PRJ_ID),
509 :url => "/invalid",
509 :url => "/invalid",
510 :path_encoding => 'ISO-8859-1'
510 :path_encoding => 'ISO-8859-1'
511 )
511 )
512 @repository.fetch_changesets
512 @repository.fetch_changesets
513 assert_equal 0, @repository.changesets.count
513 assert_equal 0, @repository.changesets.count
514
514
515 assert_difference 'Repository.count', -1 do
515 assert_difference 'Repository.count', -1 do
516 delete :destroy, :id => @repository.id
516 delete :destroy, :id => @repository.id
517 end
517 end
518 assert_response 302
518 assert_response 302
519 @project.reload
519 @project.reload
520 assert_nil @project.repository
520 assert_nil @project.repository
521 end
521 end
522 else
522 else
523 puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
523 puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
524 def test_fake; assert true end
524 def test_fake; assert true end
525 end
525 end
526 end
526 end
General Comments 0
You need to be logged in to leave comments. Login now