##// END OF EJS Templates
Upgrade to Rails 3.2.8 (#11758)....
Jean-Philippe Lang -
r10092:265baa1b2c5d
parent child
Show More

The requested changes are too big and content was truncated. Show full diff

@@ -1,92 +1,92
1 1 source 'http://rubygems.org'
2 2
3 gem 'rails', '3.2.6'
3 gem 'rails', '3.2.8'
4 4 gem "jquery-rails", "~> 2.0.2"
5 5 gem "i18n", "~> 0.6.0"
6 6 gem "coderay", "~> 1.0.6"
7 7 gem "fastercsv", "~> 1.5.0", :platforms => [:mri_18, :mingw_18, :jruby]
8 8 gem "builder"
9 9
10 10 # Optional gem for LDAP authentication
11 11 group :ldap do
12 12 gem "net-ldap", "~> 0.3.1"
13 13 end
14 14
15 15 # Optional gem for OpenID authentication
16 16 group :openid do
17 17 gem "ruby-openid", "~> 2.1.4", :require => "openid"
18 18 gem "rack-openid"
19 19 end
20 20
21 21 # Optional gem for exporting the gantt to a PNG file, not supported with jruby
22 22 platforms :mri, :mingw do
23 23 group :rmagick do
24 24 # RMagick 2 supports ruby 1.9
25 25 # RMagick 1 would be fine for ruby 1.8 but Bundler does not support
26 26 # different requirements for the same gem on different platforms
27 27 gem "rmagick", ">= 2.0.0"
28 28 end
29 29 end
30 30
31 31 # Database gems
32 32 platforms :mri, :mingw do
33 33 group :postgresql do
34 34 gem "pg", ">= 0.11.0"
35 35 end
36 36
37 37 group :sqlite do
38 38 gem "sqlite3"
39 39 end
40 40 end
41 41
42 42 platforms :mri_18, :mingw_18 do
43 43 group :mysql do
44 44 gem "mysql"
45 45 end
46 46 end
47 47
48 48 platforms :mri_19, :mingw_19 do
49 49 group :mysql do
50 50 gem "mysql2", "~> 0.3.11"
51 51 end
52 52 end
53 53
54 54 platforms :jruby do
55 55 gem "jruby-openssl"
56 56
57 57 group :mysql do
58 58 gem "activerecord-jdbcmysql-adapter"
59 59 end
60 60
61 61 group :postgresql do
62 62 gem "activerecord-jdbcpostgresql-adapter"
63 63 end
64 64
65 65 group :sqlite do
66 66 gem "activerecord-jdbcsqlite3-adapter"
67 67 end
68 68 end
69 69
70 70 group :development do
71 71 gem "rdoc", ">= 2.4.2"
72 72 gem "yard"
73 73 end
74 74
75 75 group :test do
76 76 gem "shoulda", "~> 2.11"
77 77 # Shoulda does not work nice on Ruby 1.9.3 and seems to need test-unit explicitely.
78 78 gem "test-unit", :platforms => [:mri_19]
79 79 gem "mocha", "0.12.3"
80 80 end
81 81
82 82 local_gemfile = File.join(File.dirname(__FILE__), "Gemfile.local")
83 83 if File.exists?(local_gemfile)
84 84 puts "Loading Gemfile.local ..." if $DEBUG # `ruby -d` or `bundle -v`
85 85 instance_eval File.read(local_gemfile)
86 86 end
87 87
88 88 # Load plugins' Gemfiles
89 89 Dir.glob File.expand_path("../plugins/*/Gemfile", __FILE__) do |file|
90 90 puts "Loading #{file} ..." if $DEBUG # `ruby -d` or `bundle -v`
91 91 instance_eval File.read(file)
92 92 end
@@ -1,1257 +1,1257
1 1 # encoding: utf-8
2 2 #
3 3 # Redmine - project management software
4 4 # Copyright (C) 2006-2012 Jean-Philippe Lang
5 5 #
6 6 # This program is free software; you can redistribute it and/or
7 7 # modify it under the terms of the GNU General Public License
8 8 # as published by the Free Software Foundation; either version 2
9 9 # of the License, or (at your option) any later version.
10 10 #
11 11 # This program is distributed in the hope that it will be useful,
12 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 14 # GNU General Public License for more details.
15 15 #
16 16 # You should have received a copy of the GNU General Public License
17 17 # along with this program; if not, write to the Free Software
18 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 19
20 20 require 'forwardable'
21 21 require 'cgi'
22 22
23 23 module ApplicationHelper
24 24 include Redmine::WikiFormatting::Macros::Definitions
25 25 include Redmine::I18n
26 26 include GravatarHelper::PublicMethods
27 27
28 28 extend Forwardable
29 29 def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter
30 30
31 31 # Return true if user is authorized for controller/action, otherwise false
32 32 def authorize_for(controller, action)
33 33 User.current.allowed_to?({:controller => controller, :action => action}, @project)
34 34 end
35 35
36 36 # Display a link if user is authorized
37 37 #
38 38 # @param [String] name Anchor text (passed to link_to)
39 39 # @param [Hash] options Hash params. This will checked by authorize_for to see if the user is authorized
40 40 # @param [optional, Hash] html_options Options passed to link_to
41 41 # @param [optional, Hash] parameters_for_method_reference Extra parameters for link_to
42 42 def link_to_if_authorized(name, options = {}, html_options = nil, *parameters_for_method_reference)
43 43 link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller] || params[:controller], options[:action])
44 44 end
45 45
46 46 # Displays a link to user's account page if active
47 47 def link_to_user(user, options={})
48 48 if user.is_a?(User)
49 49 name = h(user.name(options[:format]))
50 50 if user.active?
51 51 link_to name, :controller => 'users', :action => 'show', :id => user
52 52 else
53 53 name
54 54 end
55 55 else
56 56 h(user.to_s)
57 57 end
58 58 end
59 59
60 60 # Displays a link to +issue+ with its subject.
61 61 # Examples:
62 62 #
63 63 # link_to_issue(issue) # => Defect #6: This is the subject
64 64 # link_to_issue(issue, :truncate => 6) # => Defect #6: This i...
65 65 # link_to_issue(issue, :subject => false) # => Defect #6
66 66 # link_to_issue(issue, :project => true) # => Foo - Defect #6
67 67 #
68 68 def link_to_issue(issue, options={})
69 69 title = nil
70 70 subject = nil
71 71 if options[:subject] == false
72 72 title = truncate(issue.subject, :length => 60)
73 73 else
74 74 subject = issue.subject
75 75 if options[:truncate]
76 76 subject = truncate(subject, :length => options[:truncate])
77 77 end
78 78 end
79 79 s = link_to "#{h(issue.tracker)} ##{issue.id}", {:controller => "issues", :action => "show", :id => issue},
80 80 :class => issue.css_classes,
81 81 :title => title
82 82 s << h(": #{subject}") if subject
83 83 s = h("#{issue.project} - ") + s if options[:project]
84 84 s
85 85 end
86 86
87 87 # Generates a link to an attachment.
88 88 # Options:
89 89 # * :text - Link text (default to attachment filename)
90 90 # * :download - Force download (default: false)
91 91 def link_to_attachment(attachment, options={})
92 92 text = options.delete(:text) || attachment.filename
93 93 action = options.delete(:download) ? 'download' : 'show'
94 94 opt_only_path = {}
95 95 opt_only_path[:only_path] = (options[:only_path] == false ? false : true)
96 96 options.delete(:only_path)
97 97 link_to(h(text),
98 98 {:controller => 'attachments', :action => action,
99 99 :id => attachment, :filename => attachment.filename}.merge(opt_only_path),
100 100 options)
101 101 end
102 102
103 103 # Generates a link to a SCM revision
104 104 # Options:
105 105 # * :text - Link text (default to the formatted revision)
106 106 def link_to_revision(revision, repository, options={})
107 107 if repository.is_a?(Project)
108 108 repository = repository.repository
109 109 end
110 110 text = options.delete(:text) || format_revision(revision)
111 111 rev = revision.respond_to?(:identifier) ? revision.identifier : revision
112 112 link_to(
113 113 h(text),
114 114 {:controller => 'repositories', :action => 'revision', :id => repository.project, :repository_id => repository.identifier_param, :rev => rev},
115 115 :title => l(:label_revision_id, format_revision(revision))
116 116 )
117 117 end
118 118
119 119 # Generates a link to a message
120 120 def link_to_message(message, options={}, html_options = nil)
121 121 link_to(
122 122 h(truncate(message.subject, :length => 60)),
123 123 { :controller => 'messages', :action => 'show',
124 124 :board_id => message.board_id,
125 125 :id => (message.parent_id || message.id),
126 126 :r => (message.parent_id && message.id),
127 127 :anchor => (message.parent_id ? "message-#{message.id}" : nil)
128 128 }.merge(options),
129 129 html_options
130 130 )
131 131 end
132 132
133 133 # Generates a link to a project if active
134 134 # Examples:
135 135 #
136 136 # link_to_project(project) # => link to the specified project overview
137 137 # link_to_project(project, :action=>'settings') # => link to project settings
138 138 # link_to_project(project, {:only_path => false}, :class => "project") # => 3rd arg adds html options
139 139 # link_to_project(project, {}, :class => "project") # => html options with default url (project overview)
140 140 #
141 141 def link_to_project(project, options={}, html_options = nil)
142 142 if project.archived?
143 143 h(project)
144 144 else
145 145 url = {:controller => 'projects', :action => 'show', :id => project}.merge(options)
146 146 link_to(h(project), url, html_options)
147 147 end
148 148 end
149 149
150 150 def thumbnail_tag(attachment)
151 151 link_to image_tag(url_for(:controller => 'attachments', :action => 'thumbnail', :id => attachment)),
152 152 {:controller => 'attachments', :action => 'show', :id => attachment, :filename => attachment.filename},
153 153 :title => attachment.filename
154 154 end
155 155
156 156 def toggle_link(name, id, options={})
157 157 onclick = "$('##{id}').toggle(); "
158 158 onclick << (options[:focus] ? "$('##{options[:focus]}').focus(); " : "this.blur(); ")
159 159 onclick << "return false;"
160 160 link_to(name, "#", :onclick => onclick)
161 161 end
162 162
163 163 def image_to_function(name, function, html_options = {})
164 164 html_options.symbolize_keys!
165 165 tag(:input, html_options.merge({
166 166 :type => "image", :src => image_path(name),
167 167 :onclick => (html_options[:onclick] ? "#{html_options[:onclick]}; " : "") + "#{function};"
168 168 }))
169 169 end
170 170
171 171 def format_activity_title(text)
172 172 h(truncate_single_line(text, :length => 100))
173 173 end
174 174
175 175 def format_activity_day(date)
176 176 date == User.current.today ? l(:label_today).titleize : format_date(date)
177 177 end
178 178
179 179 def format_activity_description(text)
180 180 h(truncate(text.to_s, :length => 120).gsub(%r{[\r\n]*<(pre|code)>.*$}m, '...')
181 181 ).gsub(/[\r\n]+/, "<br />").html_safe
182 182 end
183 183
184 184 def format_version_name(version)
185 185 if version.project == @project
186 186 h(version)
187 187 else
188 188 h("#{version.project} - #{version}")
189 189 end
190 190 end
191 191
192 192 def due_date_distance_in_words(date)
193 193 if date
194 194 l((date < Date.today ? :label_roadmap_overdue : :label_roadmap_due_in), distance_of_date_in_words(Date.today, date))
195 195 end
196 196 end
197 197
198 198 # Renders a tree of projects as a nested set of unordered lists
199 199 # The given collection may be a subset of the whole project tree
200 200 # (eg. some intermediate nodes are private and can not be seen)
201 201 def render_project_nested_lists(projects)
202 202 s = ''
203 203 if projects.any?
204 204 ancestors = []
205 205 original_project = @project
206 206 projects.sort_by(&:lft).each do |project|
207 207 # set the project environment to please macros.
208 208 @project = project
209 209 if (ancestors.empty? || project.is_descendant_of?(ancestors.last))
210 210 s << "<ul class='projects #{ ancestors.empty? ? 'root' : nil}'>\n"
211 211 else
212 212 ancestors.pop
213 213 s << "</li>"
214 214 while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
215 215 ancestors.pop
216 216 s << "</ul></li>\n"
217 217 end
218 218 end
219 219 classes = (ancestors.empty? ? 'root' : 'child')
220 220 s << "<li class='#{classes}'><div class='#{classes}'>"
221 221 s << h(block_given? ? yield(project) : project.name)
222 222 s << "</div>\n"
223 223 ancestors << project
224 224 end
225 225 s << ("</li></ul>\n" * ancestors.size)
226 226 @project = original_project
227 227 end
228 228 s.html_safe
229 229 end
230 230
231 231 def render_page_hierarchy(pages, node=nil, options={})
232 232 content = ''
233 233 if pages[node]
234 234 content << "<ul class=\"pages-hierarchy\">\n"
235 235 pages[node].each do |page|
236 236 content << "<li>"
237 237 content << link_to(h(page.pretty_title), {:controller => 'wiki', :action => 'show', :project_id => page.project, :id => page.title},
238 238 :title => (options[:timestamp] && page.updated_on ? l(:label_updated_time, distance_of_time_in_words(Time.now, page.updated_on)) : nil))
239 239 content << "\n" + render_page_hierarchy(pages, page.id, options) if pages[page.id]
240 240 content << "</li>\n"
241 241 end
242 242 content << "</ul>\n"
243 243 end
244 244 content.html_safe
245 245 end
246 246
247 247 # Renders flash messages
248 248 def render_flash_messages
249 249 s = ''
250 250 flash.each do |k,v|
251 251 s << content_tag('div', v.html_safe, :class => "flash #{k}", :id => "flash_#{k}")
252 252 end
253 253 s.html_safe
254 254 end
255 255
256 256 # Renders tabs and their content
257 257 def render_tabs(tabs)
258 258 if tabs.any?
259 259 render :partial => 'common/tabs', :locals => {:tabs => tabs}
260 260 else
261 261 content_tag 'p', l(:label_no_data), :class => "nodata"
262 262 end
263 263 end
264 264
265 265 # Renders the project quick-jump box
266 266 def render_project_jump_box
267 267 return unless User.current.logged?
268 268 projects = User.current.memberships.collect(&:project).compact.select(&:active?).uniq
269 269 if projects.any?
270 270 options =
271 271 ("<option value=''>#{ l(:label_jump_to_a_project) }</option>" +
272 272 '<option value="" disabled="disabled">---</option>').html_safe
273 273
274 274 options << project_tree_options_for_select(projects, :selected => @project) do |p|
275 275 { :value => project_path(:id => p, :jump => current_menu_item) }
276 276 end
277 277
278 278 select_tag('project_quick_jump_box', options, :onchange => 'if (this.value != \'\') { window.location = this.value; }')
279 279 end
280 280 end
281 281
282 282 def project_tree_options_for_select(projects, options = {})
283 283 s = ''
284 284 project_tree(projects) do |project, level|
285 285 name_prefix = (level > 0 ? '&nbsp;' * 2 * level + '&#187; ' : '').html_safe
286 286 tag_options = {:value => project.id}
287 287 if project == options[:selected] || (options[:selected].respond_to?(:include?) && options[:selected].include?(project))
288 288 tag_options[:selected] = 'selected'
289 289 else
290 290 tag_options[:selected] = nil
291 291 end
292 292 tag_options.merge!(yield(project)) if block_given?
293 293 s << content_tag('option', name_prefix + h(project), tag_options)
294 294 end
295 295 s.html_safe
296 296 end
297 297
298 298 # Yields the given block for each project with its level in the tree
299 299 #
300 300 # Wrapper for Project#project_tree
301 301 def project_tree(projects, &block)
302 302 Project.project_tree(projects, &block)
303 303 end
304 304
305 305 def principals_check_box_tags(name, principals)
306 306 s = ''
307 307 principals.sort.each do |principal|
308 308 s << "<label>#{ check_box_tag name, principal.id, false } #{h principal}</label>\n"
309 309 end
310 310 s.html_safe
311 311 end
312 312
313 313 # Returns a string for users/groups option tags
314 314 def principals_options_for_select(collection, selected=nil)
315 315 s = ''
316 316 if collection.include?(User.current)
317 317 s << content_tag('option', "<< #{l(:label_me)} >>", :value => User.current.id)
318 318 end
319 319 groups = ''
320 320 collection.sort.each do |element|
321 321 selected_attribute = ' selected="selected"' if option_value_selected?(element, selected)
322 322 (element.is_a?(Group) ? groups : s) << %(<option value="#{element.id}"#{selected_attribute}>#{h element.name}</option>)
323 323 end
324 324 unless groups.empty?
325 325 s << %(<optgroup label="#{h(l(:label_group_plural))}">#{groups}</optgroup>)
326 326 end
327 327 s.html_safe
328 328 end
329 329
330 330 # Truncates and returns the string as a single line
331 331 def truncate_single_line(string, *args)
332 332 truncate(string.to_s, *args).gsub(%r{[\r\n]+}m, ' ')
333 333 end
334 334
335 335 # Truncates at line break after 250 characters or options[:length]
336 336 def truncate_lines(string, options={})
337 337 length = options[:length] || 250
338 338 if string.to_s =~ /\A(.{#{length}}.*?)$/m
339 339 "#{$1}..."
340 340 else
341 341 string
342 342 end
343 343 end
344 344
345 345 def anchor(text)
346 346 text.to_s.gsub(' ', '_')
347 347 end
348 348
349 349 def html_hours(text)
350 350 text.gsub(%r{(\d+)\.(\d+)}, '<span class="hours hours-int">\1</span><span class="hours hours-dec">.\2</span>').html_safe
351 351 end
352 352
353 353 def authoring(created, author, options={})
354 354 l(options[:label] || :label_added_time_by, :author => link_to_user(author), :age => time_tag(created)).html_safe
355 355 end
356 356
357 357 def time_tag(time)
358 358 text = distance_of_time_in_words(Time.now, time)
359 359 if @project
360 360 link_to(text, {:controller => 'activities', :action => 'index', :id => @project, :from => User.current.time_to_date(time)}, :title => format_time(time))
361 361 else
362 362 content_tag('acronym', text, :title => format_time(time))
363 363 end
364 364 end
365 365
366 366 def syntax_highlight_lines(name, content)
367 367 lines = []
368 368 syntax_highlight(name, content).each_line { |line| lines << line }
369 369 lines
370 370 end
371 371
372 372 def syntax_highlight(name, content)
373 373 Redmine::SyntaxHighlighting.highlight_by_filename(content, name)
374 374 end
375 375
376 376 def to_path_param(path)
377 377 str = path.to_s.split(%r{[/\\]}).select{|p| !p.blank?}.join("/")
378 378 str.blank? ? nil : str
379 379 end
380 380
381 381 def pagination_links_full(paginator, count=nil, options={})
382 382 page_param = options.delete(:page_param) || :page
383 383 per_page_links = options.delete(:per_page_links)
384 384 url_param = params.dup
385 385
386 386 html = ''
387 387 if paginator.current.previous
388 388 # \xc2\xab(utf-8) = &#171;
389 389 html << link_to_content_update(
390 390 "\xc2\xab " + l(:label_previous),
391 391 url_param.merge(page_param => paginator.current.previous)) + ' '
392 392 end
393 393
394 394 html << (pagination_links_each(paginator, options) do |n|
395 395 link_to_content_update(n.to_s, url_param.merge(page_param => n))
396 396 end || '')
397 397
398 398 if paginator.current.next
399 399 # \xc2\xbb(utf-8) = &#187;
400 400 html << ' ' + link_to_content_update(
401 401 (l(:label_next) + " \xc2\xbb"),
402 402 url_param.merge(page_param => paginator.current.next))
403 403 end
404 404
405 405 unless count.nil?
406 406 html << " (#{paginator.current.first_item}-#{paginator.current.last_item}/#{count})"
407 407 if per_page_links != false && links = per_page_links(paginator.items_per_page, count)
408 408 html << " | #{links}"
409 409 end
410 410 end
411 411
412 412 html.html_safe
413 413 end
414 414
415 415 def per_page_links(selected=nil, item_count=nil)
416 416 values = Setting.per_page_options_array
417 417 if item_count && values.any?
418 418 if item_count > values.first
419 419 max = values.detect {|value| value >= item_count} || item_count
420 420 else
421 421 max = item_count
422 422 end
423 423 values = values.select {|value| value <= max || value == selected}
424 424 end
425 425 if values.empty? || (values.size == 1 && values.first == selected)
426 426 return nil
427 427 end
428 428 links = values.collect do |n|
429 429 n == selected ? n : link_to_content_update(n, params.merge(:per_page => n))
430 430 end
431 431 l(:label_display_per_page, links.join(', '))
432 432 end
433 433
434 434 def reorder_links(name, url, method = :post)
435 435 link_to(image_tag('2uparrow.png', :alt => l(:label_sort_highest)),
436 436 url.merge({"#{name}[move_to]" => 'highest'}),
437 437 :method => method, :title => l(:label_sort_highest)) +
438 438 link_to(image_tag('1uparrow.png', :alt => l(:label_sort_higher)),
439 439 url.merge({"#{name}[move_to]" => 'higher'}),
440 440 :method => method, :title => l(:label_sort_higher)) +
441 441 link_to(image_tag('1downarrow.png', :alt => l(:label_sort_lower)),
442 442 url.merge({"#{name}[move_to]" => 'lower'}),
443 443 :method => method, :title => l(:label_sort_lower)) +
444 444 link_to(image_tag('2downarrow.png', :alt => l(:label_sort_lowest)),
445 445 url.merge({"#{name}[move_to]" => 'lowest'}),
446 446 :method => method, :title => l(:label_sort_lowest))
447 447 end
448 448
449 449 def breadcrumb(*args)
450 450 elements = args.flatten
451 451 elements.any? ? content_tag('p', (args.join(" \xc2\xbb ") + " \xc2\xbb ").html_safe, :class => 'breadcrumb') : nil
452 452 end
453 453
454 454 def other_formats_links(&block)
455 455 concat('<p class="other-formats">'.html_safe + l(:label_export_to))
456 456 yield Redmine::Views::OtherFormatsBuilder.new(self)
457 457 concat('</p>'.html_safe)
458 458 end
459 459
460 460 def page_header_title
461 461 if @project.nil? || @project.new_record?
462 462 h(Setting.app_title)
463 463 else
464 464 b = []
465 465 ancestors = (@project.root? ? [] : @project.ancestors.visible.all)
466 466 if ancestors.any?
467 467 root = ancestors.shift
468 468 b << link_to_project(root, {:jump => current_menu_item}, :class => 'root')
469 469 if ancestors.size > 2
470 470 b << "\xe2\x80\xa6"
471 471 ancestors = ancestors[-2, 2]
472 472 end
473 473 b += ancestors.collect {|p| link_to_project(p, {:jump => current_menu_item}, :class => 'ancestor') }
474 474 end
475 475 b << h(@project)
476 476 b.join(" \xc2\xbb ").html_safe
477 477 end
478 478 end
479 479
480 480 def html_title(*args)
481 481 if args.empty?
482 482 title = @html_title || []
483 483 title << @project.name if @project
484 484 title << Setting.app_title unless Setting.app_title == title.last
485 485 title.select {|t| !t.blank? }.join(' - ')
486 486 else
487 487 @html_title ||= []
488 488 @html_title += args
489 489 end
490 490 end
491 491
492 492 # Returns the theme, controller name, and action as css classes for the
493 493 # HTML body.
494 494 def body_css_classes
495 495 css = []
496 496 if theme = Redmine::Themes.theme(Setting.ui_theme)
497 497 css << 'theme-' + theme.name
498 498 end
499 499
500 500 css << 'controller-' + controller_name
501 501 css << 'action-' + action_name
502 502 css.join(' ')
503 503 end
504 504
505 505 def accesskey(s)
506 506 Redmine::AccessKeys.key_for s
507 507 end
508 508
509 509 # Formats text according to system settings.
510 510 # 2 ways to call this method:
511 511 # * with a String: textilizable(text, options)
512 512 # * with an object and one of its attribute: textilizable(issue, :description, options)
513 513 def textilizable(*args)
514 514 options = args.last.is_a?(Hash) ? args.pop : {}
515 515 case args.size
516 516 when 1
517 517 obj = options[:object]
518 518 text = args.shift
519 519 when 2
520 520 obj = args.shift
521 521 attr = args.shift
522 522 text = obj.send(attr).to_s
523 523 else
524 524 raise ArgumentError, 'invalid arguments to textilizable'
525 525 end
526 526 return '' if text.blank?
527 527 project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil)
528 528 only_path = options.delete(:only_path) == false ? false : true
529 529
530 530 text = text.dup
531 531 macros = catch_macros(text)
532 532 text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text, :object => obj, :attribute => attr)
533 533
534 534 @parsed_headings = []
535 535 @heading_anchors = {}
536 536 @current_section = 0 if options[:edit_section_links]
537 537
538 538 parse_sections(text, project, obj, attr, only_path, options)
539 539 text = parse_non_pre_blocks(text, obj, macros) do |text|
540 540 [:parse_inline_attachments, :parse_wiki_links, :parse_redmine_links].each do |method_name|
541 541 send method_name, text, project, obj, attr, only_path, options
542 542 end
543 543 end
544 544 parse_headings(text, project, obj, attr, only_path, options)
545 545
546 546 if @parsed_headings.any?
547 547 replace_toc(text, @parsed_headings)
548 548 end
549 549
550 550 text.html_safe
551 551 end
552 552
553 553 def parse_non_pre_blocks(text, obj, macros)
554 554 s = StringScanner.new(text)
555 555 tags = []
556 556 parsed = ''
557 557 while !s.eos?
558 558 s.scan(/(.*?)(<(\/)?(pre|code)(.*?)>|\z)/im)
559 559 text, full_tag, closing, tag = s[1], s[2], s[3], s[4]
560 560 if tags.empty?
561 561 yield text
562 562 inject_macros(text, obj, macros) if macros.any?
563 563 else
564 564 inject_macros(text, obj, macros, false) if macros.any?
565 565 end
566 566 parsed << text
567 567 if tag
568 568 if closing
569 569 if tags.last == tag.downcase
570 570 tags.pop
571 571 end
572 572 else
573 573 tags << tag.downcase
574 574 end
575 575 parsed << full_tag
576 576 end
577 577 end
578 578 # Close any non closing tags
579 579 while tag = tags.pop
580 580 parsed << "</#{tag}>"
581 581 end
582 582 parsed
583 583 end
584 584
585 585 def parse_inline_attachments(text, project, obj, attr, only_path, options)
586 586 # when using an image link, try to use an attachment, if possible
587 587 if options[:attachments] || (obj && obj.respond_to?(:attachments))
588 588 attachments = options[:attachments] || obj.attachments
589 589 text.gsub!(/src="([^\/"]+\.(bmp|gif|jpg|jpe|jpeg|png))"(\s+alt="([^"]*)")?/i) do |m|
590 590 filename, ext, alt, alttext = $1.downcase, $2, $3, $4
591 591 # search for the picture in attachments
592 592 if found = Attachment.latest_attach(attachments, filename)
593 593 image_url = url_for :only_path => only_path, :controller => 'attachments',
594 594 :action => 'download', :id => found
595 595 desc = found.description.to_s.gsub('"', '')
596 596 if !desc.blank? && alttext.blank?
597 597 alt = " title=\"#{desc}\" alt=\"#{desc}\""
598 598 end
599 599 "src=\"#{image_url}\"#{alt}"
600 600 else
601 601 m
602 602 end
603 603 end
604 604 end
605 605 end
606 606
607 607 # Wiki links
608 608 #
609 609 # Examples:
610 610 # [[mypage]]
611 611 # [[mypage|mytext]]
612 612 # wiki links can refer other project wikis, using project name or identifier:
613 613 # [[project:]] -> wiki starting page
614 614 # [[project:|mytext]]
615 615 # [[project:mypage]]
616 616 # [[project:mypage|mytext]]
617 617 def parse_wiki_links(text, project, obj, attr, only_path, options)
618 618 text.gsub!(/(!)?(\[\[([^\]\n\|]+)(\|([^\]\n\|]+))?\]\])/) do |m|
619 619 link_project = project
620 620 esc, all, page, title = $1, $2, $3, $5
621 621 if esc.nil?
622 622 if page =~ /^([^\:]+)\:(.*)$/
623 623 link_project = Project.find_by_identifier($1) || Project.find_by_name($1)
624 624 page = $2
625 625 title ||= $1 if page.blank?
626 626 end
627 627
628 628 if link_project && link_project.wiki
629 629 # extract anchor
630 630 anchor = nil
631 631 if page =~ /^(.+?)\#(.+)$/
632 632 page, anchor = $1, $2
633 633 end
634 634 anchor = sanitize_anchor_name(anchor) if anchor.present?
635 635 # check if page exists
636 636 wiki_page = link_project.wiki.find_page(page)
637 637 url = if anchor.present? && wiki_page.present? && (obj.is_a?(WikiContent) || obj.is_a?(WikiContent::Version)) && obj.page == wiki_page
638 638 "##{anchor}"
639 639 else
640 640 case options[:wiki_links]
641 641 when :local; "#{page.present? ? Wiki.titleize(page) : ''}.html" + (anchor.present? ? "##{anchor}" : '')
642 642 when :anchor; "##{page.present? ? Wiki.titleize(page) : title}" + (anchor.present? ? "_#{anchor}" : '') # used for single-file wiki export
643 643 else
644 644 wiki_page_id = page.present? ? Wiki.titleize(page) : nil
645 645 parent = wiki_page.nil? && obj.is_a?(WikiContent) && obj.page && project == link_project ? obj.page.title : nil
646 646 url_for(:only_path => only_path, :controller => 'wiki', :action => 'show', :project_id => link_project,
647 647 :id => wiki_page_id, :anchor => anchor, :parent => parent)
648 648 end
649 649 end
650 650 link_to(title.present? ? title.html_safe : h(page), url, :class => ('wiki-page' + (wiki_page ? '' : ' new')))
651 651 else
652 652 # project or wiki doesn't exist
653 653 all
654 654 end
655 655 else
656 656 all
657 657 end
658 658 end
659 659 end
660 660
661 661 # Redmine links
662 662 #
663 663 # Examples:
664 664 # Issues:
665 665 # #52 -> Link to issue #52
666 666 # Changesets:
667 667 # r52 -> Link to revision 52
668 668 # commit:a85130f -> Link to scmid starting with a85130f
669 669 # Documents:
670 670 # document#17 -> Link to document with id 17
671 671 # document:Greetings -> Link to the document with title "Greetings"
672 672 # document:"Some document" -> Link to the document with title "Some document"
673 673 # Versions:
674 674 # version#3 -> Link to version with id 3
675 675 # version:1.0.0 -> Link to version named "1.0.0"
676 676 # version:"1.0 beta 2" -> Link to version named "1.0 beta 2"
677 677 # Attachments:
678 678 # attachment:file.zip -> Link to the attachment of the current object named file.zip
679 679 # Source files:
680 680 # source:some/file -> Link to the file located at /some/file in the project's repository
681 681 # source:some/file@52 -> Link to the file's revision 52
682 682 # source:some/file#L120 -> Link to line 120 of the file
683 683 # source:some/file@52#L120 -> Link to line 120 of the file's revision 52
684 684 # export:some/file -> Force the download of the file
685 685 # Forum messages:
686 686 # message#1218 -> Link to message with id 1218
687 687 #
688 688 # Links can refer other objects from other projects, using project identifier:
689 689 # identifier:r52
690 690 # identifier:document:"Some document"
691 691 # identifier:version:1.0.0
692 692 # identifier:source:some/file
693 693 def parse_redmine_links(text, project, obj, attr, only_path, options)
694 694 text.gsub!(%r{([\s\(,\-\[\>]|^)(!)?(([a-z0-9\-_]+):)?(attachment|document|version|forum|news|message|project|commit|source|export)?(((#)|((([a-z0-9\-]+)\|)?(r)))((\d+)((#note)?-(\d+))?)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]][^A-Za-z0-9_/])|,|\s|\]|<|$)}) do |m|
695 695 leading, esc, project_prefix, project_identifier, prefix, repo_prefix, repo_identifier, sep, identifier, comment_suffix, comment_id = $1, $2, $3, $4, $5, $10, $11, $8 || $12 || $18, $14 || $19, $15, $17
696 696 link = nil
697 697 if project_identifier
698 698 project = Project.visible.find_by_identifier(project_identifier)
699 699 end
700 700 if esc.nil?
701 701 if prefix.nil? && sep == 'r'
702 702 if project
703 703 repository = nil
704 704 if repo_identifier
705 705 repository = project.repositories.detect {|repo| repo.identifier == repo_identifier}
706 706 else
707 707 repository = project.repository
708 708 end
709 709 # project.changesets.visible raises an SQL error because of a double join on repositories
710 710 if repository && (changeset = Changeset.visible.find_by_repository_id_and_revision(repository.id, identifier))
711 711 link = link_to(h("#{project_prefix}#{repo_prefix}r#{identifier}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :repository_id => repository.identifier_param, :rev => changeset.revision},
712 712 :class => 'changeset',
713 713 :title => truncate_single_line(changeset.comments, :length => 100))
714 714 end
715 715 end
716 716 elsif sep == '#'
717 717 oid = identifier.to_i
718 718 case prefix
719 719 when nil
720 720 if oid.to_s == identifier && issue = Issue.visible.find_by_id(oid, :include => :status)
721 721 anchor = comment_id ? "note-#{comment_id}" : nil
722 722 link = link_to("##{oid}", {:only_path => only_path, :controller => 'issues', :action => 'show', :id => oid, :anchor => anchor},
723 723 :class => issue.css_classes,
724 724 :title => "#{truncate(issue.subject, :length => 100)} (#{issue.status.name})")
725 725 end
726 726 when 'document'
727 727 if document = Document.visible.find_by_id(oid)
728 728 link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
729 729 :class => 'document'
730 730 end
731 731 when 'version'
732 732 if version = Version.visible.find_by_id(oid)
733 733 link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
734 734 :class => 'version'
735 735 end
736 736 when 'message'
737 737 if message = Message.visible.find_by_id(oid, :include => :parent)
738 738 link = link_to_message(message, {:only_path => only_path}, :class => 'message')
739 739 end
740 740 when 'forum'
741 741 if board = Board.visible.find_by_id(oid)
742 742 link = link_to h(board.name), {:only_path => only_path, :controller => 'boards', :action => 'show', :id => board, :project_id => board.project},
743 743 :class => 'board'
744 744 end
745 745 when 'news'
746 746 if news = News.visible.find_by_id(oid)
747 747 link = link_to h(news.title), {:only_path => only_path, :controller => 'news', :action => 'show', :id => news},
748 748 :class => 'news'
749 749 end
750 750 when 'project'
751 751 if p = Project.visible.find_by_id(oid)
752 752 link = link_to_project(p, {:only_path => only_path}, :class => 'project')
753 753 end
754 754 end
755 755 elsif sep == ':'
756 756 # removes the double quotes if any
757 757 name = identifier.gsub(%r{^"(.*)"$}, "\\1")
758 758 case prefix
759 759 when 'document'
760 760 if project && document = project.documents.visible.find_by_title(name)
761 761 link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
762 762 :class => 'document'
763 763 end
764 764 when 'version'
765 765 if project && version = project.versions.visible.find_by_name(name)
766 766 link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
767 767 :class => 'version'
768 768 end
769 769 when 'forum'
770 770 if project && board = project.boards.visible.find_by_name(name)
771 771 link = link_to h(board.name), {:only_path => only_path, :controller => 'boards', :action => 'show', :id => board, :project_id => board.project},
772 772 :class => 'board'
773 773 end
774 774 when 'news'
775 775 if project && news = project.news.visible.find_by_title(name)
776 776 link = link_to h(news.title), {:only_path => only_path, :controller => 'news', :action => 'show', :id => news},
777 777 :class => 'news'
778 778 end
779 779 when 'commit', 'source', 'export'
780 780 if project
781 781 repository = nil
782 782 if name =~ %r{^(([a-z0-9\-]+)\|)(.+)$}
783 783 repo_prefix, repo_identifier, name = $1, $2, $3
784 784 repository = project.repositories.detect {|repo| repo.identifier == repo_identifier}
785 785 else
786 786 repository = project.repository
787 787 end
788 788 if prefix == 'commit'
789 789 if repository && (changeset = Changeset.visible.find(:first, :conditions => ["repository_id = ? AND scmid LIKE ?", repository.id, "#{name}%"]))
790 790 link = link_to h("#{project_prefix}#{repo_prefix}#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :repository_id => repository.identifier_param, :rev => changeset.identifier},
791 791 :class => 'changeset',
792 792 :title => truncate_single_line(h(changeset.comments), :length => 100)
793 793 end
794 794 else
795 795 if repository && User.current.allowed_to?(:browse_repository, project)
796 796 name =~ %r{^[/\\]*(.*?)(@([0-9a-f]+))?(#(L\d+))?$}
797 797 path, rev, anchor = $1, $3, $5
798 798 link = link_to h("#{project_prefix}#{prefix}:#{repo_prefix}#{name}"), {:controller => 'repositories', :action => 'entry', :id => project, :repository_id => repository.identifier_param,
799 799 :path => to_path_param(path),
800 800 :rev => rev,
801 801 :anchor => anchor,
802 802 :format => (prefix == 'export' ? 'raw' : nil)},
803 803 :class => (prefix == 'export' ? 'source download' : 'source')
804 804 end
805 805 end
806 806 repo_prefix = nil
807 807 end
808 808 when 'attachment'
809 809 attachments = options[:attachments] || (obj && obj.respond_to?(:attachments) ? obj.attachments : nil)
810 810 if attachments && attachment = attachments.detect {|a| a.filename == name }
811 811 link = link_to h(attachment.filename), {:only_path => only_path, :controller => 'attachments', :action => 'download', :id => attachment},
812 812 :class => 'attachment'
813 813 end
814 814 when 'project'
815 815 if p = Project.visible.find(:first, :conditions => ["identifier = :s OR LOWER(name) = :s", {:s => name.downcase}])
816 816 link = link_to_project(p, {:only_path => only_path}, :class => 'project')
817 817 end
818 818 end
819 819 end
820 820 end
821 821 (leading + (link || "#{project_prefix}#{prefix}#{repo_prefix}#{sep}#{identifier}#{comment_suffix}"))
822 822 end
823 823 end
824 824
825 825 HEADING_RE = /(<h(1|2|3|4)( [^>]+)?>(.+?)<\/h(1|2|3|4)>)/i unless const_defined?(:HEADING_RE)
826 826
827 827 def parse_sections(text, project, obj, attr, only_path, options)
828 828 return unless options[:edit_section_links]
829 829 text.gsub!(HEADING_RE) do
830 830 heading = $1
831 831 @current_section += 1
832 832 if @current_section > 1
833 833 content_tag('div',
834 834 link_to(image_tag('edit.png'), options[:edit_section_links].merge(:section => @current_section)),
835 835 :class => 'contextual',
836 836 :title => l(:button_edit_section)) + heading.html_safe
837 837 else
838 838 heading
839 839 end
840 840 end
841 841 end
842 842
843 843 # Headings and TOC
844 844 # Adds ids and links to headings unless options[:headings] is set to false
845 845 def parse_headings(text, project, obj, attr, only_path, options)
846 846 return if options[:headings] == false
847 847
848 848 text.gsub!(HEADING_RE) do
849 849 level, attrs, content = $2.to_i, $3, $4
850 850 item = strip_tags(content).strip
851 851 anchor = sanitize_anchor_name(item)
852 852 # used for single-file wiki export
853 853 anchor = "#{obj.page.title}_#{anchor}" if options[:wiki_links] == :anchor && (obj.is_a?(WikiContent) || obj.is_a?(WikiContent::Version))
854 854 @heading_anchors[anchor] ||= 0
855 855 idx = (@heading_anchors[anchor] += 1)
856 856 if idx > 1
857 857 anchor = "#{anchor}-#{idx}"
858 858 end
859 859 @parsed_headings << [level, anchor, item]
860 860 "<a name=\"#{anchor}\"></a>\n<h#{level} #{attrs}>#{content}<a href=\"##{anchor}\" class=\"wiki-anchor\">&para;</a></h#{level}>"
861 861 end
862 862 end
863 863
864 864 MACROS_RE = /(
865 865 (!)? # escaping
866 866 (
867 867 \{\{ # opening tag
868 868 ([\w]+) # macro name
869 869 (\(([^\n\r]*?)\))? # optional arguments
870 870 ([\n\r].*[\n\r])? # optional block of text
871 871 \}\} # closing tag
872 872 )
873 873 )/mx unless const_defined?(:MACROS_RE)
874 874
875 875 MACRO_SUB_RE = /(
876 876 \{\{
877 877 macro\((\d+)\)
878 878 \}\}
879 879 )/x unless const_defined?(:MACROS_SUB_RE)
880 880
881 881 # Extracts macros from text
882 882 def catch_macros(text)
883 883 macros = {}
884 884 text.gsub!(MACROS_RE) do
885 885 all, macro = $1, $4.downcase
886 886 if macro_exists?(macro) || all =~ MACRO_SUB_RE
887 887 index = macros.size
888 888 macros[index] = all
889 889 "{{macro(#{index})}}"
890 890 else
891 891 all
892 892 end
893 893 end
894 894 macros
895 895 end
896 896
897 897 # Executes and replaces macros in text
898 898 def inject_macros(text, obj, macros, execute=true)
899 899 text.gsub!(MACRO_SUB_RE) do
900 900 all, index = $1, $2.to_i
901 901 orig = macros.delete(index)
902 902 if execute && orig && orig =~ MACROS_RE
903 903 esc, all, macro, args, block = $2, $3, $4.downcase, $6.to_s, $7.try(:strip)
904 904 if esc.nil?
905 905 h(exec_macro(macro, obj, args, block) || all)
906 906 else
907 907 h(all)
908 908 end
909 909 elsif orig
910 910 h(orig)
911 911 else
912 912 h(all)
913 913 end
914 914 end
915 915 end
916 916
917 917 TOC_RE = /<p>\{\{([<>]?)toc\}\}<\/p>/i unless const_defined?(:TOC_RE)
918 918
919 919 # Renders the TOC with given headings
920 920 def replace_toc(text, headings)
921 921 text.gsub!(TOC_RE) do
922 922 if headings.empty?
923 923 ''
924 924 else
925 925 div_class = 'toc'
926 926 div_class << ' right' if $1 == '>'
927 927 div_class << ' left' if $1 == '<'
928 928 out = "<ul class=\"#{div_class}\"><li>"
929 929 root = headings.map(&:first).min
930 930 current = root
931 931 started = false
932 932 headings.each do |level, anchor, item|
933 933 if level > current
934 934 out << '<ul><li>' * (level - current)
935 935 elsif level < current
936 936 out << "</li></ul>\n" * (current - level) + "</li><li>"
937 937 elsif started
938 938 out << '</li><li>'
939 939 end
940 940 out << "<a href=\"##{anchor}\">#{item}</a>"
941 941 current = level
942 942 started = true
943 943 end
944 944 out << '</li></ul>' * (current - root)
945 945 out << '</li></ul>'
946 946 end
947 947 end
948 948 end
949 949
950 950 # Same as Rails' simple_format helper without using paragraphs
951 951 def simple_format_without_paragraph(text)
952 952 text.to_s.
953 953 gsub(/\r\n?/, "\n"). # \r\n and \r -> \n
954 954 gsub(/\n\n+/, "<br /><br />"). # 2+ newline -> 2 br
955 955 gsub(/([^\n]\n)(?=[^\n])/, '\1<br />'). # 1 newline -> br
956 956 html_safe
957 957 end
958 958
959 959 def lang_options_for_select(blank=true)
960 960 (blank ? [["(auto)", ""]] : []) +
961 961 valid_languages.collect{|lang| [ ll(lang.to_s, :general_lang_name), lang.to_s]}.sort{|x,y| x.last <=> y.last }
962 962 end
963 963
964 964 def label_tag_for(name, option_tags = nil, options = {})
965 965 label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
966 966 content_tag("label", label_text)
967 967 end
968 968
969 969 def labelled_form_for(*args, &proc)
970 970 args << {} unless args.last.is_a?(Hash)
971 971 options = args.last
972 972 if args.first.is_a?(Symbol)
973 973 options.merge!(:as => args.shift)
974 974 end
975 975 options.merge!({:builder => Redmine::Views::LabelledFormBuilder})
976 976 form_for(*args, &proc)
977 977 end
978 978
979 979 def labelled_fields_for(*args, &proc)
980 980 args << {} unless args.last.is_a?(Hash)
981 981 options = args.last
982 982 options.merge!({:builder => Redmine::Views::LabelledFormBuilder})
983 983 fields_for(*args, &proc)
984 984 end
985 985
986 986 def labelled_remote_form_for(*args, &proc)
987 987 ActiveSupport::Deprecation.warn "ApplicationHelper#labelled_remote_form_for is deprecated and will be removed in Redmine 2.2."
988 988 args << {} unless args.last.is_a?(Hash)
989 989 options = args.last
990 990 options.merge!({:builder => Redmine::Views::LabelledFormBuilder, :remote => true})
991 991 form_for(*args, &proc)
992 992 end
993 993
994 994 def error_messages_for(*objects)
995 995 html = ""
996 996 objects = objects.map {|o| o.is_a?(String) ? instance_variable_get("@#{o}") : o}.compact
997 997 errors = objects.map {|o| o.errors.full_messages}.flatten
998 998 if errors.any?
999 999 html << "<div id='errorExplanation'><ul>\n"
1000 1000 errors.each do |error|
1001 1001 html << "<li>#{h error}</li>\n"
1002 1002 end
1003 1003 html << "</ul></div>\n"
1004 1004 end
1005 1005 html.html_safe
1006 1006 end
1007 1007
1008 1008 def delete_link(url, options={})
1009 1009 options = {
1010 1010 :method => :delete,
1011 1011 :data => {:confirm => l(:text_are_you_sure)},
1012 1012 :class => 'icon icon-del'
1013 1013 }.merge(options)
1014 1014
1015 1015 link_to l(:button_delete), url, options
1016 1016 end
1017 1017
1018 1018 def preview_link(url, form, target='preview', options={})
1019 1019 content_tag 'a', l(:label_preview), {
1020 1020 :href => "#",
1021 1021 :onclick => %|submitPreview("#{escape_javascript url_for(url)}", "#{escape_javascript form}", "#{escape_javascript target}"); return false;|,
1022 1022 :accesskey => accesskey(:preview)
1023 1023 }.merge(options)
1024 1024 end
1025 1025
1026 1026 def link_to_function(name, function, html_options={})
1027 1027 content_tag(:a, name, {:href => '#', :onclick => "#{function}; return false;"}.merge(html_options))
1028 1028 end
1029 1029
1030 1030 def back_url
1031 1031 url = params[:back_url]
1032 1032 if url.nil? && referer = request.env['HTTP_REFERER']
1033 1033 url = CGI.unescape(referer.to_s)
1034 1034 end
1035 1035 url
1036 1036 end
1037 1037
1038 1038 def back_url_hidden_field_tag
1039 1039 url = back_url
1040 1040 hidden_field_tag('back_url', url, :id => nil) unless url.blank?
1041 1041 end
1042 1042
1043 1043 def check_all_links(form_name)
1044 1044 link_to_function(l(:button_check_all), "checkAll('#{form_name}', true)") +
1045 1045 " | ".html_safe +
1046 1046 link_to_function(l(:button_uncheck_all), "checkAll('#{form_name}', false)")
1047 1047 end
1048 1048
1049 1049 def progress_bar(pcts, options={})
1050 1050 pcts = [pcts, pcts] unless pcts.is_a?(Array)
1051 1051 pcts = pcts.collect(&:round)
1052 1052 pcts[1] = pcts[1] - pcts[0]
1053 1053 pcts << (100 - pcts[1] - pcts[0])
1054 1054 width = options[:width] || '100px;'
1055 1055 legend = options[:legend] || ''
1056 1056 content_tag('table',
1057 1057 content_tag('tr',
1058 1058 (pcts[0] > 0 ? content_tag('td', '', :style => "width: #{pcts[0]}%;", :class => 'closed') : ''.html_safe) +
1059 1059 (pcts[1] > 0 ? content_tag('td', '', :style => "width: #{pcts[1]}%;", :class => 'done') : ''.html_safe) +
1060 1060 (pcts[2] > 0 ? content_tag('td', '', :style => "width: #{pcts[2]}%;", :class => 'todo') : ''.html_safe)
1061 1061 ), :class => 'progress', :style => "width: #{width};").html_safe +
1062 1062 content_tag('p', legend, :class => 'pourcent').html_safe
1063 1063 end
1064 1064
1065 1065 def checked_image(checked=true)
1066 1066 if checked
1067 1067 image_tag 'toggle_check.png'
1068 1068 end
1069 1069 end
1070 1070
1071 1071 def context_menu(url)
1072 1072 unless @context_menu_included
1073 1073 content_for :header_tags do
1074 1074 javascript_include_tag('context_menu') +
1075 1075 stylesheet_link_tag('context_menu')
1076 1076 end
1077 1077 if l(:direction) == 'rtl'
1078 1078 content_for :header_tags do
1079 1079 stylesheet_link_tag('context_menu_rtl')
1080 1080 end
1081 1081 end
1082 1082 @context_menu_included = true
1083 1083 end
1084 1084 javascript_tag "contextMenuInit('#{ url_for(url) }')"
1085 1085 end
1086 1086
1087 1087 def calendar_for(field_id)
1088 1088 include_calendar_headers_tags
1089 1089 javascript_tag("$(function() { $('##{field_id}').datepicker(datepickerOptions); });")
1090 1090 end
1091 1091
1092 1092 def include_calendar_headers_tags
1093 1093 unless @calendar_headers_tags_included
1094 1094 @calendar_headers_tags_included = true
1095 1095 content_for :header_tags do
1096 1096 tags = javascript_tag("var datepickerOptions={dateFormat: 'yy-mm-dd', showOn: 'button', buttonImageOnly: true, buttonImage: '" + path_to_image('/images/calendar.png') + "'};")
1097 1097 jquery_locale = l('jquery.locale', :default => current_language.to_s)
1098 1098 unless jquery_locale == 'en'
1099 1099 tags << javascript_include_tag("i18n/jquery.ui.datepicker-#{jquery_locale}.js")
1100 1100 end
1101 1101 tags
1102 1102 end
1103 1103 end
1104 1104 end
1105 1105
1106 1106 # Overrides Rails' stylesheet_link_tag with themes and plugins support.
1107 1107 # Examples:
1108 1108 # stylesheet_link_tag('styles') # => picks styles.css from the current theme or defaults
1109 1109 # stylesheet_link_tag('styles', :plugin => 'foo) # => picks styles.css from plugin's assets
1110 1110 #
1111 1111 def stylesheet_link_tag(*sources)
1112 1112 options = sources.last.is_a?(Hash) ? sources.pop : {}
1113 1113 plugin = options.delete(:plugin)
1114 1114 sources = sources.map do |source|
1115 1115 if plugin
1116 1116 "/plugin_assets/#{plugin}/stylesheets/#{source}"
1117 1117 elsif current_theme && current_theme.stylesheets.include?(source)
1118 1118 current_theme.stylesheet_path(source)
1119 1119 else
1120 1120 source
1121 1121 end
1122 1122 end
1123 1123 super sources, options
1124 1124 end
1125 1125
1126 1126 # Overrides Rails' image_tag with themes and plugins support.
1127 1127 # Examples:
1128 1128 # image_tag('image.png') # => picks image.png from the current theme or defaults
1129 1129 # image_tag('image.png', :plugin => 'foo) # => picks image.png from plugin's assets
1130 1130 #
1131 1131 def image_tag(source, options={})
1132 1132 if plugin = options.delete(:plugin)
1133 1133 source = "/plugin_assets/#{plugin}/images/#{source}"
1134 1134 elsif current_theme && current_theme.images.include?(source)
1135 1135 source = current_theme.image_path(source)
1136 1136 end
1137 1137 super source, options
1138 1138 end
1139 1139
1140 1140 # Overrides Rails' javascript_include_tag with plugins support
1141 1141 # Examples:
1142 1142 # javascript_include_tag('scripts') # => picks scripts.js from defaults
1143 1143 # javascript_include_tag('scripts', :plugin => 'foo) # => picks scripts.js from plugin's assets
1144 1144 #
1145 1145 def javascript_include_tag(*sources)
1146 1146 options = sources.last.is_a?(Hash) ? sources.pop : {}
1147 1147 if plugin = options.delete(:plugin)
1148 1148 sources = sources.map do |source|
1149 1149 if plugin
1150 1150 "/plugin_assets/#{plugin}/javascripts/#{source}"
1151 1151 else
1152 1152 source
1153 1153 end
1154 1154 end
1155 1155 end
1156 1156 super sources, options
1157 1157 end
1158 1158
1159 1159 def content_for(name, content = nil, &block)
1160 1160 @has_content ||= {}
1161 1161 @has_content[name] = true
1162 1162 super(name, content, &block)
1163 1163 end
1164 1164
1165 1165 def has_content?(name)
1166 1166 (@has_content && @has_content[name]) || false
1167 1167 end
1168 1168
1169 1169 def sidebar_content?
1170 1170 has_content?(:sidebar) || view_layouts_base_sidebar_hook_response.present?
1171 1171 end
1172 1172
1173 1173 def view_layouts_base_sidebar_hook_response
1174 1174 @view_layouts_base_sidebar_hook_response ||= call_hook(:view_layouts_base_sidebar)
1175 1175 end
1176 1176
1177 1177 def email_delivery_enabled?
1178 1178 !!ActionMailer::Base.perform_deliveries
1179 1179 end
1180 1180
1181 1181 # Returns the avatar image tag for the given +user+ if avatars are enabled
1182 1182 # +user+ can be a User or a string that will be scanned for an email address (eg. 'joe <joe@foo.bar>')
1183 1183 def avatar(user, options = { })
1184 1184 if Setting.gravatar_enabled?
1185 1185 options.merge!({:ssl => (request && request.ssl?), :default => Setting.gravatar_default})
1186 1186 email = nil
1187 1187 if user.respond_to?(:mail)
1188 1188 email = user.mail
1189 1189 elsif user.to_s =~ %r{<(.+?)>}
1190 1190 email = $1
1191 1191 end
1192 1192 return gravatar(email.to_s.downcase, options) unless email.blank? rescue nil
1193 1193 else
1194 1194 ''
1195 1195 end
1196 1196 end
1197 1197
1198 1198 def sanitize_anchor_name(anchor)
1199 1199 if ''.respond_to?(:encoding) || RUBY_PLATFORM == 'java'
1200 1200 anchor.gsub(%r{[^\p{Word}\s\-]}, '').gsub(%r{\s+(\-+\s*)?}, '-')
1201 1201 else
1202 1202 # TODO: remove when ruby1.8 is no longer supported
1203 1203 anchor.gsub(%r{[^\w\s\-]}, '').gsub(%r{\s+(\-+\s*)?}, '-')
1204 1204 end
1205 1205 end
1206 1206
1207 1207 # Returns the javascript tags that are included in the html layout head
1208 1208 def javascript_heads
1209 tags = javascript_include_tag('jquery-1.7.2-ui-1.8.21-ujs-2.0.2', 'application')
1209 tags = javascript_include_tag('jquery-1.7.2-ui-1.8.21-ujs-2.0.3', 'application')
1210 1210 unless User.current.pref.warn_on_leaving_unsaved == '0'
1211 1211 tags << "\n".html_safe + javascript_tag("$(window).load(function(){ warnLeavingUnsaved('#{escape_javascript l(:text_warn_on_leaving_unsaved)}'); });")
1212 1212 end
1213 1213 tags
1214 1214 end
1215 1215
1216 1216 def favicon
1217 1217 "<link rel='shortcut icon' href='#{image_path('/favicon.ico')}' />".html_safe
1218 1218 end
1219 1219
1220 1220 def robot_exclusion_tag
1221 1221 '<meta name="robots" content="noindex,follow,noarchive" />'.html_safe
1222 1222 end
1223 1223
1224 1224 # Returns true if arg is expected in the API response
1225 1225 def include_in_api_response?(arg)
1226 1226 unless @included_in_api_response
1227 1227 param = params[:include]
1228 1228 @included_in_api_response = param.is_a?(Array) ? param.collect(&:to_s) : param.to_s.split(',')
1229 1229 @included_in_api_response.collect!(&:strip)
1230 1230 end
1231 1231 @included_in_api_response.include?(arg.to_s)
1232 1232 end
1233 1233
1234 1234 # Returns options or nil if nometa param or X-Redmine-Nometa header
1235 1235 # was set in the request
1236 1236 def api_meta(options)
1237 1237 if params[:nometa].present? || request.headers['X-Redmine-Nometa']
1238 1238 # compatibility mode for activeresource clients that raise
1239 1239 # an error when unserializing an array with attributes
1240 1240 nil
1241 1241 else
1242 1242 options
1243 1243 end
1244 1244 end
1245 1245
1246 1246 private
1247 1247
1248 1248 def wiki_helper
1249 1249 helper = Redmine::WikiFormatting.helper_for(Setting.text_formatting)
1250 1250 extend helper
1251 1251 return self
1252 1252 end
1253 1253
1254 1254 def link_to_content_update(text, url_params = {}, html_options = {})
1255 1255 link_to(text, url_params, html_options)
1256 1256 end
1257 1257 end
@@ -1,6 +1,6
1 1 <% if @membership.valid? %>
2 2 $('#tab-content-memberships').html('<%= escape_javascript(render :partial => 'groups/memberships') %>');
3 3 $('#member-<%= @membership.id %>').effect("highlight");
4 4 <% else %>
5 alert('<%= escape_javascript(l(:notice_failed_to_save_members, :errors => @membership.errors.full_messages.join(', '))) %>');
5 alert('<%= raw(escape_javascript(l(:notice_failed_to_save_members, :errors => @membership.errors.full_messages.join(', ')))) %>');
6 6 <% end %>
@@ -1,11 +1,11
1 1 $('#tab-content-members').html('<%= escape_javascript(render :partial => 'projects/settings/members') %>');
2 2 hideOnLoad();
3 3
4 4 <% if @members.present? && @members.all? {|m| m.valid? } %>
5 5 <% @members.each do |member| %>
6 6 $("#member-<%= member.id %>").effect("highlight");
7 7 <% end %>
8 8 <% else %>
9 9 <% errors = @members.collect {|m| m.errors.full_messages}.flatten.uniq.join(', ') %>
10 alert('<%= escape_javascript l(:notice_failed_to_save_members, :errors => errors) %>');
10 alert('<%= raw(escape_javascript(l(:notice_failed_to_save_members, :errors => errors))) %>');
11 11 <% end %>
@@ -1,6 +1,6
1 1 <% if @membership.valid? %>
2 2 $('#tab-content-memberships').html('<%= escape_javascript(render :partial => 'users/memberships') %>');
3 3 $("#member-<%= @membership.id %>").effect("highlight");
4 4 <% else %>
5 alert('<%= escape_javascript l(:notice_failed_to_save_members, :errors => @membership.errors.full_messages.join(', ')) %>');
5 alert('<%= raw(escape_javascript(l(:notice_failed_to_save_members, :errors => @membership.errors.full_messages.join(', ')))) %>');
6 6 <% end %>
1 NO CONTENT: file renamed from public/javascripts/jquery-1.7.2-ui-1.8.21-ujs-2.0.2.js to public/javascripts/jquery-1.7.2-ui-1.8.21-ujs-2.0.3.js
The requested commit or file is too big and content was truncated. Show full diff
@@ -1,152 +1,152
1 1 require File.expand_path('../../test_helper', __FILE__)
2 2
3 3 class ActivitiesControllerTest < ActionController::TestCase
4 4 fixtures :projects, :trackers, :issue_statuses, :issues,
5 5 :enumerations, :users, :issue_categories,
6 6 :projects_trackers,
7 7 :roles,
8 8 :member_roles,
9 9 :members,
10 10 :groups_users,
11 11 :enabled_modules,
12 12 :workflows,
13 13 :journals, :journal_details
14 14
15 15
16 16 def test_project_index
17 17 get :index, :id => 1, :with_subprojects => 0
18 18 assert_response :success
19 19 assert_template 'index'
20 20 assert_not_nil assigns(:events_by_day)
21 21
22 22 assert_tag :tag => "h3",
23 23 :content => /#{2.days.ago.to_date.day}/,
24 24 :sibling => { :tag => "dl",
25 25 :child => { :tag => "dt",
26 26 :attributes => { :class => /issue-edit/ },
27 27 :child => { :tag => "a",
28 28 :content => /(#{IssueStatus.find(2).name})/,
29 29 }
30 30 }
31 31 }
32 32 end
33 33
34 34 def test_project_index_with_invalid_project_id_should_respond_404
35 35 get :index, :id => 299
36 36 assert_response 404
37 37 end
38 38
39 39 def test_previous_project_index
40 40 get :index, :id => 1, :from => 3.days.ago.to_date
41 41 assert_response :success
42 42 assert_template 'index'
43 43 assert_not_nil assigns(:events_by_day)
44 44
45 45 assert_tag :tag => "h3",
46 46 :content => /#{3.day.ago.to_date.day}/,
47 47 :sibling => { :tag => "dl",
48 48 :child => { :tag => "dt",
49 49 :attributes => { :class => /issue/ },
50 50 :child => { :tag => "a",
51 :content => /#{Issue.find(1).subject}/,
51 :content => /Can&#x27;t print recipes/,
52 52 }
53 53 }
54 54 }
55 55 end
56 56
57 57 def test_global_index
58 58 @request.session[:user_id] = 1
59 59 get :index
60 60 assert_response :success
61 61 assert_template 'index'
62 62 assert_not_nil assigns(:events_by_day)
63 63
64 64 i5 = Issue.find(5)
65 65 d5 = User.find(1).time_to_date(i5.created_on)
66 66 assert_tag :tag => "h3",
67 67 :content => /#{d5.day}/,
68 68 :sibling => { :tag => "dl",
69 69 :child => { :tag => "dt",
70 70 :attributes => { :class => /issue/ },
71 71 :child => { :tag => "a",
72 :content => /#{Issue.find(5).subject}/,
72 :content => /Subproject issue/,
73 73 }
74 74 }
75 75 }
76 76 end
77 77
78 78 def test_user_index
79 79 @request.session[:user_id] = 1
80 80 get :index, :user_id => 2
81 81 assert_response :success
82 82 assert_template 'index'
83 83 assert_not_nil assigns(:events_by_day)
84 84
85 85 assert_select 'h2 a[href=/users/2]', :text => 'John Smith'
86 86
87 87 i1 = Issue.find(1)
88 88 d1 = User.find(1).time_to_date(i1.created_on)
89 89
90 90 assert_tag :tag => "h3",
91 91 :content => /#{d1.day}/,
92 92 :sibling => { :tag => "dl",
93 93 :child => { :tag => "dt",
94 94 :attributes => { :class => /issue/ },
95 95 :child => { :tag => "a",
96 :content => /#{Issue.find(1).subject}/,
96 :content => /Can&#x27;t print recipes/,
97 97 }
98 98 }
99 99 }
100 100 end
101 101
102 102 def test_user_index_with_invalid_user_id_should_respond_404
103 103 get :index, :user_id => 299
104 104 assert_response 404
105 105 end
106 106
107 107 def test_index_atom_feed
108 108 get :index, :format => 'atom', :with_subprojects => 0
109 109 assert_response :success
110 110 assert_template 'common/feed'
111 111
112 112 assert_tag :tag => 'link', :parent => {:tag => 'feed', :parent => nil },
113 113 :attributes => {:rel => 'self', :href => 'http://test.host/activity.atom?with_subprojects=0'}
114 114 assert_tag :tag => 'link', :parent => {:tag => 'feed', :parent => nil },
115 115 :attributes => {:rel => 'alternate', :href => 'http://test.host/activity?with_subprojects=0'}
116 116
117 117 assert_tag :tag => 'entry', :child => {
118 118 :tag => 'link',
119 119 :attributes => {:href => 'http://test.host/issues/11'}}
120 120 end
121 121
122 122 def test_index_atom_feed_with_explicit_selection
123 123 get :index, :format => 'atom', :with_subprojects => 0,
124 124 :show_changesets => 1,
125 125 :show_documents => 1,
126 126 :show_files => 1,
127 127 :show_issues => 1,
128 128 :show_messages => 1,
129 129 :show_news => 1,
130 130 :show_time_entries => 1,
131 131 :show_wiki_edits => 1
132 132
133 133 assert_response :success
134 134 assert_template 'common/feed'
135 135
136 136 assert_tag :tag => 'link', :parent => {:tag => 'feed', :parent => nil },
137 137 :attributes => {:rel => 'self', :href => 'http://test.host/activity.atom?show_changesets=1&amp;show_documents=1&amp;show_files=1&amp;show_issues=1&amp;show_messages=1&amp;show_news=1&amp;show_time_entries=1&amp;show_wiki_edits=1&amp;with_subprojects=0'}
138 138 assert_tag :tag => 'link', :parent => {:tag => 'feed', :parent => nil },
139 139 :attributes => {:rel => 'alternate', :href => 'http://test.host/activity?show_changesets=1&amp;show_documents=1&amp;show_files=1&amp;show_issues=1&amp;show_messages=1&amp;show_news=1&amp;show_time_entries=1&amp;show_wiki_edits=1&amp;with_subprojects=0'}
140 140
141 141 assert_tag :tag => 'entry', :child => {
142 142 :tag => 'link',
143 143 :attributes => {:href => 'http://test.host/issues/11'}}
144 144 end
145 145
146 146 def test_index_atom_feed_with_one_item_type
147 147 get :index, :format => 'atom', :show_issues => '1'
148 148 assert_response :success
149 149 assert_template 'common/feed'
150 150 assert_tag :tag => 'title', :content => /Issues/
151 151 end
152 152 end
@@ -1,127 +1,127
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19
20 20 class AuthSourcesControllerTest < ActionController::TestCase
21 21 fixtures :users, :auth_sources
22 22
23 23 def setup
24 24 @request.session[:user_id] = 1
25 25 end
26 26
27 27 def test_index
28 28 get :index
29 29
30 30 assert_response :success
31 31 assert_template 'index'
32 32 assert_not_nil assigns(:auth_sources)
33 33 end
34 34
35 35 def test_new
36 36 get :new
37 37
38 38 assert_response :success
39 39 assert_template 'new'
40 40
41 41 source = assigns(:auth_source)
42 42 assert_equal AuthSourceLdap, source.class
43 43 assert source.new_record?
44 44
45 45 assert_tag 'input', :attributes => {:name => 'type', :value => 'AuthSourceLdap'}
46 46 assert_tag 'input', :attributes => {:name => 'auth_source[host]'}
47 47 end
48 48
49 49 def test_create
50 50 assert_difference 'AuthSourceLdap.count' do
51 51 post :create, :type => 'AuthSourceLdap', :auth_source => {:name => 'Test', :host => '127.0.0.1', :port => '389', :attr_login => 'cn'}
52 52 assert_redirected_to '/auth_sources'
53 53 end
54 54
55 55 source = AuthSourceLdap.first(:order => 'id DESC')
56 56 assert_equal 'Test', source.name
57 57 assert_equal '127.0.0.1', source.host
58 58 assert_equal 389, source.port
59 59 assert_equal 'cn', source.attr_login
60 60 end
61 61
62 62 def test_create_with_failure
63 63 assert_no_difference 'AuthSourceLdap.count' do
64 64 post :create, :type => 'AuthSourceLdap', :auth_source => {:name => 'Test', :host => '', :port => '389', :attr_login => 'cn'}
65 65 assert_response :success
66 66 assert_template 'new'
67 67 end
68 assert_error_tag :content => /host can't be blank/i
68 assert_error_tag :content => /host can&#x27;t be blank/i
69 69 end
70 70
71 71 def test_edit
72 72 get :edit, :id => 1
73 73
74 74 assert_response :success
75 75 assert_template 'edit'
76 76
77 77 assert_tag 'input', :attributes => {:name => 'auth_source[host]'}
78 78 end
79 79
80 80 def test_update
81 81 put :update, :id => 1, :auth_source => {:name => 'Renamed', :host => '192.168.0.10', :port => '389', :attr_login => 'uid'}
82 82 assert_redirected_to '/auth_sources'
83 83
84 84 source = AuthSourceLdap.find(1)
85 85 assert_equal 'Renamed', source.name
86 86 assert_equal '192.168.0.10', source.host
87 87 end
88 88
89 89 def test_update_with_failure
90 90 put :update, :id => 1, :auth_source => {:name => 'Renamed', :host => '', :port => '389', :attr_login => 'uid'}
91 91 assert_response :success
92 92 assert_template 'edit'
93 assert_error_tag :content => /host can't be blank/i
93 assert_error_tag :content => /host can&#x27;t be blank/i
94 94 end
95 95
96 96 def test_destroy
97 97 assert_difference 'AuthSourceLdap.count', -1 do
98 98 delete :destroy, :id => 1
99 99 end
100 100 end
101 101
102 102 def test_destroy_auth_source_in_use
103 103 User.find(2).update_attribute :auth_source_id, 1
104 104
105 105 assert_no_difference 'AuthSourceLdap.count' do
106 106 delete :destroy, :id => 1
107 107 end
108 108 end
109 109
110 110 def test_test_connection
111 111 AuthSourceLdap.any_instance.stubs(:test_connection).returns(true)
112 112
113 113 get :test_connection, :id => 1
114 114 assert_redirected_to '/auth_sources'
115 115 assert_not_nil flash[:notice]
116 116 assert_match /successful/i, flash[:notice]
117 117 end
118 118
119 119 def test_test_connection_with_failure
120 120 AuthSourceLdap.any_instance.stubs(:initialize_ldap_con).raises(Net::LDAP::LdapError.new("Something went wrong"))
121 121
122 122 get :test_connection, :id => 1
123 123 assert_redirected_to '/auth_sources'
124 124 assert_not_nil flash[:error]
125 125 assert_include 'Something went wrong', flash[:error]
126 126 end
127 127 end
@@ -1,114 +1,114
1 1 require File.expand_path('../../test_helper', __FILE__)
2 2 require 'issue_statuses_controller'
3 3
4 4 # Re-raise errors caught by the controller.
5 5 class IssueStatusesController; def rescue_action(e) raise e end; end
6 6
7 7
8 8 class IssueStatusesControllerTest < ActionController::TestCase
9 9 fixtures :issue_statuses, :issues
10 10
11 11 def setup
12 12 @controller = IssueStatusesController.new
13 13 @request = ActionController::TestRequest.new
14 14 @response = ActionController::TestResponse.new
15 15 User.current = nil
16 16 @request.session[:user_id] = 1 # admin
17 17 end
18 18
19 19 def test_index
20 20 get :index
21 21 assert_response :success
22 22 assert_template 'index'
23 23 end
24 24
25 25 def test_index_by_anonymous_should_redirect_to_login_form
26 26 @request.session[:user_id] = nil
27 27 get :index
28 28 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fissue_statuses'
29 29 end
30 30
31 31 def test_index_by_user_should_respond_with_406
32 32 @request.session[:user_id] = 2
33 33 get :index
34 34 assert_response 406
35 35 end
36 36
37 37 def test_new
38 38 get :new
39 39 assert_response :success
40 40 assert_template 'new'
41 41 end
42 42
43 43 def test_create
44 44 assert_difference 'IssueStatus.count' do
45 45 post :create, :issue_status => {:name => 'New status'}
46 46 end
47 47 assert_redirected_to :action => 'index'
48 48 status = IssueStatus.find(:first, :order => 'id DESC')
49 49 assert_equal 'New status', status.name
50 50 end
51 51
52 52 def test_create_with_failure
53 53 post :create, :issue_status => {:name => ''}
54 54 assert_response :success
55 55 assert_template 'new'
56 assert_error_tag :content => /name can't be blank/i
56 assert_error_tag :content => /name can&#x27;t be blank/i
57 57 end
58 58
59 59 def test_edit
60 60 get :edit, :id => '3'
61 61 assert_response :success
62 62 assert_template 'edit'
63 63 end
64 64
65 65 def test_update
66 66 put :update, :id => '3', :issue_status => {:name => 'Renamed status'}
67 67 assert_redirected_to :action => 'index'
68 68 status = IssueStatus.find(3)
69 69 assert_equal 'Renamed status', status.name
70 70 end
71 71
72 72 def test_update_with_failure
73 73 put :update, :id => '3', :issue_status => {:name => ''}
74 74 assert_response :success
75 75 assert_template 'edit'
76 assert_error_tag :content => /name can't be blank/i
76 assert_error_tag :content => /name can&#x27;t be blank/i
77 77 end
78 78
79 79 def test_destroy
80 80 Issue.delete_all("status_id = 1")
81 81
82 82 assert_difference 'IssueStatus.count', -1 do
83 83 delete :destroy, :id => '1'
84 84 end
85 85 assert_redirected_to :action => 'index'
86 86 assert_nil IssueStatus.find_by_id(1)
87 87 end
88 88
89 89 def test_destroy_should_block_if_status_in_use
90 90 assert_not_nil Issue.find_by_status_id(1)
91 91
92 92 assert_no_difference 'IssueStatus.count' do
93 93 delete :destroy, :id => '1'
94 94 end
95 95 assert_redirected_to :action => 'index'
96 96 assert_not_nil IssueStatus.find_by_id(1)
97 97 end
98 98
99 99 def test_update_issue_done_ratio_with_issue_done_ratio_set_to_issue_field
100 100 with_settings :issue_done_ratio => 'issue_field' do
101 101 post :update_issue_done_ratio
102 102 assert_match /not updated/, flash[:error].to_s
103 103 assert_redirected_to '/issue_statuses'
104 104 end
105 105 end
106 106
107 107 def test_update_issue_done_ratio_with_issue_done_ratio_set_to_issue_status
108 108 with_settings :issue_done_ratio => 'issue_status' do
109 109 post :update_issue_done_ratio
110 110 assert_match /Issue done ratios updated/, flash[:notice].to_s
111 111 assert_redirected_to '/issue_statuses'
112 112 end
113 113 end
114 114 end
1 NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
General Comments 0
You need to be logged in to leave comments. Login now