diff --git a/app/jobs/regular/user_email.rb b/app/jobs/regular/user_email.rb index ff38409c1..9ef71e086 100644 --- a/app/jobs/regular/user_email.rb +++ b/app/jobs/regular/user_email.rb @@ -50,7 +50,7 @@ module Jobs NOTIFICATIONS_SENT_BY_MAILING_LIST ||= Set.new %w{posted replied mentioned group_mentioned quoted} - def message_for_email(user, post, type, notification, + def message_for_email(user, post, type, notification, notification_type=nil, notification_data_hash=nil, email_token=nil, to_address=nil) @@ -86,7 +86,7 @@ module Jobs end if user.user_option.mailing_list_mode? && - !post.topic.private_message? && + (!post.try(:topic).try(:private_message?)) && NOTIFICATIONS_SENT_BY_MAILING_LIST.include?(email_args[:notification_type]) # no need to log a reason when the mail was already sent via the mailing list job return [nil, nil] diff --git a/spec/jobs/user_email_spec.rb b/spec/jobs/user_email_spec.rb index 5cce202fe..5054089b5 100644 --- a/spec/jobs/user_email_spec.rb +++ b/spec/jobs/user_email_spec.rb @@ -200,6 +200,12 @@ describe Jobs::UserEmail do Jobs::UserEmail.new.execute(type: :user_mentioned, user_id: user.id, notification_id: notification.id, post_id: post.id) # other times, we only pass the type of notification Jobs::UserEmail.new.execute(type: :user_mentioned, user_id: user.id, notification_type: "posted", post_id: post.id) + # When post is nil + Jobs::UserEmail.new.execute(type: :user_mentioned, user_id: user.id, notification_type: "posted") + # When post does not have a topic + post = Fabricate(:post) + post.topic.destroy + Jobs::UserEmail.new.execute(type: :user_mentioned, user_id: user.id, notification_type: "posted", post_id: post) end it "doesn't send the email if the post has been user deleted" do