diff --git a/app/models/person.rb b/app/models/person.rb index 5042a45e50b..7bc32c51419 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -154,7 +154,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 b1567f80dfc..90569b5459b 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