##// END OF EJS Templates
Don't use #delete on String in Mailer....
Jean-Philippe Lang -
r9117:95b10f3bd388
parent child
Show More
@@ -1,477 +1,487
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class Mailer < ActionMailer::Base
19 19 layout 'mailer'
20 20 helper :application
21 21 helper :issues
22 22 helper :custom_fields
23 23
24 24 include ActionController::UrlWriter
25 25 include Redmine::I18n
26 26
27 27 def self.default_url_options
28 28 h = Setting.host_name
29 29 h = h.to_s.gsub(%r{\/.*$}, '') unless Redmine::Utils.relative_url_root.blank?
30 30 { :host => h, :protocol => Setting.protocol }
31 31 end
32 32
33 33 # Builds a tmail object used to email recipients of the added issue.
34 34 #
35 35 # Example:
36 36 # issue_add(issue) => tmail object
37 37 # Mailer.deliver_issue_add(issue) => sends an email to issue recipients
38 38 def issue_add(issue)
39 39 redmine_headers 'Project' => issue.project.identifier,
40 40 'Issue-Id' => issue.id,
41 41 'Issue-Author' => issue.author.login
42 42 redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
43 43 message_id issue
44 44 @author = issue.author
45 45 recipients issue.recipients
46 46 cc(issue.watcher_recipients - @recipients)
47 47 subject "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] (#{issue.status.name}) #{issue.subject}"
48 48 body :issue => issue,
49 49 :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue)
50 50 render_multipart('issue_add', body)
51 51 end
52 52
53 53 # Builds a tmail object used to email recipients of the edited issue.
54 54 #
55 55 # Example:
56 56 # issue_edit(journal) => tmail object
57 57 # Mailer.deliver_issue_edit(journal) => sends an email to issue recipients
58 58 def issue_edit(journal)
59 59 issue = journal.journalized.reload
60 60 redmine_headers 'Project' => issue.project.identifier,
61 61 'Issue-Id' => issue.id,
62 62 'Issue-Author' => issue.author.login
63 63 redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
64 64 message_id journal
65 65 references issue
66 66 @author = journal.user
67 67 recipients issue.recipients
68 68 # Watchers in cc
69 69 cc(issue.watcher_recipients - @recipients)
70 70 s = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] "
71 71 s << "(#{issue.status.name}) " if journal.new_value_for('status_id')
72 72 s << issue.subject
73 73 subject s
74 74 body :issue => issue,
75 75 :journal => journal,
76 76 :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue, :anchor => "change-#{journal.id}")
77 77
78 78 render_multipart('issue_edit', body)
79 79 end
80 80
81 81 def reminder(user, issues, days)
82 82 set_language_if_valid user.language
83 83 recipients user.mail
84 84 subject l(:mail_subject_reminder, :count => issues.size, :days => days)
85 85 body :issues => issues,
86 86 :days => days,
87 87 :issues_url => url_for(:controller => 'issues', :action => 'index',
88 88 :set_filter => 1, :assigned_to_id => user.id,
89 89 :sort => 'due_date:asc')
90 90 render_multipart('reminder', body)
91 91 end
92 92
93 93 # Builds a tmail object used to email users belonging to the added document's project.
94 94 #
95 95 # Example:
96 96 # document_added(document) => tmail object
97 97 # Mailer.deliver_document_added(document) => sends an email to the document's project recipients
98 98 def document_added(document)
99 99 redmine_headers 'Project' => document.project.identifier
100 100 recipients document.recipients
101 @author = User.current
101 102 subject "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}"
102 103 body :document => document,
103 104 :document_url => url_for(:controller => 'documents', :action => 'show', :id => document)
104 105 render_multipart('document_added', body)
105 106 end
106 107
107 108 # Builds a tmail object used to email recipients of a project when an attachements are added.
108 109 #
109 110 # Example:
110 111 # attachments_added(attachments) => tmail object
111 112 # Mailer.deliver_attachments_added(attachments) => sends an email to the project's recipients
112 113 def attachments_added(attachments)
113 114 container = attachments.first.container
114 115 added_to = ''
115 116 added_to_url = ''
117 @author = attachments.first.author
116 118 case container.class.name
117 119 when 'Project'
118 120 added_to_url = url_for(:controller => 'files', :action => 'index', :project_id => container)
119 121 added_to = "#{l(:label_project)}: #{container}"
120 122 recipients container.project.notified_users.select {|user| user.allowed_to?(:view_files, container.project)}.collect {|u| u.mail}
121 123 when 'Version'
122 124 added_to_url = url_for(:controller => 'files', :action => 'index', :project_id => container.project)
123 125 added_to = "#{l(:label_version)}: #{container.name}"
124 126 recipients container.project.notified_users.select {|user| user.allowed_to?(:view_files, container.project)}.collect {|u| u.mail}
125 127 when 'Document'
126 128 added_to_url = url_for(:controller => 'documents', :action => 'show', :id => container.id)
127 129 added_to = "#{l(:label_document)}: #{container.title}"
128 130 recipients container.recipients
129 131 end
130 132 redmine_headers 'Project' => container.project.identifier
131 133 subject "[#{container.project.name}] #{l(:label_attachment_new)}"
132 134 body :attachments => attachments,
133 135 :added_to => added_to,
134 136 :added_to_url => added_to_url
135 137 render_multipart('attachments_added', body)
136 138 end
137 139
138 140 # Builds a tmail object used to email recipients of a news' project when a news item is added.
139 141 #
140 142 # Example:
141 143 # news_added(news) => tmail object
142 144 # Mailer.deliver_news_added(news) => sends an email to the news' project recipients
143 145 def news_added(news)
144 146 redmine_headers 'Project' => news.project.identifier
147 @author = news.author
145 148 message_id news
146 149 recipients news.recipients
147 150 subject "[#{news.project.name}] #{l(:label_news)}: #{news.title}"
148 151 body :news => news,
149 152 :news_url => url_for(:controller => 'news', :action => 'show', :id => news)
150 153 render_multipart('news_added', body)
151 154 end
152 155
153 156 # Builds a tmail object used to email recipients of a news' project when a news comment is added.
154 157 #
155 158 # Example:
156 159 # news_comment_added(comment) => tmail object
157 160 # Mailer.news_comment_added(comment) => sends an email to the news' project recipients
158 161 def news_comment_added(comment)
159 162 news = comment.commented
160 163 redmine_headers 'Project' => news.project.identifier
164 @author = comment.author
161 165 message_id comment
162 166 recipients news.recipients
163 167 cc news.watcher_recipients
164 168 subject "Re: [#{news.project.name}] #{l(:label_news)}: #{news.title}"
165 169 body :news => news,
166 170 :comment => comment,
167 171 :news_url => url_for(:controller => 'news', :action => 'show', :id => news)
168 172 render_multipart('news_comment_added', body)
169 173 end
170 174
171 175 # Builds a tmail object used to email the recipients of the specified message that was posted.
172 176 #
173 177 # Example:
174 178 # message_posted(message) => tmail object
175 179 # Mailer.deliver_message_posted(message) => sends an email to the recipients
176 180 def message_posted(message)
177 181 redmine_headers 'Project' => message.project.identifier,
178 182 'Topic-Id' => (message.parent_id || message.id)
183 @author = message.author
179 184 message_id message
180 185 references message.parent unless message.parent.nil?
181 186 recipients(message.recipients)
182 187 cc((message.root.watcher_recipients + message.board.watcher_recipients).uniq - @recipients)
183 188 subject "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] #{message.subject}"
184 189 body :message => message,
185 190 :message_url => url_for(message.event_url)
186 191 render_multipart('message_posted', body)
187 192 end
188 193
189 194 # Builds a tmail object used to email the recipients of a project of the specified wiki content was added.
190 195 #
191 196 # Example:
192 197 # wiki_content_added(wiki_content) => tmail object
193 198 # Mailer.deliver_wiki_content_added(wiki_content) => sends an email to the project's recipients
194 199 def wiki_content_added(wiki_content)
195 200 redmine_headers 'Project' => wiki_content.project.identifier,
196 201 'Wiki-Page-Id' => wiki_content.page.id
202 @author = wiki_content.author
197 203 message_id wiki_content
198 204 recipients wiki_content.recipients
199 205 cc(wiki_content.page.wiki.watcher_recipients - recipients)
200 206 subject "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_added, :id => wiki_content.page.pretty_title)}"
201 207 body :wiki_content => wiki_content,
202 208 :wiki_content_url => url_for(:controller => 'wiki', :action => 'show',
203 209 :project_id => wiki_content.project,
204 210 :id => wiki_content.page.title)
205 211 render_multipart('wiki_content_added', body)
206 212 end
207 213
208 214 # Builds a tmail object used to email the recipients of a project of the specified wiki content was updated.
209 215 #
210 216 # Example:
211 217 # wiki_content_updated(wiki_content) => tmail object
212 218 # Mailer.deliver_wiki_content_updated(wiki_content) => sends an email to the project's recipients
213 219 def wiki_content_updated(wiki_content)
214 220 redmine_headers 'Project' => wiki_content.project.identifier,
215 221 'Wiki-Page-Id' => wiki_content.page.id
222 @author = wiki_content.author
216 223 message_id wiki_content
217 224 recipients wiki_content.recipients
218 225 cc(wiki_content.page.wiki.watcher_recipients + wiki_content.page.watcher_recipients - recipients)
219 226 subject "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_updated, :id => wiki_content.page.pretty_title)}"
220 227 body :wiki_content => wiki_content,
221 228 :wiki_content_url => url_for(:controller => 'wiki', :action => 'show',
222 229 :project_id => wiki_content.project,
223 230 :id => wiki_content.page.title),
224 231 :wiki_diff_url => url_for(:controller => 'wiki', :action => 'diff',
225 232 :project_id => wiki_content.project, :id => wiki_content.page.title,
226 233 :version => wiki_content.version)
227 234 render_multipart('wiki_content_updated', body)
228 235 end
229 236
230 237 # Builds a tmail object used to email the specified user their account information.
231 238 #
232 239 # Example:
233 240 # account_information(user, password) => tmail object
234 241 # Mailer.deliver_account_information(user, password) => sends account information to the user
235 242 def account_information(user, password)
236 243 set_language_if_valid user.language
237 244 recipients user.mail
238 245 subject l(:mail_subject_register, Setting.app_title)
239 246 body :user => user,
240 247 :password => password,
241 248 :login_url => url_for(:controller => 'account', :action => 'login')
242 249 render_multipart('account_information', body)
243 250 end
244 251
245 252 # Builds a tmail object used to email all active administrators of an account activation request.
246 253 #
247 254 # Example:
248 255 # account_activation_request(user) => tmail object
249 256 # Mailer.deliver_account_activation_request(user)=> sends an email to all active administrators
250 257 def account_activation_request(user)
251 258 # Send the email to all active administrators
252 259 recipients User.active.find(:all, :conditions => {:admin => true}).collect { |u| u.mail }.compact
253 260 subject l(:mail_subject_account_activation_request, Setting.app_title)
254 261 body :user => user,
255 262 :url => url_for(:controller => 'users', :action => 'index',
256 263 :status => User::STATUS_REGISTERED,
257 264 :sort_key => 'created_on', :sort_order => 'desc')
258 265 render_multipart('account_activation_request', body)
259 266 end
260 267
261 268 # Builds a tmail object used to email the specified user that their account was activated by an administrator.
262 269 #
263 270 # Example:
264 271 # account_activated(user) => tmail object
265 272 # Mailer.deliver_account_activated(user) => sends an email to the registered user
266 273 def account_activated(user)
267 274 set_language_if_valid user.language
268 275 recipients user.mail
269 276 subject l(:mail_subject_register, Setting.app_title)
270 277 body :user => user,
271 278 :login_url => url_for(:controller => 'account', :action => 'login')
272 279 render_multipart('account_activated', body)
273 280 end
274 281
275 282 def lost_password(token)
276 283 set_language_if_valid(token.user.language)
277 284 recipients token.user.mail
278 285 subject l(:mail_subject_lost_password, Setting.app_title)
279 286 body :token => token,
280 287 :url => url_for(:controller => 'account', :action => 'lost_password', :token => token.value)
281 288 render_multipart('lost_password', body)
282 289 end
283 290
284 291 def register(token)
285 292 set_language_if_valid(token.user.language)
286 293 recipients token.user.mail
287 294 subject l(:mail_subject_register, Setting.app_title)
288 295 body :token => token,
289 296 :url => url_for(:controller => 'account', :action => 'activate', :token => token.value)
290 297 render_multipart('register', body)
291 298 end
292 299
293 300 def test_email(user)
294 301 set_language_if_valid(user.language)
295 302 recipients user.mail
296 303 subject 'Redmine test'
297 304 body :url => url_for(:controller => 'welcome')
298 305 render_multipart('test_email', body)
299 306 end
300 307
301 308 # Overrides default deliver! method to prevent from sending an email
302 309 # with no recipient, cc or bcc
303 310 def deliver!(mail = @mail)
304 311 set_language_if_valid @initial_language
305 312 return false if (recipients.nil? || recipients.empty?) &&
306 313 (cc.nil? || cc.empty?) &&
307 314 (bcc.nil? || bcc.empty?)
308 315
309 316 # Set Message-Id and References
310 317 if @message_id_object
311 318 mail.message_id = self.class.message_id_for(@message_id_object)
312 319 end
313 320 if @references_objects
314 321 mail.references = @references_objects.collect {|o| self.class.message_id_for(o)}
315 322 end
316 323
317 324 # Log errors when raise_delivery_errors is set to false, Rails does not
318 325 raise_errors = self.class.raise_delivery_errors
319 326 self.class.raise_delivery_errors = true
320 327 begin
321 328 return super(mail)
322 329 rescue Exception => e
323 330 if raise_errors
324 331 raise e
325 332 elsif mylogger
326 333 mylogger.error "The following error occured while sending email notification: \"#{e.message}\". Check your configuration in config/configuration.yml."
327 334 end
328 335 ensure
329 336 self.class.raise_delivery_errors = raise_errors
330 337 end
331 338 end
332 339
333 340 # Sends reminders to issue assignees
334 341 # Available options:
335 342 # * :days => how many days in the future to remind about (defaults to 7)
336 343 # * :tracker => id of tracker for filtering issues (defaults to all trackers)
337 344 # * :project => id or identifier of project to process (defaults to all projects)
338 345 # * :users => array of user ids who should be reminded
339 346 def self.reminders(options={})
340 347 days = options[:days] || 7
341 348 project = options[:project] ? Project.find(options[:project]) : nil
342 349 tracker = options[:tracker] ? Tracker.find(options[:tracker]) : nil
343 350 user_ids = options[:users]
344 351
345 352 scope = Issue.open.scoped(:conditions => ["#{Issue.table_name}.assigned_to_id IS NOT NULL" +
346 353 " AND #{Project.table_name}.status = #{Project::STATUS_ACTIVE}" +
347 354 " AND #{Issue.table_name}.due_date <= ?", days.day.from_now.to_date]
348 355 )
349 356 scope = scope.scoped(:conditions => {:assigned_to_id => user_ids}) if user_ids.present?
350 357 scope = scope.scoped(:conditions => {:project_id => project.id}) if project
351 358 scope = scope.scoped(:conditions => {:tracker_id => tracker.id}) if tracker
352 359
353 360 issues_by_assignee = scope.all(:include => [:status, :assigned_to, :project, :tracker]).group_by(&:assigned_to)
354 361 issues_by_assignee.each do |assignee, issues|
355 362 deliver_reminder(assignee, issues, days) if assignee && assignee.active?
356 363 end
357 364 end
358 365
359 366 # Activates/desactivates email deliveries during +block+
360 367 def self.with_deliveries(enabled = true, &block)
361 368 was_enabled = ActionMailer::Base.perform_deliveries
362 369 ActionMailer::Base.perform_deliveries = !!enabled
363 370 yield
364 371 ensure
365 372 ActionMailer::Base.perform_deliveries = was_enabled
366 373 end
367 374
368 375 private
369 376 def initialize_defaults(method_name)
370 377 super
371 378 @initial_language = current_language
372 379 set_language_if_valid Setting.default_language
373 380 from Setting.mail_from
374 381
375 382 # Common headers
376 383 headers 'X-Mailer' => 'Redmine',
377 384 'X-Redmine-Host' => Setting.host_name,
378 385 'X-Redmine-Site' => Setting.app_title,
379 386 'X-Auto-Response-Suppress' => 'OOF',
380 387 'Auto-Submitted' => 'auto-generated'
381 388 end
382 389
383 390 # Appends a Redmine header field (name is prepended with 'X-Redmine-')
384 391 def redmine_headers(h)
385 392 h.each { |k,v| headers["X-Redmine-#{k}"] = v.to_s }
386 393 end
387 394
388 395 # Overrides the create_mail method
389 396 def create_mail
390 # Removes the current user from the recipients and cc
397 # Removes the author from the recipients and cc
391 398 # if he doesn't want to receive notifications about what he does
392 @author ||= User.current
393 if @author.pref[:no_self_notified]
394 recipients.delete(@author.mail) if recipients
395 cc.delete(@author.mail) if cc
399 if @author && @author.logged? && @author.pref[:no_self_notified]
400 if recipients
401 recipients((recipients.is_a?(Array) ? recipients : [recipients]) - [@author.mail])
402 end
403 if cc
404 cc((cc.is_a?(Array) ? cc : [cc]) - [@author.mail])
405 end
396 406 end
397 407
398 if @author.logged?
408 if @author && @author.logged?
399 409 redmine_headers 'Sender' => @author.login
400 410 end
401 411
402 412 notified_users = [recipients, cc].flatten.compact.uniq
403 413 # Rails would log recipients only, not cc and bcc
404 414 mylogger.info "Sending email notification to: #{notified_users.join(', ')}" if mylogger
405 415
406 416 # Blind carbon copy recipients
407 417 if Setting.bcc_recipients?
408 418 bcc(notified_users)
409 419 recipients []
410 420 cc []
411 421 end
412 422 super
413 423 end
414 424
415 425 # Rails 2.3 has problems rendering implicit multipart messages with
416 426 # layouts so this method will wrap an multipart messages with
417 427 # explicit parts.
418 428 #
419 429 # https://rails.lighthouseapp.com/projects/8994/tickets/2338-actionmailer-mailer-views-and-content-type
420 430 # https://rails.lighthouseapp.com/projects/8994/tickets/1799-actionmailer-doesnt-set-template_format-when-rendering-layouts
421 431
422 432 def render_multipart(method_name, body)
423 433 if Setting.plain_text_mail?
424 434 content_type "text/plain"
425 435 body render(:file => "#{method_name}.text.erb",
426 436 :body => body,
427 437 :layout => 'mailer.text.erb')
428 438 else
429 439 content_type "multipart/alternative"
430 440 part :content_type => "text/plain",
431 441 :body => render(:file => "#{method_name}.text.erb",
432 442 :body => body, :layout => 'mailer.text.erb')
433 443 part :content_type => "text/html",
434 444 :body => render_message("#{method_name}.html.erb", body)
435 445 end
436 446 end
437 447
438 448 # Makes partial rendering work with Rails 1.2 (retro-compatibility)
439 449 def self.controller_path
440 450 ''
441 451 end unless respond_to?('controller_path')
442 452
443 453 # Returns a predictable Message-Id for the given object
444 454 def self.message_id_for(object)
445 455 # id + timestamp should reduce the odds of a collision
446 456 # as far as we don't send multiple emails for the same object
447 457 timestamp = object.send(object.respond_to?(:created_on) ? :created_on : :updated_on)
448 458 hash = "redmine.#{object.class.name.demodulize.underscore}-#{object.id}.#{timestamp.strftime("%Y%m%d%H%M%S")}"
449 459 host = Setting.mail_from.to_s.gsub(%r{^.*@}, '')
450 460 host = "#{::Socket.gethostname}.redmine" if host.empty?
451 461 "<#{hash}@#{host}>"
452 462 end
453 463
454 464 private
455 465
456 466 def message_id(object)
457 467 @message_id_object = object
458 468 end
459 469
460 470 def references(object)
461 471 @references_objects ||= []
462 472 @references_objects << object
463 473 end
464 474
465 475 def mylogger
466 476 Rails.logger
467 477 end
468 478 end
469 479
470 480 # Patch TMail so that message_id is not overwritten
471 481 module TMail
472 482 class Mail
473 483 def add_message_id( fqdn = nil )
474 484 self.message_id ||= ::TMail::new_message_id(fqdn)
475 485 end
476 486 end
477 487 end
@@ -1,159 +1,164
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19
20 20 class AdminControllerTest < ActionController::TestCase
21 21 fixtures :projects, :users, :roles
22 22
23 23 def setup
24 24 User.current = nil
25 25 @request.session[:user_id] = 1 # admin
26 26 end
27 27
28 28 def test_index
29 29 get :index
30 30 assert_no_tag :tag => 'div',
31 31 :attributes => { :class => /nodata/ }
32 32 end
33 33
34 34 def test_index_with_no_configuration_data
35 35 delete_configuration_data
36 36 get :index
37 37 assert_tag :tag => 'div',
38 38 :attributes => { :class => /nodata/ }
39 39 end
40 40
41 41 def test_projects
42 42 get :projects
43 43 assert_response :success
44 44 assert_template 'projects'
45 45 assert_not_nil assigns(:projects)
46 46 # active projects only
47 47 assert_nil assigns(:projects).detect {|u| !u.active?}
48 48 end
49 49
50 50 def test_projects_with_status_filter
51 51 get :projects, :status => 1
52 52 assert_response :success
53 53 assert_template 'projects'
54 54 assert_not_nil assigns(:projects)
55 55 # active projects only
56 56 assert_nil assigns(:projects).detect {|u| !u.active?}
57 57 end
58 58
59 59 def test_projects_with_name_filter
60 60 get :projects, :name => 'store', :status => ''
61 61 assert_response :success
62 62 assert_template 'projects'
63 63 projects = assigns(:projects)
64 64 assert_not_nil projects
65 65 assert_equal 1, projects.size
66 66 assert_equal 'OnlineStore', projects.first.name
67 67 end
68 68
69 69 def test_load_default_configuration_data
70 70 delete_configuration_data
71 71 post :default_configuration, :lang => 'fr'
72 72 assert_response :redirect
73 73 assert_nil flash[:error]
74 74 assert IssueStatus.find_by_name('Nouveau')
75 75 end
76 76
77 77 def test_load_default_configuration_data_should_rescue_error
78 78 delete_configuration_data
79 79 Redmine::DefaultData::Loader.stubs(:load).raises(Exception.new("Something went wrong"))
80 80 post :default_configuration, :lang => 'fr'
81 81 assert_response :redirect
82 82 assert_not_nil flash[:error]
83 83 assert_match /Something went wrong/, flash[:error]
84 84 end
85 85
86 86 def test_test_email
87 user = User.find(1)
88 user.pref[:no_self_notified] = '1'
89 user.pref.save!
90 ActionMailer::Base.deliveries.clear
91
87 92 get :test_email
88 93 assert_redirected_to '/settings/edit?tab=notifications'
89 94 mail = ActionMailer::Base.deliveries.last
90 95 assert_not_nil mail
91 96 user = User.find(1)
92 97 assert_equal [user.mail], mail.bcc
93 98 end
94 99
95 100 def test_test_email_failure_should_display_the_error
96 101 Mailer.stubs(:deliver_test_email).raises(Exception, 'Some error message')
97 102 get :test_email
98 103 assert_redirected_to '/settings/edit?tab=notifications'
99 104 assert_match /Some error message/, flash[:error]
100 105 end
101 106
102 107 def test_no_plugins
103 108 Redmine::Plugin.clear
104 109
105 110 get :plugins
106 111 assert_response :success
107 112 assert_template 'plugins'
108 113 end
109 114
110 115 def test_plugins
111 116 # Register a few plugins
112 117 Redmine::Plugin.register :foo do
113 118 name 'Foo plugin'
114 119 author 'John Smith'
115 120 description 'This is a test plugin'
116 121 version '0.0.1'
117 122 settings :default => {'sample_setting' => 'value', 'foo'=>'bar'}, :partial => 'foo/settings'
118 123 end
119 124 Redmine::Plugin.register :bar do
120 125 end
121 126
122 127 get :plugins
123 128 assert_response :success
124 129 assert_template 'plugins'
125 130
126 131 assert_tag :td, :child => { :tag => 'span', :content => 'Foo plugin' }
127 132 assert_tag :td, :child => { :tag => 'span', :content => 'Bar' }
128 133 end
129 134
130 135 def test_info
131 136 get :info
132 137 assert_response :success
133 138 assert_template 'info'
134 139 end
135 140
136 141 def test_admin_menu_plugin_extension
137 142 Redmine::MenuManager.map :admin_menu do |menu|
138 143 menu.push :test_admin_menu_plugin_extension, '/foo/bar', :caption => 'Test'
139 144 end
140 145
141 146 get :index
142 147 assert_response :success
143 148 assert_tag :a, :attributes => { :href => '/foo/bar' },
144 149 :content => 'Test'
145 150
146 151 Redmine::MenuManager.map :admin_menu do |menu|
147 152 menu.delete :test_admin_menu_plugin_extension
148 153 end
149 154 end
150 155
151 156 private
152 157
153 158 def delete_configuration_data
154 159 Role.delete_all('builtin = 0')
155 160 Tracker.delete_all
156 161 IssueStatus.delete_all
157 162 Enumeration.delete_all
158 163 end
159 164 end
General Comments 0
You need to be logged in to leave comments. Login now