8

So my client has reported that many of the emails are going to the wrong person, and I would like to write some feature tests to find and make sure that they are receiving the email and what it says in my specs. I have mandrill_mailer which uses mandril api, and before it sends out I would like to see what the message is.

For example. Create a new user account -> creates the user, and then sends out a welcome email. in devise it calls RegistrationMailer.new_registration(resource).deliver which then sends a email to the user:

  def new_registration(user)
user = User.find_by_email(user["email"])
mandrill_mail template: 'new-registration',
subject: 'Welcome to ContentBlvd!',
to: { email: user["email"], name: user["full_name"] },
vars: {
  'first_name' =>   user["full_name"],
  'unsubscribe' =>  "#{CONFIG[:protocol]}#{CONFIG[:host]}/unsubscribe?email=#{user.email}"
}

end

In my mailer how do I test this mail object?
I tried ActionMailer::Base.deliveries, but it returns nil (Since I'm using mandrill mailer...) So I tried - MandrillMailer::TemplateMailer.message But no luck.... Thanks for the help.

tspore
  • 1,349
  • 2
  • 11
  • 14

3 Answers3

3

At this point, MandrillMailer appears to support a robust offline testing set of options. In particular, MandrillMailer.deliveries can now be examined for expectations or debugging purposes.

Jim Van Fleet
  • 1,110
  • 7
  • 12
1

As per wiki you need to mock Excon

# spec/rails_helper.rb

config.before(:all) do 
  Excon.defaults[:mock] = true
  Excon.stub({}, {body: "{\"html\":\"RESULT\"}", status: 200})
end
vladiim
  • 1,862
  • 2
  • 20
  • 27
-4

You don't have to use the Mandrill gem to send emails using Mandrill. Just use the Rails default Mailer and add the configuration to application.rb or production.rb to use your Mandrill's account.

http://help.mandrill.com/entries/21738467-Using-Mandrill-s-SMTP-integration-with-Web-Frameworks

Ricardo Nacif
  • 508
  • 4
  • 12