From 3658481c3800713afabe7c28667d15e6de51b045 Mon Sep 17 00:00:00 2001 From: Raphael Sofaer Date: Wed, 10 Aug 2011 15:40:32 -0700 Subject: [PATCH] Fix errors when trying to mail comment notifications to post authors on posts other than status messages --- app/mailers/notifier.rb | 3 ++- spec/mailers/notifier_spec.rb | 23 +++++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/app/mailers/notifier.rb b/app/mailers/notifier.rb index 717eccecb..07717ac37 100644 --- a/app/mailers/notifier.rb +++ b/app/mailers/notifier.rb @@ -6,6 +6,7 @@ class Notifier < ActionMailer::Base default :from => AppConfig[:smtp_sender_address] include ActionView::Helpers::TextHelper + include NotifierHelper TRUNCATION_LEN = 70 @@ -73,7 +74,7 @@ class Notifier < ActionMailer::Base I18n.with_locale(@receiver.language) do mail(:from => "\"#{@sender.name} (Diaspora)\" <#{AppConfig[:smtp_sender_address]}>", :to => "\"#{@receiver.name}\" <#{@receiver.email}>", - :subject => "Re: #{truncate(@comment.parent.formatted_message(:plain_text => true).strip, :length => TRUNCATION_LEN)}") + :subject => "Re: #{post_message(@comment.parent, :length => TRUNCATION_LEN)}") end end diff --git a/spec/mailers/notifier_spec.rb b/spec/mailers/notifier_spec.rb index f445f5e0a..594576d71 100644 --- a/spec/mailers/notifier_spec.rb +++ b/spec/mailers/notifier_spec.rb @@ -172,12 +172,12 @@ describe Notifier do end context "comments" do - let!(:connect) { connect_users(user, aspect, user2, aspect2)} - let!(:sm) {user.post(:status_message, :text => "It's really sunny outside today, and this is a super long status message! #notreally", :to => :all)} - let!(:comment) { user2.comment("Totally is", :post => sm )} + let(:connect) { connect_users(user, aspect, user2, aspect2)} + let(:commented_post) {user.post(:status_message, :text => "It's really sunny outside today, and this is a super long status message! #notreally", :to => :all)} + let(:comment) { user2.comment("Totally is", :post => commented_post)} describe ".comment_on_post" do - let!(:comment_mail) {Notifier.comment_on_post(user.id, person.id, comment.id).deliver} + let(:comment_mail) {Notifier.comment_on_post(user.id, person.id, comment.id).deliver} it 'TO: goes to the right person' do comment_mail.to.should == [user.email] @@ -189,7 +189,7 @@ describe Notifier do end it 'SUBJECT: has a snippet of the post contents' do - comment_mail.subject.should == "Re: #{truncate(sm.text, :length => 70)}" + comment_mail.subject.should == "Re: #{truncate(commented_post.text, :length => 70)}" end context 'BODY' do @@ -201,6 +201,17 @@ describe Notifier do comment_mail.body.encoded.include?("#{comment.post.id.to_s}").should be true end end + + [:reshare, :activity_streams_photo].each do |post_type| + context post_type.to_s do + let(:commented_post) { Factory(post_type, :author => user.person) } + it 'succeeds' do + proc { + comment_mail + }.should_not raise_error + end + end + end end describe ".also_commented" do @@ -216,7 +227,7 @@ describe Notifier do end it 'SUBJECT: has a snippet of the post contents' do - comment_mail.subject.should == "Re: #{truncate(sm.text, :length => 70)}" + comment_mail.subject.should == "Re: #{truncate(commented_post.text, :length => 70)}" end context 'BODY' do