sending csv as a file

This commit is contained in:
Ilya Zhitomirskiy 2011-10-31 16:34:03 -07:00
parent 24545743e2
commit 9cadb99f8a
3 changed files with 13 additions and 1 deletions

View file

@ -16,12 +16,19 @@ class Notifier < ActionMailer::Base
@receiver = recipient
@string = string.html_safe
if attach = opts.delete(:attachments)
attach.each{ |f|
attachments[f[:name]] = f[:file]
}
end
default_opts = {:to => @receiver.email,
:from => AppConfig[:smtp_sender_address],
:subject => I18n.t('notifier.single_admin.subject'), :host => AppConfig[:pod_uri].host}
default_opts.merge!(opts)
mail(default_opts)
end

View file

@ -17,7 +17,7 @@ namespace :stats do
end
end
emails = Notifier.admin(string, 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]})
emails.each {|e| e.deliver!}
end
end

View file

@ -45,6 +45,11 @@ describe Notifier do
mail = Notifier.single_admin("Welcome to bureaucracy!", bob)
mail.body.encoded.should match /change your notification settings/
end
it 'has an optional attachment' do
mail = Notifier.single_admin("Welcome to bureaucracy!", bob, :attachments => [{:name => "retention stats", :file => "here is some file content"}])
mail.attachments.length.should == 1
end
end
describe ".started_sharing" do