don't add the root author to the subscribers if the root post was deleted

This commit is contained in:
Benjamin Neff 2016-08-18 23:26:27 +02:00
parent bcace2def2
commit c6427c4ec0
2 changed files with 12 additions and 1 deletions

View file

@ -70,7 +70,7 @@ class Reshare < Post
end
def subscribers
super + [root.author]
super.tap {|people| root.try {|root| people << root.author } }
end
private

View file

@ -135,5 +135,16 @@ describe Reshare, type: :model do
expect(reshare.subscribers).to match_array([alice.person, eve.person, user.person])
end
it "does not add the root author if the root post was deleted" do
user = FactoryGirl.create(:user_with_aspect)
user.share_with(alice.person, user.aspects.first)
post = eve.post(:status_message, text: "hello", public: true)
reshare = FactoryGirl.create(:reshare, root: post, author: user.person)
post.destroy
expect(reshare.reload.subscribers).to match_array([alice.person, user.person])
end
end
end