A reshares root may be already gone when generating the notification
This commit is contained in:
parent
777e3123d6
commit
619bc3f537
2 changed files with 8 additions and 1 deletions
|
|
@ -62,7 +62,7 @@ class Reshare < Post
|
||||||
end
|
end
|
||||||
|
|
||||||
def notification_type(user, person)
|
def notification_type(user, person)
|
||||||
Notifications::Reshared if root.author == user.person
|
Notifications::Reshared if root.try(:author) == user.person
|
||||||
end
|
end
|
||||||
|
|
||||||
def absolute_root
|
def absolute_root
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,13 @@ describe Reshare, :type => :model do
|
||||||
it 'returns "Reshared" for the original post author' do
|
it 'returns "Reshared" for the original post author' do
|
||||||
expect(@reshare.notification_type(alice, @reshare.author)).to eq(Notifications::Reshared)
|
expect(@reshare.notification_type(alice, @reshare.author)).to eq(Notifications::Reshared)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe '#absolute_root' do
|
describe '#absolute_root' do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue