Rick DeNatale
2009-Mar-18 20:28 UTC
[rspec-users] Problem spec''ing ActionMailer with attachment, body not getting rendered.
I''ve got a simple ActionMailer::Base subclass:
class InfoMailer < ActionMailer::Base
def info(user, zip_name)
recipients user.email
subject "Requested Info"
attachment(:content_type => "application/zip",
:filename => zip_name,
:body => File.read(zip_name))
body(:message => "Here is the Info that you Requested")
end
end
I''m trying to spec this following
http://www.rubytutorials.net/2008/02/26/small-rspec-revelations-actionmailer/
describe AssetsInfoMailer do
before(:each) do
@user = mock_model(User,
:email => @user_email = "somewhere at over.the.rainbow",
:full_name => "The Wicked Witch of the West"
)
ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.deliveries = []
end
describe ".info" do
before(:each) do
@path = ''xyz.zip''
@attachment_body = ''zip_file_contents''
File.stub!(:read).and_return(@attachment_body)
@the_mail = AssetsInfoMailer.deliver_info(@user, at path)
@attachments = @the_mail.attachments
end
it "should have the right body" do
@the_mail.body.should == ""
end
end
The expectation of an empty string is just to see what''s actually
getting
returned, the result is:
1)
''AssetsInfoMailer.info should have the right body'' FAILED
expected: "",
got: "Attachment: xyz.zip\n" (using ==)
It''s looking like the mail template never got rendered, and body is
giving
me the attachment since it''s the only part.
I''ve got one other mailer method in that mailer which doesn''t
contain an
attachement, and it''s body comes out fine.
I''m not sure what''s going on here, and I''d appreciate
any
help/insight/condolences...
--
Rick DeNatale
Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/rspec-users/attachments/20090318/0522d691/attachment.html>
Rick DeNatale
2009-Mar-18 20:33 UTC
[rspec-users] Problem spec''ing ActionMailer with attachment, body not getting rendered.
On Wed, Mar 18, 2009 at 4:28 PM, Rick DeNatale <rick.denatale at gmail.com>wrote:> I''ve got a simple ActionMailer::Base subclass: > class InfoMailer < ActionMailer::Base > > def info(user, zip_name) > recipients user.email > subject "Requested Info" > attachment(:content_type => "application/zip", > :filename => zip_name, > :body => File.read(zip_name)) > body(:message => "Here is the Info that you Requested") > end > end > > I''m trying to spec this following > http://www.rubytutorials.net/2008/02/26/small-rspec-revelations-actionmailer/ > > describe AssetsInfoMailer do > before(:each) do > @user = mock_model(User, > :email => @user_email = "somewhere at over.the.rainbow", > :full_name => "The Wicked Witch of the West" > ) > ActionMailer::Base.delivery_method = :test > ActionMailer::Base.perform_deliveries = true > ActionMailer::Base.deliveries = [] > end > > describe ".info" do > before(:each) do > @path = ''xyz.zip'' > @attachment_body = ''zip_file_contents'' > File.stub!(:read).and_return(@attachment_body) > @the_mail = AssetsInfoMailer.deliver_info(@user, at path) > @attachments = @the_mail.attachments > end > > it "should have the right body" do > @the_mail.body.should == "" > end > end > > The expectation of an empty string is just to see what''s actually getting > returned, the result is: > > 1) > ''AssetsInfoMailer.info should have the right body'' FAILED > expected: "", > got: "Attachment: xyz.zip\n" (using ==) > > It''s looking like the mail template never got rendered, and body is giving > me the attachment since it''s the only part. > > I''ve got one other mailer method in that mailer which doesn''t contain an > attachement, and it''s body comes out fine. > > I''m not sure what''s going on here, and I''d appreciate any > help/insight/condolences... >Note that I screwed up in sanitizing the code, the mailer really is AssetsInfoManager, and that''s what''s in the spec consistently. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20090318/881b66e4/attachment.html>
Zach Dennis
2009-Mar-20 15:11 UTC
[rspec-users] Problem spec''ing ActionMailer with attachment, body not getting rendered.
2009/3/18 Rick DeNatale <rick.denatale at gmail.com>:> I''ve got a simple ActionMailer::Base subclass: > class InfoMailer < ActionMailer::Base > > ????def info(user, zip_name) > ?? ?recipients user.email > ?? ?subject "Requested Info" > ?? ?attachment(:content_type => "application/zip", > ?? ? ? ? ? ? ? ?:filename => zip_name, > ?? ? ? ? ? ? ? ?:body => File.read(zip_name)) > ?? ?body(:message => "Here is the Info that you Requested") > ??end > end > I''m trying to spec this > following?http://www.rubytutorials.net/2008/02/26/small-rspec-revelations-actionmailer/ > describe AssetsInfoMailer do > ??before(:each) do > ?? ?@user = mock_model(User, > ?? ? ? ?:email => @user_email = "somewhere at over.the.rainbow", > ?? ? ? ?:full_name => "The Wicked Witch of the West" > ?? ? ? ?) > ?? ?ActionMailer::Base.delivery_method = :test > ?? ?ActionMailer::Base.perform_deliveries = true > ?? ?ActionMailer::Base.deliveries = [] > ??end > ??describe ".info" do > ?? ?before(:each) do > ?? ? ?@path = ''xyz.zip'' > ?? ? ?@attachment_body = ''zip_file_contents'' > ?? ? ?File.stub!(:read).and_return(@attachment_body) > ?? ? ?@the_mail = AssetsInfoMailer.deliver_info(@user, at path) > ?? ? ?@attachments = @the_mail.attachments > ?? ?end > > ?? ?it "should have the right body" do > ?? ? ?@the_mail.body.should == "" > ?? ?end > ??end > The expectation of an empty string is just to see what''s actually getting > returned, the result is: > 1) > ''AssetsInfoMailer.info should have the right body'' FAILED > expected: "", > ?? ? got: "Attachment: xyz.zip\n" (using ==) > It''s looking like the mail template never got rendered, and body is giving > me the attachment since it''s the only part. > I''ve got one other mailer method in that mailer which doesn''t contain an > attachement, and it''s body comes out fine. > I''m not sure what''s going on here, and I''d appreciate any > help/insight/condolences... >When sending attachments emails are sent as multipart messages. The only part being specified is the attachment. The other call to "body" is being ignored. Try something like: def info(user, zip_name) recipients user.email subject "Requested Info" attachment(:content_type => "application/zip", :filename => zip_name, :body => File.read(zip_name)) part "text/plain" do |p| p.body(:message => "Here is the Info that you Requested") end end Also when you look at the email you''ll have look at its #parts otherwise @the_mail.body is going to returned the body representation of each part concatenated.> -- > Rick DeNatale > > Blog: http://talklikeaduck.denhaven2.com/ > Twitter: http://twitter.com/RickDeNatale > WWR: http://www.workingwithrails.com/person/9021-rick-denatale > LinkedIn: http://www.linkedin.com/in/rickdenatale > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com
Zach Dennis
2009-Mar-20 15:46 UTC
[rspec-users] Problem spec''ing ActionMailer with attachment, body not getting rendered.
On Fri, Mar 20, 2009 at 11:11 AM, Zach Dennis <zach.dennis at gmail.com> wrote:> 2009/3/18 Rick DeNatale <rick.denatale at gmail.com>: >> I''ve got a simple ActionMailer::Base subclass: >> class InfoMailer < ActionMailer::Base >> >> ????def info(user, zip_name) >> ?? ?recipients user.email >> ?? ?subject "Requested Info" >> ?? ?attachment(:content_type => "application/zip", >> ?? ? ? ? ? ? ? ?:filename => zip_name, >> ?? ? ? ? ? ? ? ?:body => File.read(zip_name)) >> ?? ?body(:message => "Here is the Info that you Requested") >> ??end >> end >> I''m trying to spec this >> following?http://www.rubytutorials.net/2008/02/26/small-rspec-revelations-actionmailer/ >> describe AssetsInfoMailer do >> ??before(:each) do >> ?? ?@user = mock_model(User, >> ?? ? ? ?:email => @user_email = "somewhere at over.the.rainbow", >> ?? ? ? ?:full_name => "The Wicked Witch of the West" >> ?? ? ? ?) >> ?? ?ActionMailer::Base.delivery_method = :test >> ?? ?ActionMailer::Base.perform_deliveries = true >> ?? ?ActionMailer::Base.deliveries = [] >> ??end >> ??describe ".info" do >> ?? ?before(:each) do >> ?? ? ?@path = ''xyz.zip'' >> ?? ? ?@attachment_body = ''zip_file_contents'' >> ?? ? ?File.stub!(:read).and_return(@attachment_body) >> ?? ? ?@the_mail = AssetsInfoMailer.deliver_info(@user, at path) >> ?? ? ?@attachments = @the_mail.attachments >> ?? ?end >> >> ?? ?it "should have the right body" do >> ?? ? ?@the_mail.body.should == "" >> ?? ?end >> ??end >> The expectation of an empty string is just to see what''s actually getting >> returned, the result is: >> 1) >> ''AssetsInfoMailer.info should have the right body'' FAILED >> expected: "", >> ?? ? got: "Attachment: xyz.zip\n" (using ==) >> It''s looking like the mail template never got rendered, and body is giving >> me the attachment since it''s the only part. >> I''ve got one other mailer method in that mailer which doesn''t contain an >> attachement, and it''s body comes out fine. >> I''m not sure what''s going on here, and I''d appreciate any >> help/insight/condolences... >> > > When sending attachments emails are sent as multipart messages. The > only part being specified is the attachment. The other call to "body" > is being ignored. Try something like: > > def info(user, zip_name) > ?recipients user.email > ?subject "Requested Info" > ?attachment(:content_type => "application/zip", > ? ? ? ? ? ? ?:filename => zip_name, > ? ? ? ? ? ? ?:body => File.read(zip_name)) > ?part "text/plain" do |p| > ? ?p.body(:message => "Here is the Info that you Requested") > ?end > endI just tried my out, and while it does work because there are multiple parts specified, also re-ordering of the initial #body to come before the attachment doesn''t seem to help with the original code either. I''m curious now what you do find out and which route you decide to go, keep us posted either way Rick.> > Also when you look at the email you''ll have look at its #parts > otherwise @the_mail.body is going to returned the body representation > of each part concatenated. > > > >> -- >> Rick DeNatale >> >> Blog: http://talklikeaduck.denhaven2.com/ >> Twitter: http://twitter.com/RickDeNatale >> WWR: http://www.workingwithrails.com/person/9021-rick-denatale >> LinkedIn: http://www.linkedin.com/in/rickdenatale >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > > -- > Zach Dennis > http://www.continuousthinking.com > http://www.mutuallyhuman.com >-- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com
Rick DeNatale
2009-Mar-21 20:47 UTC
[rspec-users] Problem spec''ing ActionMailer with attachment, body not getting rendered.
On Fri, Mar 20, 2009 at 11:46 AM, Zach Dennis <zach.dennis at gmail.com> wrote:> On Fri, Mar 20, 2009 at 11:11 AM, Zach Dennis <zach.dennis at gmail.com> > wrote: > > 2009/3/18 Rick DeNatale <rick.denatale at gmail.com>: > >> I''ve got a simple ActionMailer::Base subclass: > >> class InfoMailer < ActionMailer::Base > >> > >> def info(user, zip_name) > >> recipients user.email > >> subject "Requested Info" > >> attachment(:content_type => "application/zip", > >> :filename => zip_name, > >> :body => File.read(zip_name)) > >> body(:message => "Here is the Info that you Requested") > >> end > >> end > >> I''m trying to spec this > >> following > http://www.rubytutorials.net/2008/02/26/small-rspec-revelations-actionmailer/ > >> describe AssetsInfoMailer do > >> before(:each) do > >> @user = mock_model(User, > >> :email => @user_email = "somewhere at over.the.rainbow", > >> :full_name => "The Wicked Witch of the West" > >> ) > >> ActionMailer::Base.delivery_method = :test > >> ActionMailer::Base.perform_deliveries = true > >> ActionMailer::Base.deliveries = [] > >> end > >> describe ".info" do > >> before(:each) do > >> @path = ''xyz.zip'' > >> @attachment_body = ''zip_file_contents'' > >> File.stub!(:read).and_return(@attachment_body) > >> @the_mail = AssetsInfoMailer.deliver_info(@user, at path) > >> @attachments = @the_mail.attachments > >> end > >> > >> it "should have the right body" do > >> @the_mail.body.should == "" > >> end > >> end > >> The expectation of an empty string is just to see what''s actually > getting > >> returned, the result is: > >> 1) > >> ''AssetsInfoMailer.info should have the right body'' FAILED > >> expected: "", > >> got: "Attachment: xyz.zip\n" (using ==) > >> It''s looking like the mail template never got rendered, and body is > giving > >> me the attachment since it''s the only part. > >> I''ve got one other mailer method in that mailer which doesn''t contain an > >> attachement, and it''s body comes out fine. > >> I''m not sure what''s going on here, and I''d appreciate any > >> help/insight/condolences... > >> > > > > When sending attachments emails are sent as multipart messages. The > > only part being specified is the attachment. The other call to "body" > > is being ignored. Try something like: > > > > def info(user, zip_name) > > recipients user.email > > subject "Requested Info" > > attachment(:content_type => "application/zip", > > :filename => zip_name, > > :body => File.read(zip_name)) > > part "text/plain" do |p| > > p.body(:message => "Here is the Info that you Requested") > > end > > end > > I just tried my out, and while it does work because there are multiple > parts specified, also re-ordering of the initial #body to come before > the attachment doesn''t seem to help with the original code either. > > I''m curious now what you do find out and which route you decide to go, > keep us posted either way Rick.I ende up with pretty much the above, but with p.body(render_message(''info'', :message =>... since there was a template to render. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20090321/30867f73/attachment-0001.html>