Merge pull request #793 from Retrospring/prevent-receiving-questions-while-banned

Prevent questions from being sent to banned users
This commit is contained in:
Karina Kwiatek 2022-11-12 13:37:32 +01:00 committed by GitHub
commit e8437a5226
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -12,6 +12,7 @@ class QuestionWorker
question = Question.find(question_id) question = Question.find(question_id)
user.followers.each do |f| user.followers.each do |f|
next if f.banned?
next if MuteRule.where(user: f).any? { |rule| rule.applies_to? question } next if MuteRule.where(user: f).any? { |rule| rule.applies_to? question }
Inbox.create(user_id: f.id, question_id: question_id, new: true) Inbox.create(user_id: f.id, question_id: question_id, new: true)

View File

@ -21,7 +21,7 @@ describe QuestionWorker do
it "places the question in the inbox of the user's followers" do it "places the question in the inbox of the user's followers" do
expect { subject } expect { subject }
.to( .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) .from(0)
.to(5) .to(5)
) )
@ -35,7 +35,18 @@ describe QuestionWorker do
expect { subject } expect { subject }
.to( .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)
)
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:, new: true).count }
.from(0) .from(0)
.to(4) .to(4)
) )