Create comments notification subscription upon creation (#3167)

* Create comments notification subscription upon creation

* Fix test
This commit is contained in:
Ben Halpern 2019-06-14 20:11:58 -04:00 committed by GitHub
parent c81bc8e66f
commit 85e3be1f48
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View file

@ -60,6 +60,7 @@ class CommentsController < ApplicationController
current_user.update(checked_code_of_conduct: true) if params[:checked_code_of_conduct].present? && !current_user.checked_code_of_conduct
Mention.create_all(@comment)
NotificationSubscription.create(user: current_user, notifiable_id: @comment.id, notifiable_type: "Comment", config: "all_comments")
Notification.send_new_comment_notifications_without_delay(@comment)
if @comment.invalid?

View file

@ -15,4 +15,12 @@ RSpec.describe "CommentsCreate", type: :request do
}
expect(Comment.last.user_id).to eq(user.id)
end
it "creates NotificationSubscription for comment" do
new_body = "NEW BODY #{rand(100)}"
post "/comments", params: {
comment: { body_markdown: new_body, commentable_id: article.id, commentable_type: "Article" }
}
expect(NotificationSubscription.last.notifiable).to eq(Comment.last)
end
end