From 619bc3f5379dad2f7f49e3fd2b8a8b4d2e5d296d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonne=20Ha=C3=9F?= Date: Sun, 7 Sep 2014 00:45:12 +0200 Subject: [PATCH] A reshares root may be already gone when generating the notification --- app/models/reshare.rb | 2 +- spec/models/reshare_spec.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/models/reshare.rb b/app/models/reshare.rb index 33581d05e..869d73351 100644 --- a/app/models/reshare.rb +++ b/app/models/reshare.rb @@ -62,7 +62,7 @@ class Reshare < Post end def notification_type(user, person) - Notifications::Reshared if root.author == user.person + Notifications::Reshared if root.try(:author) == user.person end def absolute_root diff --git a/spec/models/reshare_spec.rb b/spec/models/reshare_spec.rb index ce05d3b6b..929ded2b9 100644 --- a/spec/models/reshare_spec.rb +++ b/spec/models/reshare_spec.rb @@ -75,6 +75,13 @@ describe Reshare, :type => :model do it 'returns "Reshared" for the original post author' do expect(@reshare.notification_type(alice, @reshare.author)).to eq(Notifications::Reshared) end + + it 'does not error out if the root was deleted' do + @reshare.root = nil + expect { + @reshare.notification_type(alice, @reshare.author) + }.to_not raise_error + end end describe '#absolute_root' do