Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Remove legacy mailer configuration and move into settings

Oliver Günther22b7849520dc
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 5606ab455e1..355194396f4 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -139,7 +139,7 @@ class ApplicationController < ActionController::Base
:stop_if_feeds_disabled,
:set_cache_buster,
:action_hooks,
- :reload_mailer_configuration!
+ :reload_mailer_settings!
include Redmine::Search::Controller
include Redmine::MenuManager::MenuController
@@ -167,8 +167,8 @@ class ApplicationController < ActionController::Base
end
end
- def reload_mailer_configuration!
- OpenProject::Configuration.reload_mailer_configuration!
+ def reload_mailer_settings!
+ Setting.reload_mailer_settings!
end
# Checks if the session cookie is missing.
diff --git a/app/models/setting.rb b/app/models/setting.rb
index 14dd8b97184..764d891bff8 100644
--- a/app/models/setting.rb
+++ b/app/models/setting.rb
@@ -29,6 +29,7 @@
class Setting < ApplicationRecord
extend CallbacksHelper
extend Aliases
+ extend MailSettings
ENCODINGS = %w(US-ASCII
windows-1250
diff --git a/app/models/setting/mail_settings.rb b/app/models/setting/mail_settings.rb
new file mode 100644
index 00000000000..5d84b7a3c0f
--- /dev/null
+++ b/app/models/setting/mail_settings.rb
@@ -0,0 +1,78 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2022 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+class Setting
+ module MailSettings
+ ##
+ # Reload the currently configured mailer configuration
+ def reload_mailer_settings!
+ ActionMailer::Base.perform_deliveries = true
+ ActionMailer::Base.delivery_method = Setting.email_delivery_method if Setting.email_delivery_method
+
+ if Setting.email_delivery_method == :smtp
+ reload_smtp_settings!
+ end
+ rescue StandardError => e
+ Rails.logger.error "Unable to set ActionMailer settings (#{e.message}). " \
+ "Email sending will most likely NOT work."
+ end
+
+ private
+
+ def reload_smtp_settings!
+ # Correct smtp settings when using authentication :none
+ authentication = Setting.smtp_authentication.try(:to_sym)
+ keys = %i[address port domain authentication user_name password]
+ if authentication == :none
+ # Rails Mailer will croak if passing :none as the authentication.
+ # Instead, it requires to be removed from its settings
+ ActionMailer::Base.smtp_settings.delete :user_name
+ ActionMailer::Base.smtp_settings.delete :password
+ ActionMailer::Base.smtp_settings.delete :authentication
+
+ keys = %i[address port domain]
+ end
+
+ keys.each do |setting|
+ value = Setting["smtp_#{setting}"]
+ if value.present?
+ ActionMailer::Base.smtp_settings[setting] = value
+ else
+ ActionMailer::Base.smtp_settings.delete setting
+ end
+ end
+
+ ActionMailer::Base.smtp_settings[:enable_starttls_auto] = Setting.smtp_enable_starttls_auto?
+ ActionMailer::Base.smtp_settings[:ssl] = Setting.smtp_ssl?
+
+ Setting.smtp_openssl_verify_mode.tap do |mode|
+ ActionMailer::Base.smtp_settings[:openssl_verify_mode] = mode unless mode.nil?
+ end
+ end
+ end
+end
diff --git a/app/workers/application_job.rb b/app/workers/application_job.rb
index da7eca59c93..3721af444fd 100644
--- a/app/workers/application_job.rb
+++ b/app/workers/application_job.rb
@@ -88,15 +88,15 @@ class ApplicationJob < ::ActiveJob::Base
# Since the email configuration is now done in the web app, we need to
# make sure that any changes to the configuration is correctly picked up
# by the background jobs at runtime.
- def reload_mailer_configuration!
- OpenProject::Configuration.reload_mailer_configuration!
+ def reload_mailer_settings!
+ Setting.reload_mailer_settings!
end
private
def clean_context
with_clean_request_store do
- reload_mailer_configuration!
+ reload_mailer_settings!
yield
end
diff --git a/config/application.rb b/config/application.rb
index 22a16c8c277..f9d2d84283e 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -44,7 +44,7 @@ if defined?(Bundler)
Bundler.require(*Rails.groups(:opf_plugins))
end
-require_relative '../lib/open_project/configuration'
+require_relative '../lib_static/open_project/configuration'
module OpenProject
class Application < Rails::Application
@@ -177,8 +177,6 @@ module OpenProject
# This allows for setting the root either via config file or via environment variable.
config.action_controller.relative_url_root = OpenProject::Configuration['rails_relative_url_root']
- OpenProject::Configuration.configure_cache(config)
-
config.active_job.queue_adapter = :delayed_job
config.action_controller.asset_host = OpenProject::Configuration::AssetHost.value
diff --git a/config/initializers/cache_store.rb b/config/initializers/cache_store.rb
new file mode 100644
index 00000000000..c57316fcee9
--- /dev/null
+++ b/config/initializers/cache_store.rb
@@ -0,0 +1,32 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2022 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+# Be sure to restart your server when you modify this file.
+OpenProject::Application.configure do
+ OpenProject::Configuration.configure_cache(config)
+end
diff --git a/config/initializers/migrate_email_settings.rb b/config/initializers/migrate_email_settings.rb
deleted file mode 100644
index f3b4f697cce..00000000000
--- a/config/initializers/migrate_email_settings.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-OpenProject::Application.configure do
- config.after_initialize do
- # settings table may not exist when you run db:migrate at installation
- # time, so just ignore this block when that happens.
- if Setting.settings_table_exists_yet?
- OpenProject::Configuration.migrate_mailer_configuration!
- OpenProject::Configuration.reload_mailer_configuration!
- end
- end
-end
diff --git a/lib_static/open_project/configuration.rb b/lib_static/open_project/configuration.rb
index 21d638de923..686a5deb68d 100644
--- a/lib_static/open_project/configuration.rb
+++ b/lib_static/open_project/configuration.rb
@@ -45,8 +45,6 @@ module OpenProject
end
def configure_cache(application_config)
- return unless override_cache_config? application_config
-
# rails defaults to :file_store, use :mem_cache_store when :memcache is configured in configuration.yml
# Also use :mem_cache_store for when :dalli_store is configured
cache_store = self['rails_cache_store'].try(:to_sym)
@@ -55,131 +53,20 @@ module OpenProject
when :memcache, :dalli_store
cache_config = [:mem_cache_store]
cache_config << self['cache_memcache_server'] if self['cache_memcache_server']
- # default to :file_store
+ # default to :file_store
when NilClass, :file_store
cache_config = [:file_store, Rails.root.join('tmp/cache')]
else
cache_config = [cache_store]
end
- parameters = cache_parameters
- cache_config << parameters if parameters.size > 0
+ parameters = cache_store_parameters
+ cache_config << parameters unless parameters.empty?
application_config.cache_store = cache_config
end
- def override_cache_config?(application_config)
- # override if cache store is not set
- # or cache store is :file_store
- # or there is something to overwrite it
- application_config.cache_store.nil? ||
- application_config.cache_store == :file_store ||
- self['rails_cache_store'].present?
- end
-
- def migrate_mailer_configuration!
- # do not migrate if forced to legacy configuration (using settings or ENV)
- return true if self['email_delivery_configuration'] == 'legacy'
- # do not migrate if no legacy configuration
- return true if self['email_delivery_method'].blank?
- # do not migrate if the setting already exists and is not blank
- return true if Setting.email_delivery_method.present?
-
- Rails.logger.info 'Migrating existing email configuration to the settings table...'
- Setting.email_delivery_method = self['email_delivery_method'].to_sym
-
- ['smtp_', 'sendmail_'].each do |config_type|
- mail_delivery_configs = Settings::Definition.all_of_prefix(config_type)
-
- next if mail_delivery_configs.empty?
-
- mail_delivery_configs.each do |config|
- Setting["#{config_type}#{config.name}"] = case config.value
- when TrueClass
- 1
- when FalseClass
- 0
- else
- v
- end
- end
- end
-
- true
- end
-
- def reload_mailer_configuration!
- if self['email_delivery_configuration'] == 'legacy'
- configure_legacy_action_mailer
- else
- case Setting.email_delivery_method
- when :smtp
- ActionMailer::Base.perform_deliveries = true
- ActionMailer::Base.delivery_method = Setting.email_delivery_method
-
- reload_smtp_settings!
- when :sendmail
- ActionMailer::Base.perform_deliveries = true
- ActionMailer::Base.delivery_method = Setting.email_delivery_method
- end
- end
- rescue StandardError => e
- Rails.logger.warn "Unable to set ActionMailer settings (#{e.message}). " \
- 'Email sending will most likely NOT work.'
- end
-
- # This is used to configure email sending from users who prefer to
- # continue using environment variables of configuration.yml settings. Our
- # hosted SaaS version requires this.
- def configure_legacy_action_mailer
- return true if self['email_delivery_method'].blank?
-
- ActionMailer::Base.perform_deliveries = true
- ActionMailer::Base.delivery_method = self['email_delivery_method'].to_sym
-
- %w[smtp_ sendmail_].each do |config_type|
- config = settings_of_prefix(config_type)
-
- next if config.empty?
-
- ActionMailer::Base.send("#{config_type}settings=", config)
- end
- end
-
- private
-
- def reload_smtp_settings!
- # Correct smtp settings when using authentication :none
- authentication = Setting.smtp_authentication.try(:to_sym)
- keys = %i[address port domain authentication user_name password]
- if authentication == :none
- # Rails Mailer will croak if passing :none as the authentication.
- # Instead, it requires to be removed from its settings
- ActionMailer::Base.smtp_settings.delete :user_name
- ActionMailer::Base.smtp_settings.delete :password
- ActionMailer::Base.smtp_settings.delete :authentication
-
- keys = %i[address port domain]
- end
-
- keys.each do |setting|
- value = Setting["smtp_#{setting}"]
- if value.present?
- ActionMailer::Base.smtp_settings[setting] = value
- else
- ActionMailer::Base.smtp_settings.delete setting
- end
- end
-
- ActionMailer::Base.smtp_settings[:enable_starttls_auto] = Setting.smtp_enable_starttls_auto?
- ActionMailer::Base.smtp_settings[:ssl] = Setting.smtp_ssl?
-
- Setting.smtp_openssl_verify_mode.tap do |mode|
- ActionMailer::Base.smtp_settings[:openssl_verify_mode] = mode unless mode.nil?
- end
- end
-
- def cache_parameters
+ def cache_store_parameters
mapping = {
'cache_expires_in_seconds' => %i[expires_in to_i],
'cache_namespace' => %i[namespace to_s]
@@ -194,6 +81,8 @@ module OpenProject
parameters
end
+ private
+
def method_missing(name, *args, &block)
setting_name = name.to_s.sub(/\?$/, '')
diff --git a/spec/lib/open_project/configuration_spec.rb b/spec/lib/open_project/configuration_spec.rb
index 653935c7663..1518314d6f3 100644
--- a/spec/lib/open_project/configuration_spec.rb
+++ b/spec/lib/open_project/configuration_spec.rb
@@ -55,225 +55,6 @@ describe OpenProject::Configuration, :settings_reset do
end
end
- describe '.migrate_mailer_configuration!' do
- before do
- allow(Setting)
- .to receive(:email_delivery_method=)
- end
-
- it 'does nothing if no legacy configuration given' do
- described_class['email_delivery_method'] = nil
- expect(described_class.migrate_mailer_configuration!).to be_truthy
- expect(Setting).not_to have_received(:email_delivery_method=)
- end
-
- it 'does nothing if email_delivery_configuration forced to legacy' do
- described_class['email_delivery_configuration'] = 'legacy'
- expect(described_class.migrate_mailer_configuration!).to be_truthy
- expect(Setting).not_to have_received(:email_delivery_method=)
- end
-
- it 'does nothing if setting already set' do
- described_class['email_delivery_method'] = :sendmail
- allow(Setting)
- .to receive(:email_delivery_method)
- .and_return(:sendmail)
- expect(Setting).not_to have_received(:email_delivery_method=)
- expect(described_class.migrate_mailer_configuration!).to be_truthy
- end
-
- it 'migrates the existing configuration to the settings table' do
- described_class['email_delivery_method'] = :smtp
- described_class['smtp_password'] = 'p4ssw0rd'
- described_class['smtp_address'] = 'smtp.example.com'
- described_class['smtp_port'] = 587
- described_class['smtp_user_name'] = 'username'
- described_class['smtp_enable_starttls_auto'] = true
- described_class['smtp_ssl'] = true
-
- expect(described_class.migrate_mailer_configuration!).to be_truthy
- expect(Setting.email_delivery_method).to eq(:smtp)
- expect(Setting.smtp_password).to eq('p4ssw0rd')
- expect(Setting.smtp_address).to eq('smtp.example.com')
- expect(Setting.smtp_port).to eq(587)
- expect(Setting.smtp_user_name).to eq('username')
- expect(Setting).to be_smtp_enable_starttls_auto
- expect(Setting).to be_smtp_ssl
- end
- end
-
- describe '.reload_mailer_configuration!' do
- before do
- allow(ActionMailer::Base)
- .to receive(:perform_deliveries=)
- allow(ActionMailer::Base)
- .to receive(:delivery_method=)
- end
-
- it 'uses the legacy method to configure email settings' do
- allow(described_class)
- .to receive(:configure_legacy_action_mailer)
- described_class['email_delivery_configuration'] = 'legacy'
- described_class.reload_mailer_configuration!
- expect(described_class).to have_received(:configure_legacy_action_mailer)
- end
-
- context 'without smtp_authentication and without ssl' do
- it 'uses the setting values',
- with_settings: {
- email_delivery_method: :smtp,
- smtp_authentication: :none,
- smtp_password: 'old',
- smtp_address: 'smtp.example.com',
- smtp_domain: 'example.com',
- smtp_port: 25,
- smtp_user_name: 'username',
- smtp_enable_starttls_auto: 1,
- smtp_ssl: 0
- } do
- described_class.reload_mailer_configuration!
- expect(ActionMailer::Base).to have_received(:perform_deliveries=).with(true)
- expect(ActionMailer::Base).to have_received(:delivery_method=).with(:smtp)
- expect(ActionMailer::Base.smtp_settings[:smtp_authentication]).to be_nil
- expect(ActionMailer::Base.smtp_settings).to eq(address: 'smtp.example.com',
- port: 25,
- domain: 'example.com',
- enable_starttls_auto: true,
- openssl_verify_mode: 'peer',
- ssl: false)
- end
- end
-
- context 'without smtp_authentication and with ssl' do
- it 'users the setting values',
- with_settings: {
- email_delivery_method: :smtp,
- smtp_authentication: :none,
- smtp_password: 'old',
- smtp_address: 'smtp.example.com',
- smtp_domain: 'example.com',
- smtp_port: 25,
- smtp_user_name: 'username',
- smtp_enable_starttls_auto: 0,
- smtp_ssl: 1
- } do
- described_class.reload_mailer_configuration!
- expect(ActionMailer::Base).to have_received(:perform_deliveries=).with(true)
- expect(ActionMailer::Base).to have_received(:delivery_method=).with(:smtp)
- expect(ActionMailer::Base.smtp_settings[:smtp_authentication]).to be_nil
- expect(ActionMailer::Base.smtp_settings).to eq(address: 'smtp.example.com',
- port: 25,
- domain: 'example.com',
- enable_starttls_auto: false,
- openssl_verify_mode: 'peer',
- ssl: true)
- end
- end
-
- context 'with smtp_authentication and without ssl' do
- it 'users the setting values',
- with_settings: {
- email_delivery_method: :smtp,
- smtp_password: 'p4ssw0rd',
- smtp_address: 'smtp.example.com',
- smtp_domain: 'example.com',
- smtp_port: 587,
- smtp_user_name: 'username',
- smtp_enable_starttls_auto: 1,
- smtp_ssl: 0
- } do
- described_class.reload_mailer_configuration!
- expect(ActionMailer::Base).to have_received(:perform_deliveries=).with(true)
- expect(ActionMailer::Base).to have_received(:delivery_method=).with(:smtp)
- expect(ActionMailer::Base.smtp_settings[:smtp_authentication]).to be_nil
- expect(ActionMailer::Base.smtp_settings).to eq(address: 'smtp.example.com',
- port: 587,
- domain: 'example.com',
- authentication: 'plain',
- user_name: 'username',
- password: 'p4ssw0rd',
- enable_starttls_auto: true,
- openssl_verify_mode: 'peer',
- ssl: false)
- end
- end
-
- context 'with smtp_authentication and with ssl' do
- it 'users the setting values',
- with_settings: {
- email_delivery_method: :smtp,
- smtp_password: 'p4ssw0rd',
- smtp_address: 'smtp.example.com',
- smtp_domain: 'example.com',
- smtp_port: 587,
- smtp_user_name: 'username',
- smtp_enable_starttls_auto: 0,
- smtp_ssl: 1
- } do
- described_class.reload_mailer_configuration!
- expect(ActionMailer::Base).to have_received(:perform_deliveries=).with(true)
- expect(ActionMailer::Base).to have_received(:delivery_method=).with(:smtp)
- expect(ActionMailer::Base.smtp_settings[:smtp_authentication]).to be_nil
- expect(ActionMailer::Base.smtp_settings).to eq(address: 'smtp.example.com',
- port: 587,
- domain: 'example.com',
- authentication: 'plain',
- user_name: 'username',
- password: 'p4ssw0rd',
- enable_starttls_auto: false,
- openssl_verify_mode: 'peer',
- ssl: true)
- end
- end
- end
-
- describe '.configure_legacy_action_mailer' do
- let(:action_mailer) do
- class_double('ActionMailer::Base',
- deliveries: []).tap do |mailer|
- allow(mailer).to receive(:perform_deliveries=)
- allow(mailer).to receive(:delivery_method=)
- allow(mailer).to receive(:smtp_settings=)
- end
- end
- let(:settings) do
- { 'email_delivery_method' => 'smtp',
- 'smtp_address' => 'smtp.example.net',
- 'smtp_port' => '25' }.map do |name, value|
- API::ParserStruct.new name: name, value: value
- end
- end
-
- before do
- allow(Settings::Definition)
- .to receive(:[]) do |name|
- settings.detect { |s| s.name == name }
- end
-
- allow(Settings::Definition)
- .to receive(:all_of_prefix) do |prefix|
- settings.select { |s| s.name.start_with?(prefix) }
- end
-
- stub_const('ActionMailer::Base', action_mailer)
- end
-
- it 'enables deliveries and configure ActionMailer smtp delivery' do
- described_class.send(:configure_legacy_action_mailer)
-
- expect(action_mailer)
- .to have_received(:perform_deliveries=)
- .with(true)
- expect(action_mailer)
- .to have_received(:delivery_method=)
- .with(:smtp)
- expect(action_mailer)
- .to have_received(:smtp_settings=)
- .with(address: 'smtp.example.net',
- port: '25')
- end
- end
-
describe '.configure_cache' do
let(:application_config) do
Rails::Application::Configuration.new Rails.root
@@ -294,17 +75,6 @@ describe OpenProject::Configuration, :settings_reset do
expect(application_config.cache_store).to eq([:bar])
end
end
-
- context 'without additional cache store configuration' do
- before do
- described_class['rails_cache_store'] = nil
- end
-
- it 'does not change the cache store' do
- described_class.send(:configure_cache, application_config)
- expect(application_config.cache_store).to eq('foo')
- end
- end
end
context 'without cache store already set' do
diff --git a/spec/mailers/smtp_settings_spec.rb b/spec/mailers/smtp_settings_spec.rb
index 652f08a30cc..827f9df4b5d 100644
--- a/spec/mailers/smtp_settings_spec.rb
+++ b/spec/mailers/smtp_settings_spec.rb
@@ -53,7 +53,7 @@ describe "SMTP settings" do
allow(Setting).to receive(:smtp_ssl?).and_return ssl
end
- OpenProject::Configuration.reload_mailer_configuration!
+ Setting.reload_mailer_settings!
end
def send_mail
@@ -166,4 +166,4 @@ describe "SMTP settings" do
end
end
end
-end
\ No newline at end of file
+end
diff --git a/spec/models/setting_spec.rb b/spec/models/setting_spec.rb
index 68117a1c3cf..f1d6bfedaee 100644
--- a/spec/models/setting_spec.rb
+++ b/spec/models/setting_spec.rb
@@ -474,4 +474,121 @@ describe Setting, type: :model do
expect(collector).to include 'some name'
end
end
+
+ describe '.reload_mailer_settings!' do
+ before do
+ allow(ActionMailer::Base)
+ .to receive(:perform_deliveries=)
+ allow(ActionMailer::Base)
+ .to receive(:delivery_method=)
+ end
+
+ context 'without smtp_authentication and without ssl' do
+ it 'uses the setting values',
+ with_settings: {
+ email_delivery_method: :smtp,
+ smtp_authentication: :none,
+ smtp_password: 'old',
+ smtp_address: 'smtp.example.com',
+ smtp_domain: 'example.com',
+ smtp_port: 25,
+ smtp_user_name: 'username',
+ smtp_enable_starttls_auto: 1,
+ smtp_ssl: 0
+ } do
+ described_class.reload_mailer_settings!
+ expect(ActionMailer::Base).to have_received(:perform_deliveries=).with(true)
+ expect(ActionMailer::Base).to have_received(:delivery_method=).with(:smtp)
+ expect(ActionMailer::Base.smtp_settings[:smtp_authentication]).to be_nil
+ expect(ActionMailer::Base.smtp_settings).to eq(address: 'smtp.example.com',
+ port: 25,
+ domain: 'example.com',
+ enable_starttls_auto: true,
+ openssl_verify_mode: 'peer',
+ ssl: false)
+ end
+ end
+
+ context 'without smtp_authentication and with ssl' do
+ it 'users the setting values',
+ with_settings: {
+ email_delivery_method: :smtp,
+ smtp_authentication: :none,
+ smtp_password: 'old',
+ smtp_address: 'smtp.example.com',
+ smtp_domain: 'example.com',
+ smtp_port: 25,
+ smtp_user_name: 'username',
+ smtp_enable_starttls_auto: 0,
+ smtp_ssl: 1
+ } do
+ described_class.reload_mailer_settings!
+ expect(ActionMailer::Base).to have_received(:perform_deliveries=).with(true)
+ expect(ActionMailer::Base).to have_received(:delivery_method=).with(:smtp)
+ expect(ActionMailer::Base.smtp_settings[:smtp_authentication]).to be_nil
+ expect(ActionMailer::Base.smtp_settings).to eq(address: 'smtp.example.com',
+ port: 25,
+ domain: 'example.com',
+ enable_starttls_auto: false,
+ openssl_verify_mode: 'peer',
+ ssl: true)
+ end
+ end
+
+ context 'with smtp_authentication and without ssl' do
+ it 'users the setting values',
+ with_settings: {
+ email_delivery_method: :smtp,
+ smtp_password: 'p4ssw0rd',
+ smtp_address: 'smtp.example.com',
+ smtp_domain: 'example.com',
+ smtp_port: 587,
+ smtp_user_name: 'username',
+ smtp_enable_starttls_auto: 1,
+ smtp_ssl: 0
+ } do
+ described_class.reload_mailer_settings!
+ expect(ActionMailer::Base).to have_received(:perform_deliveries=).with(true)
+ expect(ActionMailer::Base).to have_received(:delivery_method=).with(:smtp)
+ expect(ActionMailer::Base.smtp_settings[:smtp_authentication]).to be_nil
+ expect(ActionMailer::Base.smtp_settings).to eq(address: 'smtp.example.com',
+ port: 587,
+ domain: 'example.com',
+ authentication: 'plain',
+ user_name: 'username',
+ password: 'p4ssw0rd',
+ enable_starttls_auto: true,
+ openssl_verify_mode: 'peer',
+ ssl: false)
+ end
+ end
+
+ context 'with smtp_authentication and with ssl' do
+ it 'users the setting values',
+ with_settings: {
+ email_delivery_method: :smtp,
+ smtp_password: 'p4ssw0rd',
+ smtp_address: 'smtp.example.com',
+ smtp_domain: 'example.com',
+ smtp_port: 587,
+ smtp_user_name: 'username',
+ smtp_enable_starttls_auto: 0,
+ smtp_ssl: 1
+ } do
+ described_class.reload_mailer_settings!
+ expect(ActionMailer::Base).to have_received(:perform_deliveries=).with(true)
+ expect(ActionMailer::Base).to have_received(:delivery_method=).with(:smtp)
+ expect(ActionMailer::Base.smtp_settings[:smtp_authentication]).to be_nil
+ expect(ActionMailer::Base.smtp_settings).to eq(address: 'smtp.example.com',
+ port: 587,
+ domain: 'example.com',
+ authentication: 'plain',
+ user_name: 'username',
+ password: 'p4ssw0rd',
+ enable_starttls_auto: false,
+ openssl_verify_mode: 'peer',
+ ssl: true)
+ end
+ end
+ end
end