Skip to content

Commit

Permalink
[fix] Usage of HackathonConfig values in initializers
Browse files Browse the repository at this point in the history
Need to use lambdas such that the real value is accurate whenever it’s called for
  • Loading branch information
sman591 committed Apr 17, 2019
1 parent 4ee9459 commit c0f5403
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ApplicationMailer < ActionMailer::Base
default from: HackathonConfig['email_from']
default from: -> { HackathonConfig['email_from'] }
layout 'mailer'
end
2 changes: 1 addition & 1 deletion app/mailers/mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
13 changes: 13 additions & 0 deletions test/controllers/mailer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 <test@custom.example.com>'
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

0 comments on commit c0f5403

Please sign in to comment.