From b06b99ab5fbc395ae78ee82af1d53857c4d2cfc9 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 28 Mar 2019 15:22:35 +0200 Subject: [PATCH] Add mailers' preview --- config/application.rb | 3 +++ config/environments/staging-example.rb | 4 ++++ .../previews/domain_delete_mailer_preview.rb | 15 +++++++++++++++ .../previews/domain_expire_mailer_preview.rb | 7 +++++++ 4 files changed, 29 insertions(+) create mode 100644 test/mailers/previews/domain_delete_mailer_preview.rb create mode 100644 test/mailers/previews/domain_expire_mailer_preview.rb diff --git a/config/application.rb b/config/application.rb index 1420d3cd3a..26da91b5de 100644 --- a/config/application.rb +++ b/config/application.rb @@ -77,6 +77,9 @@ class Application < Rails::Application config.action_mailer.perform_deliveries = true config.action_mailer.raise_delivery_errors = true + # Override "spec/mailers/previews" that RSpec sets + config.action_mailer.preview_path = "#{Rails.root}/test/mailers/previews" + config.action_mailer.smtp_settings = { address: ENV['smtp_address'], port: ENV['smtp_port'], diff --git a/config/environments/staging-example.rb b/config/environments/staging-example.rb index 8af2ff60de..b6d2450065 100644 --- a/config/environments/staging-example.rb +++ b/config/environments/staging-example.rb @@ -1 +1,5 @@ require_relative 'production' + +Rails.application.configure do + config.action_mailer.show_previews = true +end \ No newline at end of file diff --git a/test/mailers/previews/domain_delete_mailer_preview.rb b/test/mailers/previews/domain_delete_mailer_preview.rb new file mode 100644 index 0000000000..12dbbad694 --- /dev/null +++ b/test/mailers/previews/domain_delete_mailer_preview.rb @@ -0,0 +1,15 @@ +class DomainDeleteMailerPreview < ActionMailer::Preview + def self.define_forced_templates + DomainDeleteMailer.force_delete_templates.each do |template_name| + define_method "forced_#{template_name}".to_sym do + domain = Domain.first + DomainDeleteMailer.forced(domain: domain, + registrar: domain.registrar, + registrant: domain.registrant, + template_name: template_name) + end + end + end + + define_forced_templates +end \ No newline at end of file diff --git a/test/mailers/previews/domain_expire_mailer_preview.rb b/test/mailers/previews/domain_expire_mailer_preview.rb new file mode 100644 index 0000000000..bec206c0fc --- /dev/null +++ b/test/mailers/previews/domain_expire_mailer_preview.rb @@ -0,0 +1,7 @@ +class DomainExpireMailerPreview < ActionMailer::Preview + def expired + domain = Domain.first + DomainExpireMailer.expired(domain: domain, + registrar: domain.registrar) + end +end \ No newline at end of file