Always paying attention that mails only use urls is a bit annoying/dangerous and also means we cannot reuse partials and cannot use nice resource routes like `link_to user.name, user`
Make ActionMailer always use full urls:
# we only want urls in our emails, never paths
module OnlyAbsoluteUrls
def url_for(*args)
url = super
if url.include?("://")
url
else
"#{ActionMailer::Base.default_url_options.fetch(:host)}#{url}"
end
end
end
class ApplicationMailer < ActionMailer::Base
helper OnlyAbsoluteUrls
end
and to make sure it works let’s verify in all mailer tests that we did not actually generated paths:
after { deliveries.map(&:body).map(&:to_s).join.wont_include '"/' }