# How to test sending mails in model

**URL:** <https://www.ruby-forum.com/t/how-to-test-sending-mails-in-model/124867>\
**Category:** Rails\
**Created:** [January 3, 2008, 9:04am UTC](https://www.ruby-forum.com/t/how-to-test-sending-mails-in-model/124867 "2008-01-03T09:04:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![leonb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/22d042/32.png) [@leonb](https://www.ruby-forum.com/u/leonb)\
**Post date:** [January 3, 2008, 9:04am UTC](https://www.ruby-forum.com/t/how-to-test-sending-mails-in-model/124867/1 "2008-01-03T09:04:55Z")

</div>

Hi all, I have this model (see the attachment). I has an after\_save  
filter which sends mail. But I don’t know how to test it. Most things I  
find about testing the sending of e-mails is about the ActionMailer  
class.

Does anyone know how I can test this method properly  
(send\_mail\_about\_new\_deposit)?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![leonb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/22d042/32.png) [@leonb](https://www.ruby-forum.com/u/leonb)\
**Post date:** [January 3, 2008, 11:01am UTC](https://www.ruby-forum.com/t/how-to-test-sending-mails-in-model/124867/2 "2008-01-03T11:01:37Z")

</div>

we use ActionMailer very often, but normally do only this simple test:

first:  
ActionMailer::Base.deliveries.clear

then create/save the deposit and with:  
assert\_equal(1, ActionMailer::Base.deliveries.length)

make sure, that the mail was sent

---

<div class="post-metadata">

**Author:** ![leonb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/22d042/32.png) [@leonb](https://www.ruby-forum.com/u/leonb)\
**Post date:** [January 9, 2008, 10:58pm UTC](https://www.ruby-forum.com/t/how-to-test-sending-mails-in-model/124867/3 "2008-01-09T22:58:01Z")

</div>

Thorsten M. wrote:

> we use ActionMailer very often, but normally do only this simple test:
> 
> first:  
> ActionMailer::Base.deliveries.clear
> 
> then create/save the deposit and with:  
> assert\_equal(1, ActionMailer::Base.deliveries.length)
> 
> make sure, that the mail was sent

Ah thanks! Looks very simple and is exactly what I want.
