Skip to content

Commit

Permalink
Send/delete batch upload emails to user_email, if specified
Browse files Browse the repository at this point in the history
  • Loading branch information
tallenaz committed Oct 28, 2016
1 parent 042d800 commit 3f61c4d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
16 changes: 12 additions & 4 deletions app/mailers/webforms_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@ class WebformsMailer < ApplicationMailer
def batch_upload_email(uni_updates_batch, duplicates)
@uni_updates_batch = uni_updates_batch
@duplicates = duplicates
destination = 'sul-unicorn-devs@lists.stanford.edu'
mail(to: destination, subject: 'batch record update')
all_recipients = ['sul-unicorn-devs@lists.stanford.edu']
if @uni_updates_batch.user_email
form_recipients = @uni_updates_batch.user_email.split(',')
all_recipients << form_recipients
end
mail(to: all_recipients, subject: 'batch record update')
end

def batch_delete_email(uni_updates_batch)
@uni_updates_batch = uni_updates_batch
destination = 'sul-unicorn-devs@lists.stanford.edu'
mail(to: destination, subject: 'batch record deletion')
all_recipients = ['sul-unicorn-devs@lists.stanford.edu']
if @uni_updates_batch.user_email
form_recipients = @uni_updates_batch.user_email.split(',')
all_recipients << form_recipients
end
mail(to: all_recipients, subject: 'batch record deletion')
end
end
14 changes: 11 additions & 3 deletions spec/mailers/webforms_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@
describe WebformsMailer do
describe 'batch update and delete mail' do
let(:uni_updates_batch) { FactoryGirl.create(:uni_updates_batch) }
let(:uni_updates_batch_w_no_user) { FactoryGirl.create(:uni_updates_batch, user_email: '') }
let(:upload_mail) { WebformsMailer.batch_upload_email(uni_updates_batch, ['123']) }
let(:upload_mail_no_user) { WebformsMailer.batch_upload_email(uni_updates_batch_w_no_user, ['123']) }
let(:delete_mail) { WebformsMailer.batch_delete_email(uni_updates_batch) }
let(:delete_mail_no_user) { WebformsMailer.batch_delete_email(uni_updates_batch_w_no_user) }

describe 'to' do
it 'is the list email address' do
expect(upload_mail.to).to eq ['sul-unicorn-devs@lists.stanford.edu']
expect(delete_mail.to).to eq ['sul-unicorn-devs@lists.stanford.edu']
it 'is the list email address and email_user' do
expect(upload_mail.to).to eq ['sul-unicorn-devs@lists.stanford.edu', 'libraryuser@stanford.edu']
expect(delete_mail.to).to eq ['sul-unicorn-devs@lists.stanford.edu', 'libraryuser@stanford.edu']
end

it 'is just the email address when no email_user is specified' do
expect(upload_mail_no_user.to).to eq ['sul-unicorn-devs@lists.stanford.edu']
expect(delete_mail_no_user.to).to eq ['sul-unicorn-devs@lists.stanford.edu']
end
end

Expand Down

0 comments on commit 3f61c4d

Please sign in to comment.