A reshares root may be already gone when generating the notification

This commit is contained in:
Jonne Haß 2014-09-07 00:45:12 +02:00
parent 777e3123d6
commit 619bc3f537
2 changed files with 8 additions and 1 deletions

View file

@ -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

View file

@ -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