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 = {})
|
||||
mails = []
|
||||
recipients.each do |rec|
|
||||
mail = single_admin(string, rec, opts)
|
||||
mail = single_admin(string, rec, opts.dup)
|
||||
mails << mail
|
||||
end
|
||||
mails
|
||||
|
|
|
|||
|
|
@ -19,6 +19,6 @@ namespace :stats do
|
|||
|
||||
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}]})
|
||||
emails.each {|e| e.deliver!}
|
||||
emails.each {|e| e.deliver}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -18,18 +18,31 @@ describe Notifier do
|
|||
mail.body.encoded.should match /Welcome to bureaucracy!/
|
||||
mail.body.encoded.should match /#{bob.username}/
|
||||
end
|
||||
it 'mails a bunch of users' do
|
||||
users = []
|
||||
5.times do
|
||||
users << Factory.create(:user)
|
||||
|
||||
context 'mails a bunch of users' do
|
||||
before do
|
||||
@users = []
|
||||
5.times do
|
||||
@users << Factory.create(:user)
|
||||
end
|
||||
end
|
||||
it 'has a body' do
|
||||
mails = Notifier.admin("Welcome to bureaucracy!", @users)
|
||||
mails.length.should == 5
|
||||
mails.each{|mail|
|
||||
this_user = @users.detect{|u| mail.to == [u.email]}
|
||||
mail.body.encoded.should match /Welcome to bureaucracy!/
|
||||
mail.body.encoded.should match /#{this_user.username}/
|
||||
}
|
||||
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
|
||||
mails = Notifier.admin("Welcome to bureaucracy!", users)
|
||||
mails.length.should == 5
|
||||
mails.each{|mail|
|
||||
this_user = users.detect{|u| mail.to == [u.email]}
|
||||
mail.body.encoded.should match /Welcome to bureaucracy!/
|
||||
mail.body.encoded.should match /#{this_user.username}/
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue