diff options
-rw-r--r-- | app/mailers/info_request_batch_mailer.rb | 25 | ||||
-rw-r--r-- | app/views/info_request_batch_mailer/batch_sent.text.erb | 15 | ||||
-rw-r--r-- | spec/mailers/info_request_batch_mailer.rb | 35 |
3 files changed, 75 insertions, 0 deletions
diff --git a/app/mailers/info_request_batch_mailer.rb b/app/mailers/info_request_batch_mailer.rb new file mode 100644 index 000000000..a2becfb24 --- /dev/null +++ b/app/mailers/info_request_batch_mailer.rb @@ -0,0 +1,25 @@ +# models/info_request_batch_mailer.rb: +# Emails relating to user accounts. e.g. Confirming a new account +# +# Copyright (c) 2013 UK Citizens Online Democracy. All rights reserved. +# Email: hello@mysociety.org; WWW: http://www.mysociety.org/ + +class InfoRequestBatchMailer < ApplicationMailer + + def batch_sent(info_request_batch, unrequestable, user) + @info_request_batch, @unrequestable = info_request_batch, unrequestable + headers('Return-Path' => blackhole_email, 'Reply-To' => contact_from_name_and_email) + + # Make a link going to the info request batch page, which logs the user in. + post_redirect = PostRedirect.new( + :uri => info_request_batch_url(@info_request_batch), + :user_id => info_request_batch.user_id) + post_redirect.save! + @url = confirm_url(:email_token => post_redirect.email_token) + + mail(:from => contact_from_name_and_email, + :to => user.name_and_email, + :subject => _("Your batch request \"{{title}}\" has been sent", + :title => info_request_batch.title)) + end +end diff --git a/app/views/info_request_batch_mailer/batch_sent.text.erb b/app/views/info_request_batch_mailer/batch_sent.text.erb new file mode 100644 index 000000000..25fb7d06a --- /dev/null +++ b/app/views/info_request_batch_mailer/batch_sent.text.erb @@ -0,0 +1,15 @@ +<%= _('Your batch request "{{title}}" has been sent', :title => @info_request_batch.title) %> + + +<%= _('Follow this link to see the requests:')%> + +<%= @url %> + +<% if !@unrequestable.empty? %> +<%= _('Unfortunately, we do not have a working address for {{public_body_names}}.', :public_body_names => @unrequestable.map{|body| body.name}.join(",")) %> +<%= _('You may be able to find one on their website, or by phoning them up and asking. If you manage to find one, then please send it to us:') %> + +<%= help_contact_url %> + +<% end %> +-- <%= _('the {{site_name}} team', :site_name => site_name) %> diff --git a/spec/mailers/info_request_batch_mailer.rb b/spec/mailers/info_request_batch_mailer.rb new file mode 100644 index 000000000..19791e163 --- /dev/null +++ b/spec/mailers/info_request_batch_mailer.rb @@ -0,0 +1,35 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe InfoRequestBatchMailer do + + describe 'when sending batch sent notification' do + + before do + @user = FactoryGirl.create(:user) + @info_request_batch = FactoryGirl.create(:info_request_batch) + @public_body = FactoryGirl.create(:public_body) + @unrequestable = [@public_body] + @mail = InfoRequestBatchMailer.batch_sent(@info_request_batch, @unrequestable, @user) + end + + it 'renders the subject' do + @mail.subject.should == 'Your batch request "Example title" has been sent' + end + + it 'renders the receiver email' do + @mail.to.should == [@user.email] + end + + it 'renders the sender email' do + @mail.from.should == ['postmaster@localhost'] + end + + it 'assigns @unrequestable' do + @mail.body.encoded.should match(@public_body.name) + end + + it 'assigns @url' do + @mail.body.encoded.should match("http://test.host/en/c/") + end + end +end |