From bf1ed12c886bce4a0a9b33e015ffcd0d1fea406e Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sat, 13 Apr 2019 17:05:35 +0300 Subject: [PATCH] Remove hardcoded default email sender And make it configurable via `action_mailer_default_sender` config. Closes #243 --- app/mailers/application_mailer.rb | 1 - config/application-example.yml | 3 +++ config/application.rb | 1 + config/initializers/figaro.rb | 1 + test/mailers/application_mailer_test.rb | 17 +++++++++++++++++ 5 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 test/mailers/application_mailer_test.rb diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 4f340a3f81..50e69d0f61 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,6 +1,5 @@ class ApplicationMailer < ActionMailer::Base append_view_path Rails.root.join('app', 'views', 'mailers') - default from: 'noreply@internet.ee' layout 'mailer' # turn on delivery on specific (epp) request only, thus rake tasks does not deliver anything diff --git a/config/application-example.yml b/config/application-example.yml index 9cbcadbb6b..edb53e364b 100644 --- a/config/application-example.yml +++ b/config/application-example.yml @@ -143,12 +143,15 @@ same_site_session_cookies: 'false' # false|strict|lax release_domains_to_auction: 'true' auction_api_allowed_ips: '' # 192.0.2.0, 192.0.2.1 +action_mailer_default_sender: # no-reply@example.com + # Since the keys for staging are absent from the repo, we need to supply them separate for testing. test: payments_seb_bank_certificate: 'test/fixtures/files/seb_bank_cert.pem' payments_seb_seller_private: 'test/fixtures/files/seb_seller_key.pem' release_domains_to_auction: 'false' auction_api_allowed_ips: '' + action_mailer_default_sender: 'no-reply@registry.test' # Airbrake // Errbit: airbrake_host: "https://your-errbit-host.ee" diff --git a/config/application.rb b/config/application.rb index 26da91b5de..0a547e60f7 100644 --- a/config/application.rb +++ b/config/application.rb @@ -90,6 +90,7 @@ class Application < Rails::Application domain: ENV['smtp_domain'], openssl_verify_mode: ENV['smtp_openssl_verify_mode'] } + config.action_mailer.default_options = { from: ENV['action_mailer_default_sender'] } config.action_view.default_form_builder = 'DefaultFormBuilder' config.secret_key_base = Figaro.env.secret_key_base diff --git a/config/initializers/figaro.rb b/config/initializers/figaro.rb index 9c2ae3b340..76a8d23ce4 100644 --- a/config/initializers/figaro.rb +++ b/config/initializers/figaro.rb @@ -11,4 +11,5 @@ legal_documents_dir bank_statement_import_dir time_zone + action_mailer_default_sender ]) diff --git a/test/mailers/application_mailer_test.rb b/test/mailers/application_mailer_test.rb new file mode 100644 index 0000000000..3422382b7b --- /dev/null +++ b/test/mailers/application_mailer_test.rb @@ -0,0 +1,17 @@ +require 'test_helper' + +class ApplicationMailerTest < ActiveSupport::TestCase + def test_reads_default_sender_setting_from_config + assert_equal 'no-reply@registry.test', ENV['action_mailer_default_sender'] + + mailer = Class.new(ApplicationMailer) do + def test + # Empty block to avoid template rendering + mail {} + end + end + email = mailer.test + + assert_equal ['no-reply@registry.test'], email.from + end +end \ No newline at end of file