Make Devise::Mailer inherit from ApplicationMailer

This way we remove duplication in the `from:` proc, the helpers, and the
methods we're about to write.
This commit is contained in:
Javi Martín
2022-09-24 15:37:35 +02:00
parent e5933ce6bb
commit a729967e8a
3 changed files with 6 additions and 3 deletions

View File

@@ -1,5 +1,4 @@
class DeviseMailer < Devise::Mailer class DeviseMailer < Devise::Mailer
helper :application, :settings, :mailer
include Devise::Controllers::UrlHelpers include Devise::Controllers::UrlHelpers
default template_path: "devise/mailer" default template_path: "devise/mailer"

View File

@@ -14,11 +14,15 @@ Devise.setup do |config|
# Configure the e-mail address which will be shown in Devise::Mailer, # Configure the e-mail address which will be shown in Devise::Mailer,
# note that it will be overwritten if you use your own mailer class # note that it will be overwritten if you use your own mailer class
# with default "from" parameter. # with default "from" parameter.
config.mailer_sender = proc { "'#{Setting["mailer_from_name"]}' <#{Setting["mailer_from_address"]}>" } # We're not setting it here because it's set by the ApplicationMailer class
# config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com"
# Configure the class responsible to send e-mails. # Configure the class responsible to send e-mails.
config.mailer = "DeviseMailer" config.mailer = "DeviseMailer"
# Configure the parent class responsible to send e-mails.
config.parent_mailer = "ApplicationMailer"
# ==> ORM configuration # ==> ORM configuration
# Load and configure the ORM. Supports :active_record (default) and # Load and configure the ORM. Supports :active_record (default) and
# :mongoid (bson_ext recommended) by default. Other ORMs may be # :mongoid (bson_ext recommended) by default. Other ORMs may be

View File

@@ -18,7 +18,7 @@ describe DeviseMailer do
email = DeviseMailer.confirmation_instructions(create(:user), "ABC") email = DeviseMailer.confirmation_instructions(create(:user), "ABC")
expect(email).to deliver_from "'New organization' <new@consul.dev>" expect(email).to deliver_from "New organization <new@consul.dev>"
end end
end end
end end