From c6427c4ec087dd3493667f35c318a211fbb9b50c Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Thu, 18 Aug 2016 23:26:27 +0200 Subject: [PATCH] don't add the root author to the subscribers if the root post was deleted --- app/models/reshare.rb | 2 +- spec/models/reshare_spec.rb | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/models/reshare.rb b/app/models/reshare.rb index d69c9d278..bb914d401 100644 --- a/app/models/reshare.rb +++ b/app/models/reshare.rb @@ -70,7 +70,7 @@ class Reshare < Post end def subscribers - super + [root.author] + super.tap {|people| root.try {|root| people << root.author } } end private diff --git a/spec/models/reshare_spec.rb b/spec/models/reshare_spec.rb index 208a62d7a..cc436de9a 100644 --- a/spec/models/reshare_spec.rb +++ b/spec/models/reshare_spec.rb @@ -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