2

I'm receiving real emails when I run my tests with RSpec. I've made everything as it was written in this question (I've add change my environment config to do not send emails, but it no make any effect at all. I'm thinking that my setting are replaced somewhere but I can't find where.

Here is my config for test env (config/enviroments/test.rb)

Myapp::Application.configure do
  config.action_mailer.delivery_method = :test
  config.action_mailer.perform_deliveries = false
end

here are my mailers:

class ApplicationMailer < ActionMailer::Base
  default from: 'hello@myapp.com'
  layout 'mailer'

  ADMIN_EMAIL = 'admin@myapp.com'
end

class AdminMailer < ApplicationMailer
  default to: "#{ADMIN_EMAIL}"

  def mandrill_client
    @mandrill_client ||= Mandrill::API.new MANDRILL_API_KEY
  end

  def new_user(user)
    #set required params
    mandrill_client.messages.send_template template_name, template_content, message
  end

end

It seems that I've missed something very obvious. However I need your help in breaking it up.

Community
  • 1
  • 1
Tetiana Chupryna
  • 1,044
  • 1
  • 11
  • 28

1 Answers1

1

Since you use Mandrill::API to send emails, and not ActionMailer, your settings to ActionMailer have absolutely no effect on it.

You should either find corresponding setting in the Mandrill::API, or stub the send method for tests.

I would actually suggest you to still use the ActionMailer with the Mandrill SMTP server:

config.action_mailer.smtp_settings = {
  address: 'smtp.mandrillapp.com',
  port: 587,
  domain: Rails.application.config_for(:global)['domain'],
  authentication: 'plain',
  enable_starttls_auto: true,
  user_name: Rails.application.secrets.email_provider_username,
  password: Rails.application.secrets.email_provider_apikey
}
Yury Lebedev
  • 3,985
  • 19
  • 26