Handle Reactions Without Users When Sending Notifications (#5820)
* Add reaction's owner existence in the database * Add test
This commit is contained in:
parent
2c07b08514
commit
faad0b83e6
2 changed files with 14 additions and 2 deletions
|
|
@ -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) } }
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue