#!/bin/env ruby require File.dirname(__FILE__) + '/../test_helper' require 'mailer' class MailerTest < Test::Unit::TestCase fixtures 'users', 'posts', 'topics', 'forums' def setup @sent_mail = ActionMailer::Base.deliveries = [] end def teardown ActionMailer::Base.deliveries = [] end def test_registration_mail Mailer.deliver_registration_mail(User.find(1), 'some password', 'http://localhost:3000/user/login') assert_equal 1, @sent_mail.size end def test_new_post_notification Mailer.deliver_new_post_notification(User.find(1), Post.find(1)) assert_equal 1, @sent_mail.size end def test_reset_password Mailer.deliver_reset_password(User.find(1), 'url_to_reset') assert_equal 1, @sent_mail.size assert_match /url_to_reset/, @sent_mail[0].encoded end def test_user_message text = "hello user2" Mailer.deliver_user_message(User.find(1), User.find(2), text) assert_match /#{text}/, @sent_mail[0].encoded assert_match /#{User.find(1).name}/, @sent_mail[0].encoded assert_match /#{RForum::CONFIG[:mail_charset]}/, @sent_mail[0]['content-type'].to_s assert_equal User.find(1).email, @sent_mail[0]['from'].to_s end def test_delete_post_notification Mailer.deliver_delete_post_notification(Post.find(1)) assert_match /#{Post.find(1).subject}/, @sent_mail[0].encoded end def test_ml_post_no_list p = Post.find(1) assert_raises(RuntimeError) { Mailer.deliver_ml_post(p) } end def test_ml_post p = Post.find(21) Mailer.deliver_ml_post(p) assert @sent_mail[0].body[p.text] assert_equal p.subject, @sent_mail[0].subject assert_equal p.author.email, @sent_mail[0].from[0] assert_equal p.topic.forum.list_address, @sent_mail[0].to[0] assert_equal 'test1', @sent_mail[0].header['header1'].to_s assert_equal 'test2', @sent_mail[0].header['header2'].to_s end end