From a77aa9600c2f00205c559f4c502b7d850228dc66 Mon Sep 17 00:00:00 2001 From: Stuart Olivera Date: Mon, 27 May 2019 13:28:32 -0400 Subject: [PATCH] refactor: Mailer -> UserMailer --- app/controllers/manage/messages_controller.rb | 6 +++--- app/jobs/bulk_message_job.rb | 2 +- app/mailers/application_mailer.rb | 2 +- app/mailers/mail_preview.rb | 2 +- app/mailers/{mailer.rb => user_mailer.rb} | 2 +- app/models/message.rb | 2 +- app/models/user.rb | 2 +- .../layouts/{mailer.html.erb => user_mailer.html.erb} | 0 app/views/mailer/bulk_message_email.html.erb | 1 - app/views/user_mailer/bulk_message_email.html.erb | 1 + .../bulk_templates/_default.html.erb | 0 config/initializers/devise.rb | 2 +- test/controllers/{mailer_test.rb => user_mailer_test.rb} | 8 ++++---- 13 files changed, 15 insertions(+), 15 deletions(-) rename app/mailers/{mailer.rb => user_mailer.rb} (96%) rename app/views/layouts/{mailer.html.erb => user_mailer.html.erb} (100%) delete mode 100644 app/views/mailer/bulk_message_email.html.erb create mode 100644 app/views/user_mailer/bulk_message_email.html.erb rename app/views/{mailer => user_mailer}/bulk_templates/_default.html.erb (100%) rename test/controllers/{mailer_test.rb => user_mailer_test.rb} (81%) diff --git a/app/controllers/manage/messages_controller.rb b/app/controllers/manage/messages_controller.rb index 909eac07e..33380188c 100644 --- a/app/controllers/manage/messages_controller.rb +++ b/app/controllers/manage/messages_controller.rb @@ -59,14 +59,14 @@ def deliver end def preview - email = Mailer.bulk_message_email(@message.id, current_user.id, nil, true) + email = UserMailer.bulk_message_email(@message.id, current_user.id, nil, true) render html: email.body.raw_source.html_safe end def live_preview body = params[:body] || "" message = Message.new(body: body) - email = Mailer.bulk_message_email(nil, current_user.id, message, true) + email = UserMailer.bulk_message_email(nil, current_user.id, message, true) render html: email.body.raw_source.html_safe end @@ -88,7 +88,7 @@ def template def template_preview body = File.read("app/views/manage/messages/_template_example.html.md") message = Message.new(body: body) - email = Mailer.bulk_message_email(nil, current_user.id, message, true) + email = UserMailer.bulk_message_email(nil, current_user.id, message, true) render html: email.body.raw_source.html_safe end diff --git a/app/jobs/bulk_message_job.rb b/app/jobs/bulk_message_job.rb index c6479f0f6..2989e6564 100644 --- a/app/jobs/bulk_message_job.rb +++ b/app/jobs/bulk_message_job.rb @@ -9,7 +9,7 @@ def perform(message) recipients = self.class.build_recipients(message.recipients) recipients.each do |recipient| - Mailer.bulk_message_email(message.id, recipient).deliver_later + UserMailer.bulk_message_email(message.id, recipient).deliver_later end message.update_attribute(:delivered_at, Time.now) diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 26d84d05b..0758f85ae 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,6 +1,6 @@ class ApplicationMailer < ActionMailer::Base default from: -> { HackathonConfig["email_from"] } - layout "mailer" + layout "user_mailer" def pretty_email(name, email) return email if name.blank? diff --git a/app/mailers/mail_preview.rb b/app/mailers/mail_preview.rb index f03eeeb29..d29bda648 100644 --- a/app/mailers/mail_preview.rb +++ b/app/mailers/mail_preview.rb @@ -2,7 +2,7 @@ class MailPreview < ActionMailer::Preview def bulk_message_email message = Message.first - Mailer.bulk_message_email(message, User.first.id) + UserMailer.bulk_message_email(message, User.first.id) end def admin_weekly_report diff --git a/app/mailers/mailer.rb b/app/mailers/user_mailer.rb similarity index 96% rename from app/mailers/mailer.rb rename to app/mailers/user_mailer.rb index 96bf3ecce..c13612be3 100644 --- a/app/mailers/mailer.rb +++ b/app/mailers/user_mailer.rb @@ -1,4 +1,4 @@ -class Mailer < ApplicationMailer +class UserMailer < ApplicationMailer include Roadie::Rails::Automatic add_template_helper(HackathonManagerHelper) diff --git a/app/models/message.rb b/app/models/message.rb index f8b1f7586..cf6fcd1c3 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -171,7 +171,7 @@ def self.for_trigger(trigger) end def self.queue_for_trigger(trigger, user_id) - for_trigger(trigger).map { |message| Mailer.bulk_message_email(message.id, user_id).deliver_later } + for_trigger(trigger).map { |message| UserMailer.bulk_message_email(message.id, user_id).deliver_later } end def self.bulk diff --git a/app/models/user.rb b/app/models/user.rb index 12be798b8..7667d98cd 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -32,7 +32,7 @@ def send_devise_notification(notification, *args) def queue_reminder_email return if reminder_sent_at - Mailer.incomplete_reminder_email(id).deliver_later(wait: 1.day) + UserMailer.incomplete_reminder_email(id).deliver_later(wait: 1.day) update_attribute(:reminder_sent_at, Time.now) end diff --git a/app/views/layouts/mailer.html.erb b/app/views/layouts/user_mailer.html.erb similarity index 100% rename from app/views/layouts/mailer.html.erb rename to app/views/layouts/user_mailer.html.erb diff --git a/app/views/mailer/bulk_message_email.html.erb b/app/views/mailer/bulk_message_email.html.erb deleted file mode 100644 index 0bc64b42b..000000000 --- a/app/views/mailer/bulk_message_email.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= render partial: "mailer/bulk_templates/#{@message.template}" %> diff --git a/app/views/user_mailer/bulk_message_email.html.erb b/app/views/user_mailer/bulk_message_email.html.erb new file mode 100644 index 000000000..0e271e552 --- /dev/null +++ b/app/views/user_mailer/bulk_message_email.html.erb @@ -0,0 +1 @@ +<%= render partial: "user_mailer/bulk_templates/#{@message.template}" %> diff --git a/app/views/mailer/bulk_templates/_default.html.erb b/app/views/user_mailer/bulk_templates/_default.html.erb similarity index 100% rename from app/views/mailer/bulk_templates/_default.html.erb rename to app/views/user_mailer/bulk_templates/_default.html.erb diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 1016c0aca..5295a105b 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -263,6 +263,6 @@ # Devise Rails.application.config.to_prepare do - Devise::Mailer.layout "mailer" + Devise::Mailer.layout "user_mailer" end end diff --git a/test/controllers/mailer_test.rb b/test/controllers/user_mailer_test.rb similarity index 81% rename from test/controllers/mailer_test.rb rename to test/controllers/user_mailer_test.rb index b92ca462f..5b9d237e4 100644 --- a/test/controllers/mailer_test.rb +++ b/test/controllers/user_mailer_test.rb @@ -1,6 +1,6 @@ require "test_helper" -class MailerTest < ActionMailer::TestCase +class UserMailerTest < ActionMailer::TestCase context "upon trigger of a bulk message" do setup do @message = create(:message, subject: "Example Subject", body: "Hello World!") @@ -8,7 +8,7 @@ class MailerTest < ActionMailer::TestCase end should "deliver bulk messages" do - email = Mailer.bulk_message_email(@message.id, @user.id).deliver_now + email = UserMailer.bulk_message_email(@message.id, @user.id).deliver_now assert_equal ["test@example.com"], email.to assert_equal "Example Subject", email.subject @@ -24,7 +24,7 @@ class MailerTest < ActionMailer::TestCase should "queue reminder bulk message" do assert_difference "enqueued_jobs.size", 1 do - Mailer.incomplete_reminder_email(@user.id).deliver_later + UserMailer.incomplete_reminder_email(@user.id).deliver_later end end end @@ -37,7 +37,7 @@ class MailerTest < ActionMailer::TestCase end should "use customized email_from" do - email = Mailer.bulk_message_email(@message.id, @user.id).deliver_now + email = UserMailer.bulk_message_email(@message.id, @user.id).deliver_now assert_equal ["test@custom.example.com"], email.from end