Skip to content

Fix ActionMailer assertion not working for mail defining delivery_job:#34339

Merged
rafaelfranca merged 2 commits intorails:masterfrom
Edouard-chin:ec-mail-test-helper
Nov 21, 2018
Merged

Fix ActionMailer assertion not working for mail defining delivery_job:#34339
rafaelfranca merged 2 commits intorails:masterfrom
Edouard-chin:ec-mail-test-helper

Conversation

@Edouard-chin
Copy link
Member

@Edouard-chin Edouard-chin commented Oct 28, 2018

Fix ActionMailer assertion not working for mail defining delivery_job:

  • If a Mail defines a custom delivery_job, all ActionMailer assertion
    helper (assert_emails, assert_enqueued_emails ...) wouldn't work.
MyMailer < ApplicationMailer
 self.delivery_job = MyJob
end

# This assertion will fail
assert_emails(1) do
 MyMailer.my_mail.deliver_later
end

This PR leverage the new ActiveJob feature that accepts Procs for the
only keyword and check if the delivery job is one of ActionMailer
registered ones.

@rails-bot
Copy link

r? @schneems

(@rails-bot has picked a reviewer for you, use r? to override)

- That feature is useful to enqueue or assert that jobs got enqueued
  or performed based on dynamic conditions.
  We will be able to leverage that feature to fix all ActionMailer
  assertion helper issue when a Mailer define a custom delivery job
  (see next commit).
@Edouard-chin
Copy link
Member Author

Sorry for the delay, this is ready with a new implementation

- If a Mail defines a custom delivery_job, all ActionMailer assertion
  helper (assert_emails, assert_enqueued_emails ...) wouldn't work.

  ```ruby
    MyMailer < ApplicationMailer
      self.delivery_job = MyJob
    end

    # This assertion will fail
    assert_emails(1) do
      MyMailer.my_mail.deliver_later
    end

  This PR leverage the new ActiveJob feature that accepts Procs for the
  `only` keyword and check if the delivery job is one of ActionMailer
   registered ones.
@rafaelfranca rafaelfranca merged commit 47ab6b3 into rails:master Nov 21, 2018
@Edouard-chin Edouard-chin deleted the ec-mail-test-helper branch November 21, 2018 23:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants