From 68ca431165f3bdde3e60baedf8029bda6c063d97 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Sat, 12 Nov 2022 11:58:20 +0100 Subject: [PATCH 1/3] Prevent questions from being sent to banned users --- app/workers/question_worker.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/workers/question_worker.rb b/app/workers/question_worker.rb index 0416244a..8f7823a6 100644 --- a/app/workers/question_worker.rb +++ b/app/workers/question_worker.rb @@ -12,6 +12,7 @@ class QuestionWorker question = Question.find(question_id) user.followers.each do |f| + next if f.banned? next if MuteRule.where(user: f).any? { |rule| rule.applies_to? question } Inbox.create(user_id: f.id, question_id: question_id, new: true) From 0b67baa3c48cc786e49fae6822d0931ec0fdf24f Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Sat, 12 Nov 2022 12:13:51 +0100 Subject: [PATCH 2/3] Add test for sending questions to banned users --- spec/workers/question_worker_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spec/workers/question_worker_spec.rb b/spec/workers/question_worker_spec.rb index 94f45a50..c427058b 100644 --- a/spec/workers/question_worker_spec.rb +++ b/spec/workers/question_worker_spec.rb @@ -40,5 +40,16 @@ describe QuestionWorker do .to(4) ) end + + it "does not send questions to banned users" do + user.followers.first.ban + + expect { subject } + .to( + change { Inbox.where(user_id: user.followers.ids, question_id: question_id, new: true).count } + .from(0) + .to(4) + ) + end end end From a8360dcad0d144df39441a18784e45a176a02d3b Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Sat, 12 Nov 2022 12:39:41 +0100 Subject: [PATCH 3/3] Appease the robot dog --- spec/workers/question_worker_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/workers/question_worker_spec.rb b/spec/workers/question_worker_spec.rb index c427058b..cafbc455 100644 --- a/spec/workers/question_worker_spec.rb +++ b/spec/workers/question_worker_spec.rb @@ -21,7 +21,7 @@ describe QuestionWorker do it "places the question in the inbox of the user's followers" do expect { subject } .to( - change { Inbox.where(user_id: user.followers.ids, question_id: question_id, new: true).count } + change { Inbox.where(user_id: user.followers.ids, question_id:, new: true).count } .from(0) .to(5) ) @@ -35,7 +35,7 @@ describe QuestionWorker do expect { subject } .to( - change { Inbox.where(user_id: user.followers.ids, question_id: question_id, new: true).count } + change { Inbox.where(user_id: user.followers.ids, question_id:, new: true).count } .from(0) .to(4) ) @@ -46,7 +46,7 @@ describe QuestionWorker do expect { subject } .to( - change { Inbox.where(user_id: user.followers.ids, question_id: question_id, new: true).count } + change { Inbox.where(user_id: user.followers.ids, question_id:, new: true).count } .from(0) .to(4) )