Handle Reactions Without Users When Sending Notifications (#5820)

* Add reaction's owner existence in the database

* Add test
This commit is contained in:
Mohamed ABDELLANI 2020-02-07 20:10:52 +01:00 committed by GitHub
parent 2c07b08514
commit faad0b83e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View file

@ -24,8 +24,8 @@ module Notifications
reaction_siblings = Reaction.where(reactable_id: reaction.reactable_id, reactable_type: reaction.reactable_type).
where.not(reactions: { user_id: reaction.reactable_user_id }).
includes(:reactable, :user).
order("created_at DESC")
preload(:reactable).includes(:user).where.not(users: { id: nil }).
order("reactions.created_at DESC")
aggregated_reaction_siblings = reaction_siblings.map { |reaction| { category: reaction.category, created_at: reaction.created_at, user: user_data(reaction.user) } }

View file

@ -292,6 +292,18 @@ RSpec.describe Notification, type: :model do
end
end.to change(article.user.notifications, :count).by(1)
end
it "does not send a notification to the author of an article if the reaction owner is deleted" do
user4 = create(:user)
reaction = create(:reaction, reactable: article, user: user4)
user4.delete
expect do
sidekiq_perform_enqueued_jobs do
described_class.send_reaction_notification(reaction, reaction.reactable.user)
end
end.not_to change(article.user.notifications, :count)
end
end
context "when a reaction is destroyed" do