From c33009049af55102bbbab6e98a19fef6a13feea4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonne=20Ha=C3=9F?= Date: Wed, 11 Sep 2019 14:35:03 +0200 Subject: [PATCH] Handle processing a mention in a comment of an already deleted post --- app/models/person.rb | 4 +++- spec/models/notifications/mentioned_spec.rb | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/models/person.rb b/app/models/person.rb index 8853a096dea..0a27d346a46 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -138,7 +138,9 @@ def downcase_diaspora_handle # @param [Post] the post for which we query mentionable in comments people # @return [Person::ActiveRecord_Relation] scope :allowed_to_be_mentioned_in_a_comment_to, ->(post) { - allowed = if post.public? + allowed = if post.nil? + none + elsif post.public? all else left_join_visible_post_interactions_on_authorship(post.id) diff --git a/spec/models/notifications/mentioned_spec.rb b/spec/models/notifications/mentioned_spec.rb index ca77f960fb3..256784369aa 100644 --- a/spec/models/notifications/mentioned_spec.rb +++ b/spec/models/notifications/mentioned_spec.rb @@ -63,5 +63,16 @@ def self.filter_mentions(mentions, *) expect(TestNotification).not_to receive(:create_notification) TestNotification.notify(status_message, nil) end + + it "doesn't create a notification for a mention in a comment of an already deleted post" do + post = FactoryGirl.create(:status_message, public: true) + comment = FactoryGirl.create(:comment, commentable: post, text: text_mentioning(alice)) + post.delete + comment.reload + + expect { + Notifications::MentionedInComment.notify(comment, [alice]) + }.to_not change(Notification, :count) + end end end