ankane / ahoy_email

First-party email analytics for Rails
MIT License
1.11k stars 137 forks source link

Handle the case of a mailer method that ends up not sending any mail. #122

Closed xxx closed 5 years ago

xxx commented 5 years ago

I'm upgrading from 0.5.2 to 1.0.2, and we're suddenly seeing errors in mailer tests in cases where the to list is whittled down to nothing, so we don't send the mail (calling mail with a blank to throws STMP errors), and nil is returned from the mailer method

I don't think the line that sets :user changed between the two versions, so I'm not sure if our case is supposed to even make it that far, but the fix was one character, assuming targetted Ruby versions all have the safe navigation operator.

sumitngupta commented 5 years ago

👍

ankane commented 5 years ago

Hey @xxx, thanks for the PR 👍 I think try would be a bit better. Also, I'm unable to reproduce with a test case:

  def test_to_empty
    UserMailer.to_field(nil).deliver_now
  end

It raises an ArgumentError: SMTP To address may not be blank: [] in Rails 4.2-5.2 in the tests.

xxx commented 5 years ago

@ankane Right - the issue is when you don't call mail at all. The blank to is the SMTP error I mentioned (and is why we don't call mail at all if we run out of users to send to). There is a failing test case in the PR

ankane commented 5 years ago

Wow, totally missed the test case 👌 Looks great, thanks!