We're reading the value from the database, but the `ApplicationMailer.default` method is evaluated when the application is started. So if we don't use a Proc, we'll need to restart the server every time we change the value in the database, or else the old value will still be used. Using a Proc makes sure the mailer from address is evaluated at runtime, so emails are sent using the from address currently defined in the database. The same situation took place using the devise mailer. Now we don't need to check for the settings table being present because the Proc in the devise initializer won't be evaluated before the settings table is created and populated.
27 lines
708 B
Ruby
27 lines
708 B
Ruby
require "rails_helper"
|
|
|
|
describe Mailer do
|
|
describe "#comment" do
|
|
it "sends emails in the user's locale" do
|
|
user = create(:user, locale: "es")
|
|
proposal = create(:proposal, author: user)
|
|
comment = create(:comment, commentable: proposal)
|
|
|
|
email = I18n.with_locale :en do
|
|
described_class.comment(comment)
|
|
end
|
|
|
|
expect(email.subject).to include("comentado")
|
|
end
|
|
|
|
it "reads the from address at runtime" do
|
|
Setting["mailer_from_name"] = "New organization"
|
|
Setting["mailer_from_address"] = "new@consul.dev"
|
|
|
|
email = Mailer.comment(create(:comment))
|
|
|
|
expect(email).to deliver_from "New organization <new@consul.dev>"
|
|
end
|
|
end
|
|
end
|