Mercurial > hg > soundsoftware-site
comparison test/unit/mailer_test.rb @ 1298:4f746d8966dd redmine_2.3_integration
Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author | Chris Cannam |
---|---|
date | Fri, 14 Jun 2013 09:28:30 +0100 |
parents | 622f24f53b42 |
children |
comparison
equal
deleted
inserted
replaced
1297:0a574315af3e | 1298:4f746d8966dd |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2012 Jean-Philippe Lang | 2 # Copyright (C) 2006-2013 Jean-Philippe Lang |
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
208 assert_equal 'redmine@example.net', mail.from_addrs.first | 208 assert_equal 'redmine@example.net', mail.from_addrs.first |
209 assert_equal 'Redmine app <redmine@example.net>', mail.header['From'].to_s | 209 assert_equal 'Redmine app <redmine@example.net>', mail.header['From'].to_s |
210 end | 210 end |
211 | 211 |
212 def test_should_not_send_email_without_recipient | 212 def test_should_not_send_email_without_recipient |
213 news = News.find(:first) | 213 news = News.first |
214 user = news.author | 214 user = news.author |
215 # Remove members except news author | 215 # Remove members except news author |
216 news.project.memberships.each {|m| m.destroy unless m.user == user} | 216 news.project.memberships.each {|m| m.destroy unless m.user == user} |
217 | 217 |
218 user.pref[:no_self_notified] = false | 218 user.pref[:no_self_notified] = false |
277 "http://mydomain.foo/boards/#{message.board.id}/topics/#{message.root.id}?r=#{message.id}#message-#{message.id}", | 277 "http://mydomain.foo/boards/#{message.board.id}/topics/#{message.root.id}?r=#{message.id}#message-#{message.id}", |
278 :text => message.subject | 278 :text => message.subject |
279 end | 279 end |
280 end | 280 end |
281 | 281 |
282 context("#issue_add") do | 282 test "#issue_add should notify project members" do |
283 setup do | 283 issue = Issue.find(1) |
284 ActionMailer::Base.deliveries.clear | 284 assert Mailer.issue_add(issue).deliver |
285 Setting.bcc_recipients = '1' | 285 assert last_email.bcc.include?('dlopper@somenet.foo') |
286 @issue = Issue.find(1) | 286 end |
287 end | 287 |
288 | 288 test "#issue_add should not notify project members that are not allow to view the issue" do |
289 should "notify project members" do | 289 issue = Issue.find(1) |
290 assert Mailer.issue_add(@issue).deliver | 290 Role.find(2).remove_permission!(:view_issues) |
291 assert last_email.bcc.include?('dlopper@somenet.foo') | 291 assert Mailer.issue_add(issue).deliver |
292 end | 292 assert !last_email.bcc.include?('dlopper@somenet.foo') |
293 | 293 end |
294 should "not notify project members that are not allow to view the issue" do | 294 |
295 Role.find(2).remove_permission!(:view_issues) | 295 test "#issue_add should notify issue watchers" do |
296 assert Mailer.issue_add(@issue).deliver | 296 issue = Issue.find(1) |
297 assert !last_email.bcc.include?('dlopper@somenet.foo') | 297 user = User.find(9) |
298 end | 298 # minimal email notification options |
299 | 299 user.pref[:no_self_notified] = '1' |
300 should "notify issue watchers" do | 300 user.pref.save |
301 user = User.find(9) | 301 user.mail_notification = false |
302 # minimal email notification options | 302 user.save |
303 user.pref[:no_self_notified] = '1' | 303 |
304 user.pref.save | 304 Watcher.create!(:watchable => issue, :user => user) |
305 user.mail_notification = false | 305 assert Mailer.issue_add(issue).deliver |
306 user.save | 306 assert last_email.bcc.include?(user.mail) |
307 | 307 end |
308 Watcher.create!(:watchable => @issue, :user => user) | 308 |
309 assert Mailer.issue_add(@issue).deliver | 309 test "#issue_add should not notify watchers not allowed to view the issue" do |
310 assert last_email.bcc.include?(user.mail) | 310 issue = Issue.find(1) |
311 end | 311 user = User.find(9) |
312 | 312 Watcher.create!(:watchable => issue, :user => user) |
313 should "not notify watchers not allowed to view the issue" do | 313 Role.non_member.remove_permission!(:view_issues) |
314 user = User.find(9) | 314 assert Mailer.issue_add(issue).deliver |
315 Watcher.create!(:watchable => @issue, :user => user) | 315 assert !last_email.bcc.include?(user.mail) |
316 Role.non_member.remove_permission!(:view_issues) | |
317 assert Mailer.issue_add(@issue).deliver | |
318 assert !last_email.bcc.include?(user.mail) | |
319 end | |
320 end | 316 end |
321 | 317 |
322 # test mailer methods for each language | 318 # test mailer methods for each language |
323 def test_issue_add | 319 def test_issue_add |
324 issue = Issue.find(1) | 320 issue = Issue.find(1) |
400 assert_select "a[href=?]", "http://mydomain.foo/projects/ecookbook/files" | 396 assert_select "a[href=?]", "http://mydomain.foo/projects/ecookbook/files" |
401 end | 397 end |
402 end | 398 end |
403 | 399 |
404 def test_news_added | 400 def test_news_added |
405 news = News.find(:first) | 401 news = News.first |
406 valid_languages.each do |lang| | 402 valid_languages.each do |lang| |
407 Setting.default_language = lang.to_s | 403 Setting.default_language = lang.to_s |
408 assert Mailer.news_added(news).deliver | 404 assert Mailer.news_added(news).deliver |
409 end | 405 end |
410 end | 406 end |
416 assert Mailer.news_comment_added(comment).deliver | 412 assert Mailer.news_comment_added(comment).deliver |
417 end | 413 end |
418 end | 414 end |
419 | 415 |
420 def test_message_posted | 416 def test_message_posted |
421 message = Message.find(:first) | 417 message = Message.first |
422 recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author} | 418 recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author} |
423 recipients = recipients.compact.uniq | 419 recipients = recipients.compact.uniq |
424 valid_languages.each do |lang| | 420 valid_languages.each do |lang| |
425 Setting.default_language = lang.to_s | 421 Setting.default_language = lang.to_s |
426 assert Mailer.message_posted(message).deliver | 422 assert Mailer.message_posted(message).deliver |