##// END OF EJS Templates
Inline images alt attribute set to the attachment description....
Jean-Philippe Lang -
r1313:c37abb64151e
parent child
Show More
@@ -1,504 +1,506
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 module ApplicationHelper
19 19 include Redmine::WikiFormatting::Macros::Definitions
20 20
21 21 def current_role
22 22 @current_role ||= User.current.role_for_project(@project)
23 23 end
24 24
25 25 # Return true if user is authorized for controller/action, otherwise false
26 26 def authorize_for(controller, action)
27 27 User.current.allowed_to?({:controller => controller, :action => action}, @project)
28 28 end
29 29
30 30 # Display a link if user is authorized
31 31 def link_to_if_authorized(name, options = {}, html_options = nil, *parameters_for_method_reference)
32 32 link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller] || params[:controller], options[:action])
33 33 end
34 34
35 35 # Display a link to user's account page
36 36 def link_to_user(user)
37 37 user ? link_to(user, :controller => 'account', :action => 'show', :id => user) : 'Anonymous'
38 38 end
39 39
40 40 def link_to_issue(issue, options={})
41 41 link_to "#{issue.tracker.name} ##{issue.id}", {:controller => "issues", :action => "show", :id => issue}, options
42 42 end
43 43
44 44 def toggle_link(name, id, options={})
45 45 onclick = "Element.toggle('#{id}'); "
46 46 onclick << (options[:focus] ? "Form.Element.focus('#{options[:focus]}'); " : "this.blur(); ")
47 47 onclick << "return false;"
48 48 link_to(name, "#", :onclick => onclick)
49 49 end
50 50
51 51 def show_and_goto_link(name, id, options={})
52 52 onclick = "Element.show('#{id}'); "
53 53 onclick << (options[:focus] ? "Form.Element.focus('#{options[:focus]}'); " : "this.blur(); ")
54 54 onclick << "Element.scrollTo('#{id}'); "
55 55 onclick << "return false;"
56 56 link_to(name, "#", options.merge(:onclick => onclick))
57 57 end
58 58
59 59 def image_to_function(name, function, html_options = {})
60 60 html_options.symbolize_keys!
61 61 tag(:input, html_options.merge({
62 62 :type => "image", :src => image_path(name),
63 63 :onclick => (html_options[:onclick] ? "#{html_options[:onclick]}; " : "") + "#{function};"
64 64 }))
65 65 end
66 66
67 67 def prompt_to_remote(name, text, param, url, html_options = {})
68 68 html_options[:onclick] = "promptToRemote('#{text}', '#{param}', '#{url_for(url)}'); return false;"
69 69 link_to name, {}, html_options
70 70 end
71 71
72 72 def format_date(date)
73 73 return nil unless date
74 74 # "Setting.date_format.size < 2" is a temporary fix (content of date_format setting changed)
75 75 @date_format ||= (Setting.date_format.blank? || Setting.date_format.size < 2 ? l(:general_fmt_date) : Setting.date_format)
76 76 date.strftime(@date_format)
77 77 end
78 78
79 79 def format_time(time, include_date = true)
80 80 return nil unless time
81 81 time = time.to_time if time.is_a?(String)
82 82 zone = User.current.time_zone
83 83 if time.utc?
84 84 local = zone ? zone.adjust(time) : time.getlocal
85 85 else
86 86 local = zone ? zone.adjust(time.getutc) : time
87 87 end
88 88 @date_format ||= (Setting.date_format.blank? || Setting.date_format.size < 2 ? l(:general_fmt_date) : Setting.date_format)
89 89 @time_format ||= (Setting.time_format.blank? ? l(:general_fmt_time) : Setting.time_format)
90 90 include_date ? local.strftime("#{@date_format} #{@time_format}") : local.strftime(@time_format)
91 91 end
92 92
93 93 def html_hours(text)
94 94 text.gsub(%r{(\d+)\.(\d+)}, '<span class="hours hours-int">\1</span><span class="hours hours-dec">.\2</span>')
95 95 end
96 96
97 97 def authoring(created, author)
98 98 time_tag = content_tag('acronym', distance_of_time_in_words(Time.now, created), :title => format_time(created))
99 99 l(:label_added_time_by, author || 'Anonymous', time_tag)
100 100 end
101 101
102 102 def l_or_humanize(s)
103 103 l_has_string?("label_#{s}".to_sym) ? l("label_#{s}".to_sym) : s.to_s.humanize
104 104 end
105 105
106 106 def day_name(day)
107 107 l(:general_day_names).split(',')[day-1]
108 108 end
109 109
110 110 def month_name(month)
111 111 l(:actionview_datehelper_select_month_names).split(',')[month-1]
112 112 end
113 113
114 114 def pagination_links_full(paginator, count=nil, options={})
115 115 page_param = options.delete(:page_param) || :page
116 116 url_param = params.dup
117 117 # don't reuse params if filters are present
118 118 url_param.clear if url_param.has_key?(:set_filter)
119 119
120 120 html = ''
121 121 html << link_to_remote(('&#171; ' + l(:label_previous)),
122 122 {:update => 'content',
123 123 :url => url_param.merge(page_param => paginator.current.previous),
124 124 :complete => 'window.scrollTo(0,0)'},
125 125 {:href => url_for(:params => url_param.merge(page_param => paginator.current.previous))}) + ' ' if paginator.current.previous
126 126
127 127 html << (pagination_links_each(paginator, options) do |n|
128 128 link_to_remote(n.to_s,
129 129 {:url => {:params => url_param.merge(page_param => n)},
130 130 :update => 'content',
131 131 :complete => 'window.scrollTo(0,0)'},
132 132 {:href => url_for(:params => url_param.merge(page_param => n))})
133 133 end || '')
134 134
135 135 html << ' ' + link_to_remote((l(:label_next) + ' &#187;'),
136 136 {:update => 'content',
137 137 :url => url_param.merge(page_param => paginator.current.next),
138 138 :complete => 'window.scrollTo(0,0)'},
139 139 {:href => url_for(:params => url_param.merge(page_param => paginator.current.next))}) if paginator.current.next
140 140
141 141 unless count.nil?
142 142 html << [" (#{paginator.current.first_item}-#{paginator.current.last_item}/#{count})", per_page_links(paginator.items_per_page)].compact.join(' | ')
143 143 end
144 144
145 145 html
146 146 end
147 147
148 148 def per_page_links(selected=nil)
149 149 url_param = params.dup
150 150 url_param.clear if url_param.has_key?(:set_filter)
151 151
152 152 links = Setting.per_page_options_array.collect do |n|
153 153 n == selected ? n : link_to_remote(n, {:update => "content", :url => params.dup.merge(:per_page => n)},
154 154 {:href => url_for(url_param.merge(:per_page => n))})
155 155 end
156 156 links.size > 1 ? l(:label_display_per_page, links.join(', ')) : nil
157 157 end
158 158
159 159 def breadcrumb(*args)
160 160 content_tag('p', args.join(' &#187; ') + ' &#187; ', :class => 'breadcrumb')
161 161 end
162 162
163 163 def html_title(*args)
164 164 if args.empty?
165 165 title = []
166 166 title << @project.name if @project
167 167 title += @html_title if @html_title
168 168 title << Setting.app_title
169 169 title.compact.join(' - ')
170 170 else
171 171 @html_title ||= []
172 172 @html_title += args
173 173 end
174 174 end
175 175
176 176 def accesskey(s)
177 177 Redmine::AccessKeys.key_for s
178 178 end
179 179
180 180 # Formats text according to system settings.
181 181 # 2 ways to call this method:
182 182 # * with a String: textilizable(text, options)
183 183 # * with an object and one of its attribute: textilizable(issue, :description, options)
184 184 def textilizable(*args)
185 185 options = args.last.is_a?(Hash) ? args.pop : {}
186 186 case args.size
187 187 when 1
188 188 obj = nil
189 189 text = args.shift
190 190 when 2
191 191 obj = args.shift
192 192 text = obj.send(args.shift).to_s
193 193 else
194 194 raise ArgumentError, 'invalid arguments to textilizable'
195 195 end
196 196 return '' if text.blank?
197 197
198 198 only_path = options.delete(:only_path) == false ? false : true
199 199
200 200 # when using an image link, try to use an attachment, if possible
201 201 attachments = options[:attachments] || (obj && obj.respond_to?(:attachments) ? obj.attachments : nil)
202 202
203 203 if attachments
204 204 text = text.gsub(/!((\<|\=|\>)?(\([^\)]+\))?(\[[^\]]+\])?(\{[^\}]+\})?)(\S+\.(gif|jpg|jpeg|png))!/) do |m|
205 205 style = $1
206 206 filename = $6
207 207 rf = Regexp.new(filename, Regexp::IGNORECASE)
208 208 # search for the picture in attachments
209 209 if found = attachments.detect { |att| att.filename =~ rf }
210 image_url = url_for :only_path => only_path, :controller => 'attachments', :action => 'download', :id => found.id
211 "!#{style}#{image_url}!"
210 image_url = url_for :only_path => only_path, :controller => 'attachments', :action => 'download', :id => found
211 desc = found.description.to_s.gsub(/^([^\(\)]*).*$/, "\\1")
212 alt = desc.blank? ? nil : "(#{desc})"
213 "!#{style}#{image_url}#{alt}!"
212 214 else
213 215 "!#{style}#{filename}!"
214 216 end
215 217 end
216 218 end
217 219
218 220 text = (Setting.text_formatting == 'textile') ?
219 221 Redmine::WikiFormatting.to_html(text) { |macro, args| exec_macro(macro, obj, args) } :
220 222 simple_format(auto_link(h(text)))
221 223
222 224 # different methods for formatting wiki links
223 225 case options[:wiki_links]
224 226 when :local
225 227 # used for local links to html files
226 228 format_wiki_link = Proc.new {|project, title| "#{title}.html" }
227 229 when :anchor
228 230 # used for single-file wiki export
229 231 format_wiki_link = Proc.new {|project, title| "##{title}" }
230 232 else
231 233 format_wiki_link = Proc.new {|project, title| url_for(:only_path => only_path, :controller => 'wiki', :action => 'index', :id => project, :page => title) }
232 234 end
233 235
234 236 project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil)
235 237
236 238 # Wiki links
237 239 #
238 240 # Examples:
239 241 # [[mypage]]
240 242 # [[mypage|mytext]]
241 243 # wiki links can refer other project wikis, using project name or identifier:
242 244 # [[project:]] -> wiki starting page
243 245 # [[project:|mytext]]
244 246 # [[project:mypage]]
245 247 # [[project:mypage|mytext]]
246 248 text = text.gsub(/(!)?(\[\[([^\]\n\|]+)(\|([^\]\n\|]+))?\]\])/) do |m|
247 249 link_project = project
248 250 esc, all, page, title = $1, $2, $3, $5
249 251 if esc.nil?
250 252 if page =~ /^([^\:]+)\:(.*)$/
251 253 link_project = Project.find_by_name($1) || Project.find_by_identifier($1)
252 254 page = $2
253 255 title ||= $1 if page.blank?
254 256 end
255 257
256 258 if link_project && link_project.wiki
257 259 # check if page exists
258 260 wiki_page = link_project.wiki.find_page(page)
259 261 link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page)),
260 262 :class => ('wiki-page' + (wiki_page ? '' : ' new')))
261 263 else
262 264 # project or wiki doesn't exist
263 265 title || page
264 266 end
265 267 else
266 268 all
267 269 end
268 270 end
269 271
270 272 # Redmine links
271 273 #
272 274 # Examples:
273 275 # Issues:
274 276 # #52 -> Link to issue #52
275 277 # Changesets:
276 278 # r52 -> Link to revision 52
277 279 # commit:a85130f -> Link to scmid starting with a85130f
278 280 # Documents:
279 281 # document#17 -> Link to document with id 17
280 282 # document:Greetings -> Link to the document with title "Greetings"
281 283 # document:"Some document" -> Link to the document with title "Some document"
282 284 # Versions:
283 285 # version#3 -> Link to version with id 3
284 286 # version:1.0.0 -> Link to version named "1.0.0"
285 287 # version:"1.0 beta 2" -> Link to version named "1.0 beta 2"
286 288 # Attachments:
287 289 # attachment:file.zip -> Link to the attachment of the current object named file.zip
288 290 # Source files:
289 291 # source:some/file -> Link to the file located at /some/file in the project's repository
290 292 # source:some/file@52 -> Link to the file's revision 52
291 293 # source:some/file#L120 -> Link to line 120 of the file
292 294 # source:some/file@52#L120 -> Link to line 120 of the file's revision 52
293 295 # export:some/file -> Force the download of the file
294 296 text = text.gsub(%r{([\s\(,-^])(!)?(attachment|document|version|commit|source|export)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*|"[^"]+"))(?=[[:punct:]]|\s|<|$)}) do |m|
295 297 leading, esc, prefix, sep, oid = $1, $2, $3, $5 || $7, $6 || $8
296 298 link = nil
297 299 if esc.nil?
298 300 if prefix.nil? && sep == 'r'
299 301 if project && (changeset = project.changesets.find_by_revision(oid))
300 302 link = link_to("r#{oid}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => oid},
301 303 :class => 'changeset',
302 304 :title => truncate(changeset.comments, 100))
303 305 end
304 306 elsif sep == '#'
305 307 oid = oid.to_i
306 308 case prefix
307 309 when nil
308 310 if issue = Issue.find_by_id(oid, :include => [:project, :status], :conditions => Project.visible_by(User.current))
309 311 link = link_to("##{oid}", {:only_path => only_path, :controller => 'issues', :action => 'show', :id => oid},
310 312 :class => (issue.closed? ? 'issue closed' : 'issue'),
311 313 :title => "#{truncate(issue.subject, 100)} (#{issue.status.name})")
312 314 link = content_tag('del', link) if issue.closed?
313 315 end
314 316 when 'document'
315 317 if document = Document.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current))
316 318 link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
317 319 :class => 'document'
318 320 end
319 321 when 'version'
320 322 if version = Version.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current))
321 323 link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
322 324 :class => 'version'
323 325 end
324 326 end
325 327 elsif sep == ':'
326 328 # removes the double quotes if any
327 329 name = oid.gsub(%r{^"(.*)"$}, "\\1")
328 330 case prefix
329 331 when 'document'
330 332 if project && document = project.documents.find_by_title(name)
331 333 link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
332 334 :class => 'document'
333 335 end
334 336 when 'version'
335 337 if project && version = project.versions.find_by_name(name)
336 338 link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
337 339 :class => 'version'
338 340 end
339 341 when 'commit'
340 342 if project && (changeset = project.changesets.find(:first, :conditions => ["scmid LIKE ?", "#{name}%"]))
341 343 link = link_to h("#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision}, :class => 'changeset', :title => truncate(changeset.comments, 100)
342 344 end
343 345 when 'source', 'export'
344 346 if project && project.repository
345 347 name =~ %r{^[/\\]*(.*?)(@([0-9a-f]+))?(#(L\d+))?$}
346 348 path, rev, anchor = $1, $3, $5
347 349 link = link_to h("#{prefix}:#{name}"), {:controller => 'repositories', :action => 'entry', :id => project, :path => path,
348 350 :rev => rev,
349 351 :anchor => anchor,
350 352 :format => (prefix == 'export' ? 'raw' : nil)},
351 353 :class => (prefix == 'export' ? 'source download' : 'source')
352 354 end
353 355 when 'attachment'
354 356 if attachments && attachment = attachments.detect {|a| a.filename == name }
355 357 link = link_to h(attachment.filename), {:only_path => only_path, :controller => 'attachments', :action => 'download', :id => attachment},
356 358 :class => 'attachment'
357 359 end
358 360 end
359 361 end
360 362 end
361 363 leading + (link || "#{prefix}#{sep}#{oid}")
362 364 end
363 365
364 366 text
365 367 end
366 368
367 369 # Same as Rails' simple_format helper without using paragraphs
368 370 def simple_format_without_paragraph(text)
369 371 text.to_s.
370 372 gsub(/\r\n?/, "\n"). # \r\n and \r -> \n
371 373 gsub(/\n\n+/, "<br /><br />"). # 2+ newline -> 2 br
372 374 gsub(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br
373 375 end
374 376
375 377 def error_messages_for(object_name, options = {})
376 378 options = options.symbolize_keys
377 379 object = instance_variable_get("@#{object_name}")
378 380 if object && !object.errors.empty?
379 381 # build full_messages here with controller current language
380 382 full_messages = []
381 383 object.errors.each do |attr, msg|
382 384 next if msg.nil?
383 385 msg = msg.first if msg.is_a? Array
384 386 if attr == "base"
385 387 full_messages << l(msg)
386 388 else
387 389 full_messages << "&#171; " + (l_has_string?("field_" + attr) ? l("field_" + attr) : object.class.human_attribute_name(attr)) + " &#187; " + l(msg) unless attr == "custom_values"
388 390 end
389 391 end
390 392 # retrieve custom values error messages
391 393 if object.errors[:custom_values]
392 394 object.custom_values.each do |v|
393 395 v.errors.each do |attr, msg|
394 396 next if msg.nil?
395 397 msg = msg.first if msg.is_a? Array
396 398 full_messages << "&#171; " + v.custom_field.name + " &#187; " + l(msg)
397 399 end
398 400 end
399 401 end
400 402 content_tag("div",
401 403 content_tag(
402 404 options[:header_tag] || "span", lwr(:gui_validation_error, full_messages.length) + ":"
403 405 ) +
404 406 content_tag("ul", full_messages.collect { |msg| content_tag("li", msg) }),
405 407 "id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation"
406 408 )
407 409 else
408 410 ""
409 411 end
410 412 end
411 413
412 414 def lang_options_for_select(blank=true)
413 415 (blank ? [["(auto)", ""]] : []) +
414 416 GLoc.valid_languages.collect{|lang| [ ll(lang.to_s, :general_lang_name), lang.to_s]}.sort{|x,y| x.last <=> y.last }
415 417 end
416 418
417 419 def label_tag_for(name, option_tags = nil, options = {})
418 420 label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
419 421 content_tag("label", label_text)
420 422 end
421 423
422 424 def labelled_tabular_form_for(name, object, options, &proc)
423 425 options[:html] ||= {}
424 426 options[:html][:class] = 'tabular' unless options[:html].has_key?(:class)
425 427 form_for(name, object, options.merge({ :builder => TabularFormBuilder, :lang => current_language}), &proc)
426 428 end
427 429
428 430 def check_all_links(form_name)
429 431 link_to_function(l(:button_check_all), "checkAll('#{form_name}', true)") +
430 432 " | " +
431 433 link_to_function(l(:button_uncheck_all), "checkAll('#{form_name}', false)")
432 434 end
433 435
434 436 def progress_bar(pcts, options={})
435 437 pcts = [pcts, pcts] unless pcts.is_a?(Array)
436 438 pcts[1] = pcts[1] - pcts[0]
437 439 pcts << (100 - pcts[1] - pcts[0])
438 440 width = options[:width] || '100px;'
439 441 legend = options[:legend] || ''
440 442 content_tag('table',
441 443 content_tag('tr',
442 444 (pcts[0] > 0 ? content_tag('td', '', :width => "#{pcts[0].floor}%;", :class => 'closed') : '') +
443 445 (pcts[1] > 0 ? content_tag('td', '', :width => "#{pcts[1].floor}%;", :class => 'done') : '') +
444 446 (pcts[2] > 0 ? content_tag('td', '', :width => "#{pcts[2].floor}%;", :class => 'todo') : '')
445 447 ), :class => 'progress', :style => "width: #{width};") +
446 448 content_tag('p', legend, :class => 'pourcent')
447 449 end
448 450
449 451 def context_menu_link(name, url, options={})
450 452 options[:class] ||= ''
451 453 if options.delete(:selected)
452 454 options[:class] << ' icon-checked disabled'
453 455 options[:disabled] = true
454 456 end
455 457 if options.delete(:disabled)
456 458 options.delete(:method)
457 459 options.delete(:confirm)
458 460 options.delete(:onclick)
459 461 options[:class] << ' disabled'
460 462 url = '#'
461 463 end
462 464 link_to name, url, options
463 465 end
464 466
465 467 def calendar_for(field_id)
466 468 include_calendar_headers_tags
467 469 image_tag("calendar.png", {:id => "#{field_id}_trigger",:class => "calendar-trigger"}) +
468 470 javascript_tag("Calendar.setup({inputField : '#{field_id}', ifFormat : '%Y-%m-%d', button : '#{field_id}_trigger' });")
469 471 end
470 472
471 473 def include_calendar_headers_tags
472 474 unless @calendar_headers_tags_included
473 475 @calendar_headers_tags_included = true
474 476 content_for :header_tags do
475 477 javascript_include_tag('calendar/calendar') +
476 478 javascript_include_tag("calendar/lang/calendar-#{current_language}.js") +
477 479 javascript_include_tag('calendar/calendar-setup') +
478 480 stylesheet_link_tag('calendar')
479 481 end
480 482 end
481 483 end
482 484
483 485 def wikitoolbar_for(field_id)
484 486 return '' unless Setting.text_formatting == 'textile'
485 487
486 488 help_link = l(:setting_text_formatting) + ': ' +
487 489 link_to(l(:label_help), compute_public_path('wiki_syntax', 'help', 'html'),
488 490 :onclick => "window.open(\"#{ compute_public_path('wiki_syntax', 'help', 'html') }\", \"\", \"resizable=yes, location=no, width=300, height=640, menubar=no, status=no, scrollbars=yes\"); return false;")
489 491
490 492 javascript_include_tag('jstoolbar/jstoolbar') +
491 493 javascript_include_tag("jstoolbar/lang/jstoolbar-#{current_language}") +
492 494 javascript_tag("var toolbar = new jsToolBar($('#{field_id}')); toolbar.setHelpLink('#{help_link}'); toolbar.draw();")
493 495 end
494 496
495 497 def content_for(name, content = nil, &block)
496 498 @has_content ||= {}
497 499 @has_content[name] = true
498 500 super(name, content, &block)
499 501 end
500 502
501 503 def has_content?(name)
502 504 (@has_content && @has_content[name]) || false
503 505 end
504 506 end
@@ -1,38 +1,39
1 1 ---
2 2 attachments_001:
3 3 created_on: 2006-07-19 21:07:27 +02:00
4 4 downloads: 0
5 5 content_type: text/plain
6 6 disk_filename: 060719210727_error281.txt
7 7 container_id: 3
8 8 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
9 9 id: 1
10 10 container_type: Issue
11 11 filesize: 28
12 12 filename: error281.txt
13 13 author_id: 2
14 14 attachments_002:
15 15 created_on: 2006-07-19 21:07:27 +02:00
16 16 downloads: 0
17 17 content_type: text/plain
18 18 disk_filename: 060719210727_document.txt
19 19 container_id: 1
20 20 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
21 21 id: 2
22 22 container_type: Document
23 23 filesize: 28
24 24 filename: document.txt
25 25 author_id: 2
26 26 attachments_003:
27 27 created_on: 2006-07-19 21:07:27 +02:00
28 28 downloads: 0
29 29 content_type: image/gif
30 30 disk_filename: 060719210727_logo.gif
31 31 container_id: 4
32 32 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
33 33 id: 3
34 34 container_type: WikiPage
35 35 filesize: 280
36 36 filename: logo.gif
37 description: This is a logo
37 38 author_id: 2
38 39 No newline at end of file
@@ -1,162 +1,163
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.dirname(__FILE__) + '/../test_helper'
19 19 require 'wiki_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class WikiController; def rescue_action(e) raise e end; end
23 23
24 24 class WikiControllerTest < Test::Unit::TestCase
25 25 fixtures :projects, :users, :roles, :members, :enabled_modules, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, :attachments
26 26
27 27 def setup
28 28 @controller = WikiController.new
29 29 @request = ActionController::TestRequest.new
30 30 @response = ActionController::TestResponse.new
31 31 User.current = nil
32 32 end
33 33
34 34 def test_show_start_page
35 35 get :index, :id => 1
36 36 assert_response :success
37 37 assert_template 'show'
38 38 assert_tag :tag => 'h1', :content => /CookBook documentation/
39 39 end
40 40
41 41 def test_show_page_with_name
42 42 get :index, :id => 1, :page => 'Another_page'
43 43 assert_response :success
44 44 assert_template 'show'
45 45 assert_tag :tag => 'h1', :content => /Another page/
46 46 # Included page with an inline image
47 47 assert_tag :tag => 'p', :content => /This is an inline image/
48 assert_tag :tag => 'img', :attributes => { :src => '/attachments/download/3' }
48 assert_tag :tag => 'img', :attributes => { :src => '/attachments/download/3',
49 :alt => 'This is a logo' }
49 50 end
50 51
51 52 def test_show_unexistent_page_without_edit_right
52 53 get :index, :id => 1, :page => 'Unexistent page'
53 54 assert_response 404
54 55 end
55 56
56 57 def test_show_unexistent_page_with_edit_right
57 58 @request.session[:user_id] = 2
58 59 get :index, :id => 1, :page => 'Unexistent page'
59 60 assert_response :success
60 61 assert_template 'edit'
61 62 end
62 63
63 64 def test_create_page
64 65 @request.session[:user_id] = 2
65 66 post :edit, :id => 1,
66 67 :page => 'New page',
67 68 :content => {:comments => 'Created the page',
68 69 :text => "h1. New page\n\nThis is a new page",
69 70 :version => 0}
70 71 assert_redirected_to 'wiki/ecookbook/New_page'
71 72 page = Project.find(1).wiki.find_page('New page')
72 73 assert !page.new_record?
73 74 assert_not_nil page.content
74 75 assert_equal 'Created the page', page.content.comments
75 76 end
76 77
77 78 def test_preview
78 79 @request.session[:user_id] = 2
79 80 xhr :post, :preview, :id => 1, :page => 'CookBook_documentation',
80 81 :content => { :comments => '',
81 82 :text => 'this is a *previewed text*',
82 83 :version => 3 }
83 84 assert_response :success
84 85 assert_template 'common/_preview'
85 86 assert_tag :tag => 'strong', :content => /previewed text/
86 87 end
87 88
88 89 def test_history
89 90 get :history, :id => 1, :page => 'CookBook_documentation'
90 91 assert_response :success
91 92 assert_template 'history'
92 93 assert_not_nil assigns(:versions)
93 94 assert_equal 3, assigns(:versions).size
94 95 end
95 96
96 97 def test_diff
97 98 get :diff, :id => 1, :page => 'CookBook_documentation', :version => 2, :version_from => 1
98 99 assert_response :success
99 100 assert_template 'diff'
100 101 assert_tag :tag => 'span', :attributes => { :class => 'diff_in'},
101 102 :content => /updated/
102 103 end
103 104
104 105 def test_annotate
105 106 get :annotate, :id => 1, :page => 'CookBook_documentation', :version => 2
106 107 assert_response :success
107 108 assert_template 'annotate'
108 109 # Line 1
109 110 assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '1' },
110 111 :child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /John Smith/ },
111 112 :child => { :tag => 'td', :content => /h1\. CookBook documentation/ }
112 113 # Line 2
113 114 assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '2' },
114 115 :child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /redMine Admin/ },
115 116 :child => { :tag => 'td', :content => /Some updated \[\[documentation\]\] here/ }
116 117 end
117 118
118 119 def test_rename_with_redirect
119 120 @request.session[:user_id] = 2
120 121 post :rename, :id => 1, :page => 'Another_page',
121 122 :wiki_page => { :title => 'Another renamed page',
122 123 :redirect_existing_links => 1 }
123 124 assert_redirected_to 'wiki/ecookbook/Another_renamed_page'
124 125 wiki = Project.find(1).wiki
125 126 # Check redirects
126 127 assert_not_nil wiki.find_page('Another page')
127 128 assert_nil wiki.find_page('Another page', :with_redirect => false)
128 129 end
129 130
130 131 def test_rename_without_redirect
131 132 @request.session[:user_id] = 2
132 133 post :rename, :id => 1, :page => 'Another_page',
133 134 :wiki_page => { :title => 'Another renamed page',
134 135 :redirect_existing_links => "0" }
135 136 assert_redirected_to 'wiki/ecookbook/Another_renamed_page'
136 137 wiki = Project.find(1).wiki
137 138 # Check that there's no redirects
138 139 assert_nil wiki.find_page('Another page')
139 140 end
140 141
141 142 def test_destroy
142 143 @request.session[:user_id] = 2
143 144 post :destroy, :id => 1, :page => 'CookBook_documentation'
144 145 assert_redirected_to 'wiki/ecookbook/Page_index/special'
145 146 end
146 147
147 148 def test_page_index
148 149 get :special, :id => 'ecookbook', :page => 'Page_index'
149 150 assert_response :success
150 151 assert_template 'special_page_index'
151 152 pages = assigns(:pages)
152 153 assert_not_nil pages
153 154 assert_equal Project.find(1).wiki.pages.size, pages.size
154 155 assert_tag :tag => 'a', :attributes => { :href => '/wiki/ecookbook/CookBook_documentation' },
155 156 :content => /CookBook documentation/
156 157 end
157 158
158 159 def test_not_found
159 160 get :index, :id => 999
160 161 assert_response 404
161 162 end
162 163 end
General Comments 0
You need to be logged in to leave comments. Login now