forked from SplitTime/OpenSplitTime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set up ActionMailer; send mail to admin when new event is created.
- Loading branch information
Showing
14 changed files
with
120 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class AdminMailer < ApplicationMailer | ||
def new_event(event, user) | ||
@event = event | ||
@user = user | ||
mail(to: ENV['ADMIN_EMAIL'], subject: "New event: #{@event.name}") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
class ApplicationMailer < ActionMailer::Base | ||
default from: "no-reply@#{ENV['BASE_URI']}" | ||
# layout 'mailer' | ||
layout 'mailer' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<p> | ||
<%= "#{@user.full_name} has created a new event called" %> | ||
<%= link_to @event.name, event_url(@event) %> | ||
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= "#{@user.full_name} has created a new event called #{@event.name}." %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | ||
<style> | ||
/* Email styles need to be inline */ | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<%= yield %> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= yield %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe AdminMailer, type: :mailer do | ||
include ActiveJob::TestHelper | ||
let(:user){ create(:user) } | ||
let(:event) { create(:event) } | ||
|
||
it 'creates a job' do | ||
ActiveJob::Base.queue_adapter = :test | ||
expect { AdminMailer.new_event(event, user).deliver_later }.to have_enqueued_job.on_queue('mailers') | ||
end | ||
|
||
# Because we have config.action_mailer.delivery_method set to :test in our :test.rb, | ||
# all 'sent' emails are gathered into the ActionMailer::Base.deliveries array. | ||
|
||
it 'sends an email' do | ||
expect { | ||
perform_enqueued_jobs do | ||
AdminMailer.new_event(event, user).deliver_later | ||
end | ||
}.to change { ActionMailer::Base.deliveries.size }.by(1) | ||
end | ||
|
||
it 'sends email to the correct admin' do | ||
perform_enqueued_jobs do | ||
AdminMailer.new_event(event, user).deliver_later | ||
end | ||
|
||
mail = ActionMailer::Base.deliveries.last | ||
expect(mail.to[0]).to eq ENV['ADMIN_EMAIL'] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Preview all emails at http://localhost:3000/rails/mailers/admin_mailer | ||
class AdminMailerPreview < ActionMailer::Preview | ||
def new_event | ||
event = Event.first | ||
user = User.first | ||
AdminMailer.new_event(event, user) | ||
end | ||
end |