From 8e3ef448e5902be4cc19339d7a82dbd11f49448d Mon Sep 17 00:00:00 2001 From: Rafi Date: Mon, 6 Jul 2020 01:21:28 +0530 Subject: [PATCH] [deploy] Removing notification of hidden message (#8881) --- app/controllers/comments_controller.rb | 5 +++++ spec/requests/comments_spec.rb | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 5a874c10e..57d838f9f 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -221,6 +221,11 @@ class CommentsController < ApplicationController authorize @comment @comment.hidden_by_commentable_user = true @comment&.commentable&.update_column(:any_comments_hidden, true) + + Notification.destroy_by(user_id: current_user.id, + notifiable_type: "Comment", + notifiable_id: params[:comment_id]) + if @comment.save render json: { hidden: "true" }, status: :ok else diff --git a/spec/requests/comments_spec.rb b/spec/requests/comments_spec.rb index 2f8f5a396..7b0ff639a 100644 --- a/spec/requests/comments_spec.rb +++ b/spec/requests/comments_spec.rb @@ -332,6 +332,23 @@ RSpec.describe "Comments", type: :request do describe "PATCH /comments/:comment_id/hide" do include_examples "PATCH /comments/:comment_id/hide or unhide", path: "hide", hidden: "true" + + context "with notifications" do + let(:user2) { create(:user) } + let(:article) { create(:article, :with_notification_subscription, user: user) } + let(:comment) { create(:comment, commentable: article, user: user2) } + + before do + sign_in user + Notification.send_new_comment_notifications_without_delay(comment) + end + + it "Delete notification when comment is hidden" do + notification = user.notifications.last + patch "/comments/#{comment.id}/hide", headers: { HTTP_ACCEPT: "application/json" } + expect(Notification.exists?(id: notification.id)).to eq(false) + end + end end describe "PATCH /comments/:comment_id/unhide" do