adding attachments to all recepients
This commit is contained in:
parent
4be75a255f
commit
c64588a68d
3 changed files with 26 additions and 13 deletions
|
|
@ -6,7 +6,7 @@ class Notifier < ActionMailer::Base
|
||||||
def self.admin(string, recipients, opts = {})
|
def self.admin(string, recipients, opts = {})
|
||||||
mails = []
|
mails = []
|
||||||
recipients.each do |rec|
|
recipients.each do |rec|
|
||||||
mail = single_admin(string, rec, opts)
|
mail = single_admin(string, rec, opts.dup)
|
||||||
mails << mail
|
mails << mail
|
||||||
end
|
end
|
||||||
mails
|
mails
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,6 @@ namespace :stats do
|
||||||
|
|
||||||
emails = Notifier.admin( "here are some retention stats", admins, {:subject => "retention numbers #{Time.now.to_s}",
|
emails = Notifier.admin( "here are some retention stats", admins, {:subject => "retention numbers #{Time.now.to_s}",
|
||||||
:attachments => [{:name => "retention_numbers_#{Time.now.to_s}.csv", :file => string}]})
|
:attachments => [{:name => "retention_numbers_#{Time.now.to_s}.csv", :file => string}]})
|
||||||
emails.each {|e| e.deliver!}
|
emails.each {|e| e.deliver}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -18,19 +18,32 @@ describe Notifier do
|
||||||
mail.body.encoded.should match /Welcome to bureaucracy!/
|
mail.body.encoded.should match /Welcome to bureaucracy!/
|
||||||
mail.body.encoded.should match /#{bob.username}/
|
mail.body.encoded.should match /#{bob.username}/
|
||||||
end
|
end
|
||||||
it 'mails a bunch of users' do
|
|
||||||
users = []
|
context 'mails a bunch of users' do
|
||||||
|
before do
|
||||||
|
@users = []
|
||||||
5.times do
|
5.times do
|
||||||
users << Factory.create(:user)
|
@users << Factory.create(:user)
|
||||||
end
|
end
|
||||||
mails = Notifier.admin("Welcome to bureaucracy!", users)
|
end
|
||||||
|
it 'has a body' do
|
||||||
|
mails = Notifier.admin("Welcome to bureaucracy!", @users)
|
||||||
mails.length.should == 5
|
mails.length.should == 5
|
||||||
mails.each{|mail|
|
mails.each{|mail|
|
||||||
this_user = users.detect{|u| mail.to == [u.email]}
|
this_user = @users.detect{|u| mail.to == [u.email]}
|
||||||
mail.body.encoded.should match /Welcome to bureaucracy!/
|
mail.body.encoded.should match /Welcome to bureaucracy!/
|
||||||
mail.body.encoded.should match /#{this_user.username}/
|
mail.body.encoded.should match /#{this_user.username}/
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "has attachments" do
|
||||||
|
mails = Notifier.admin("Welcome to bureaucracy!", @users, :attachments => [{:name => "retention stats", :file => "here is some file content"}])
|
||||||
|
mails.length.should == 5
|
||||||
|
mails.each{|mail|
|
||||||
|
mail.attachments.count.should == 1
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '.single_admin' do
|
describe '.single_admin' do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue