From 4e6a9aeb1e3eafe8978f0a10af6711532b42cd2d Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Tue, 17 Jan 2017 20:28:30 +0100 Subject: [PATCH] Fallback to title if the reshare root was deleted closes #7284 --- app/helpers/notifier_helper.rb | 2 +- spec/helpers/notifier_helper_spec.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/helpers/notifier_helper.rb b/app/helpers/notifier_helper.rb index df3526271..7cbb2c4dc 100644 --- a/app/helpers/notifier_helper.rb +++ b/app/helpers/notifier_helper.rb @@ -5,7 +5,7 @@ module NotifierHelper # @return [String] The formatted post. def post_message(post, opts={}) if post.respond_to? :message - post.message.plain_text_without_markdown + post.message.try(:plain_text_without_markdown) || post_page_title(post) else I18n.translate 'notifier.a_post_you_shared' end diff --git a/spec/helpers/notifier_helper_spec.rb b/spec/helpers/notifier_helper_spec.rb index ca8a31934..654fcd6d4 100644 --- a/spec/helpers/notifier_helper_spec.rb +++ b/spec/helpers/notifier_helper_spec.rb @@ -14,6 +14,13 @@ describe NotifierHelper, :type => :helper do it 'strip markdown in the post' do expect(post_message(@markdown_post)).to eq(@striped_markdown_post) end + + it "falls back to the title, if the root post was deleted" do + reshare = FactoryGirl.create(:reshare) + reshare.root.destroy + expect(helper.post_message(Reshare.find(reshare.id))) + .to eq(I18n.t("posts.show.reshare_by", author: reshare.author_name)) + end end describe '#comment_message' do