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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With