Testing Actionmailer on Travis-CI

knirirr

I've got some code such as this in a Rails model:

after_update :email_edits

def email_edits
    EditsMailer.with(record_id: id, user_id: user.id).record_modified.deliver_later
end

This is easy enough to unit test locally, e.g.

email = EditsMailer.with(record_id: records(:one).id,
                         user_id: users(:one).id).record_modified

assert_emails 1 do
   email.deliver_now
end

...but, the inevitable result when this is pushed to Travis-CI and the tests run is:

1 emails expected, but 0 were sent.
Expected: 1
Actual: 0

Integration tests also fail.

I've seen suggestions of testing whether emails are added to the ActiveJob queue, or overrding deliver_later so that deliver_now is used in tests, but I am already using deliver_now and it still fails. Even if Travis doesn't allow the sending of emails I'd expect that config.action_mailer.delivery_method = :test in config/environments/test.rb would still be effective.

Another possible workaround I thought of would be to try disabling those particular tests on Travis, but that would be unsatisfactory. Can anyone suggest what the problem might be?

knirirr

Eventually found the answer:

config.action_mailer.perform_deliveries = false

Was only being set in the Travis environment due to variable in a credentials file not being available there.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related