Skip to content

Commit

Permalink
refactor: Mailer -> UserMailer
Browse files Browse the repository at this point in the history
  • Loading branch information
sman591 committed May 27, 2019
1 parent c4df212 commit a77aa96
Show file tree
Hide file tree
Showing 13 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions app/controllers/manage/messages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion app/jobs/bulk_message_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -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?
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/mail_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/mailer.rb → app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Mailer < ApplicationMailer
class UserMailer < ApplicationMailer
include Roadie::Rails::Automatic
add_template_helper(HackathonManagerHelper)

Expand Down
2 changes: 1 addition & 1 deletion app/models/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion app/views/mailer/bulk_message_email.html.erb

This file was deleted.

1 change: 1 addition & 0 deletions app/views/user_mailer/bulk_message_email.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render partial: "user_mailer/bulk_templates/#{@message.template}" %>
2 changes: 1 addition & 1 deletion config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,6 @@

# Devise
Rails.application.config.to_prepare do
Devise::Mailer.layout "mailer"
Devise::Mailer.layout "user_mailer"
end
end
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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!")
@user = create(:user, email: "test@example.com")
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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit a77aa96

Please sign in to comment.