From c64588a68d6303d7460b05d6a56d92f7b21795e0 Mon Sep 17 00:00:00 2001 From: Ilya Zhitomirskiy Date: Mon, 31 Oct 2011 18:04:26 -0700 Subject: [PATCH] adding attachments to all recepients --- app/mailers/notifier.rb | 2 +- lib/tasks/stats.rake | 2 +- spec/mailers/notifier_spec.rb | 35 ++++++++++++++++++++++++----------- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/app/mailers/notifier.rb b/app/mailers/notifier.rb index b7a746cca..851595084 100644 --- a/app/mailers/notifier.rb +++ b/app/mailers/notifier.rb @@ -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 diff --git a/lib/tasks/stats.rake b/lib/tasks/stats.rake index 72bd30ecc..ccd85b33a 100644 --- a/lib/tasks/stats.rake +++ b/lib/tasks/stats.rake @@ -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 diff --git a/spec/mailers/notifier_spec.rb b/spec/mailers/notifier_spec.rb index 4322ba1f8..178662c29 100644 --- a/spec/mailers/notifier_spec.rb +++ b/spec/mailers/notifier_spec.rb @@ -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