Fix errors when trying to mail comment notifications to post authors on posts other than status messages

This commit is contained in:
Raphael Sofaer 2011-08-10 15:40:32 -07:00
parent e0051eaba8
commit 3658481c38
2 changed files with 19 additions and 7 deletions

View file

@ -6,6 +6,7 @@ class Notifier < ActionMailer::Base
default :from => AppConfig[:smtp_sender_address] default :from => AppConfig[:smtp_sender_address]
include ActionView::Helpers::TextHelper include ActionView::Helpers::TextHelper
include NotifierHelper
TRUNCATION_LEN = 70 TRUNCATION_LEN = 70
@ -73,7 +74,7 @@ class Notifier < ActionMailer::Base
I18n.with_locale(@receiver.language) do I18n.with_locale(@receiver.language) do
mail(:from => "\"#{@sender.name} (Diaspora)\" <#{AppConfig[:smtp_sender_address]}>", mail(:from => "\"#{@sender.name} (Diaspora)\" <#{AppConfig[:smtp_sender_address]}>",
:to => "\"#{@receiver.name}\" <#{@receiver.email}>", :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
end end

View file

@ -172,12 +172,12 @@ describe Notifier do
end end
context "comments" do context "comments" do
let!(:connect) { connect_users(user, aspect, user2, aspect2)} 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(: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 => sm )} let(:comment) { user2.comment("Totally is", :post => commented_post)}
describe ".comment_on_post" do 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 it 'TO: goes to the right person' do
comment_mail.to.should == [user.email] comment_mail.to.should == [user.email]
@ -189,7 +189,7 @@ describe Notifier do
end end
it 'SUBJECT: has a snippet of the post contents' do 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 end
context 'BODY' do context 'BODY' do
@ -201,6 +201,17 @@ describe Notifier do
comment_mail.body.encoded.include?("#{comment.post.id.to_s}").should be true comment_mail.body.encoded.include?("#{comment.post.id.to_s}").should be true
end end
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 end
describe ".also_commented" do describe ".also_commented" do
@ -216,7 +227,7 @@ describe Notifier do
end end
it 'SUBJECT: has a snippet of the post contents' do 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 end
context 'BODY' do context 'BODY' do