Skip to content

Commit

Permalink
Merge pull request #368 from sul-dlss/mail_template
Browse files Browse the repository at this point in the history
Mail template
  • Loading branch information
peetucket committed Sep 27, 2018
2 parents bd01d39 + ca21977 commit e1b7b02
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 9 deletions.
3 changes: 1 addition & 2 deletions app/mailers/job_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class JobMailer < ApplicationMailer
def completion_email
@job_run = params[:job_run]
@user = @job_run.bundle_context.user
mail(to: @user.email, subject: 'Your pre-assembly job has completed')
mail(to: @user.email, subject: @job_run.mail_subject)
end

end
5 changes: 5 additions & 0 deletions app/models/job_run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ def enqueue!
"#{job_type.camelize}Job".constantize.perform_later(self)
end

# @return [String] Subject line for notification email
def mail_subject
"[#{bundle_context.project_name}] Your #{job_type.humanize} job completed"
end

def send_notification
return unless output_location
JobMailer.with(job_run: self).completion_email.deliver_later
Expand Down
4 changes: 2 additions & 2 deletions app/views/job_mailer/completion_email.text.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Your <%=@job_run.job_type%> job #<%=@job_run.id%> completed. View the job details here: "=url_for(@job_run) will go here".
<%# TODO: update URL_FOR above when https://github.com/sul-dlss/pre-assembly/issues/295 completed %>
Your <%= @job_run.job_type.humanize %> job #<%= @job_run.id %> completed.
You can view the job details and log file at: <%= job_run_url(@job_run); %>
4 changes: 1 addition & 3 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@
# Store uploaded files on the local file system (see config/storage.yml for options)
config.active_storage.service = :local

# config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } # from Devise setup, though we don't expect it to be used

config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } # needed by url_for() in mail templates
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false

config.action_mailer.perform_caching = false

# Print deprecation notices to the Rails logger.
Expand Down
1 change: 1 addition & 0 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
# Use a real queuing backend for Active Job
config.active_job.queue_adapter = :resque

config.action_mailer.default_url_options = { host: 'sul-preassembly-prod.stanford.edu' } # needed by url_for() in mail templates
config.action_mailer.perform_caching = false

# Ignore bad email addresses and do not raise email delivery errors.
Expand Down
1 change: 1 addition & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
# Store uploaded files on the local file system in a temporary directory
config.active_storage.service = :test

config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } # needed by url_for() in mail templates
config.action_mailer.perform_caching = false

# Tell Action Mailer not to deliver emails to the real world.
Expand Down
13 changes: 11 additions & 2 deletions spec/mailers/job_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@
let(:job_notification) { described_class.with(job_run: job_run).completion_email }

it 'renders the headers' do
expect(job_notification.subject).to eq("Your pre-assembly job has completed")
expect(job_notification.subject).to eq("[Test_Project] Your Discovery report job completed")
expect(job_notification.to).to eq([job_run.bundle_context.user.email])
expect(job_notification.from).to eq(["no-reply-preassembly-job@stanford.edu"])
end

describe 'subject' do
before { job_run.job_type = 1 }

it 'adapts depending on job_type' do
expect(job_notification.subject).to eq("[Test_Project] Your Preassembly job completed")
end
end

it 'renders the body' do
expect(job_notification.body.encoded).to include("Your discovery_report job \##{job_run.id} completed")
expect(job_notification.body.encoded).to include("Your Discovery report job \##{job_run.id} completed")
.and include("http://localhost:3000/job_runs/#{job_run.id}")
end
end

0 comments on commit e1b7b02

Please sign in to comment.