From c0f54032d1e97b203f9ae286af5a80a19f1594f6 Mon Sep 17 00:00:00 2001 From: Stuart Olivera Date: Wed, 17 Apr 2019 19:54:19 -0400 Subject: [PATCH] [fix] Usage of HackathonConfig values in initializers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Need to use lambdas such that the real value is accurate whenever it’s called for --- app/mailers/application_mailer.rb | 2 +- app/mailers/mailer.rb | 2 +- config/initializers/devise.rb | 2 +- test/controllers/mailer_test.rb | 13 +++++++++++++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 3e5bdc1a3..e9d2de534 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,4 +1,4 @@ class ApplicationMailer < ActionMailer::Base - default from: HackathonConfig['email_from'] + default from: -> { HackathonConfig['email_from'] } layout 'mailer' end diff --git a/app/mailers/mailer.rb b/app/mailers/mailer.rb index 308eacd20..08a665d2a 100644 --- a/app/mailers/mailer.rb +++ b/app/mailers/mailer.rb @@ -2,7 +2,7 @@ class Mailer < ApplicationMailer include Roadie::Rails::Automatic add_template_helper(HackathonManagerHelper) - default from: HackathonConfig['email_from'] + default from: -> { HackathonConfig['email_from'] } def bulk_message_email(message_id, user_id, message = nil) @message = message || Message.find_by_id(message_id) diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 52b505db1..d5b9ee1ce 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -13,7 +13,7 @@ # 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 # with default "from" parameter. - config.mailer_sender = HackathonConfig['email_from'] + config.mailer_sender = -> { HackathonConfig['email_from'] } # Configure the class responsible to send e-mails. # config.mailer = 'Devise::Mailer' diff --git a/test/controllers/mailer_test.rb b/test/controllers/mailer_test.rb index ceaf653d1..1fc7794dd 100644 --- a/test/controllers/mailer_test.rb +++ b/test/controllers/mailer_test.rb @@ -47,4 +47,17 @@ class MailerTest < ActionMailer::TestCase assert_match %r{example.com\/rsvp}, email.encoded end end + + context "with customized HackathonConfig" do + setup do + @user = create(:user, email: "test@example.com") + HackathonConfig['email_from'] = 'This is a test ' + end + + should "use customized email_from" do + email = Mailer.incomplete_reminder_email(@user.id).deliver_now + + assert_equal ["test@custom.example.com"], email.from + end + end end