[deploy] Removing notification of hidden message (#8881)

This commit is contained in:
Rafi 2020-07-06 01:21:28 +05:30 committed by GitHub
parent f38da6bc94
commit 8e3ef448e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View file

@ -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

View file

@ -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