2020-05-25 09:33:09 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "rails_helper"
|
|
|
|
|
|
|
|
describe QuestionWorker do
|
|
|
|
describe "#perform" do
|
|
|
|
let(:user) { FactoryBot.create(:user) }
|
|
|
|
let(:user_id) { user.id }
|
2022-11-06 06:23:05 -08:00
|
|
|
let(:question) { FactoryBot.create(:question, user:) }
|
2020-05-25 09:33:09 -07:00
|
|
|
let(:question_id) { question.id }
|
|
|
|
|
|
|
|
before do
|
|
|
|
5.times do
|
|
|
|
other_user = FactoryBot.create(:user)
|
|
|
|
other_user.follow(user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { described_class.new.perform(user_id, question_id) }
|
|
|
|
|
|
|
|
it "places the question in the inbox of the user's followers" do
|
|
|
|
expect { subject }
|
|
|
|
.to(
|
2022-11-06 06:23:05 -08:00
|
|
|
change { Inbox.where(user_id: user.followers.ids, question_id:, new: true).count }
|
2020-05-25 09:33:09 -07:00
|
|
|
.from(0)
|
|
|
|
.to(5)
|
|
|
|
)
|
|
|
|
end
|
2021-12-22 10:21:09 -08:00
|
|
|
|
|
|
|
it "respects mute rules" do
|
2022-01-23 10:25:56 -08:00
|
|
|
question.content = "Some spicy question text"
|
2021-12-22 10:21:09 -08:00
|
|
|
question.save
|
|
|
|
|
2022-01-23 10:25:56 -08:00
|
|
|
MuteRule.create(user_id: user.followers.first.id, muted_phrase: "spicy")
|
2021-12-22 10:21:09 -08:00
|
|
|
|
|
|
|
expect { subject }
|
|
|
|
.to(
|
2022-11-06 06:23:05 -08:00
|
|
|
change { Inbox.where(user_id: user.followers.ids, question_id:, new: true).count }
|
2021-12-22 10:21:09 -08:00
|
|
|
.from(0)
|
|
|
|
.to(4)
|
|
|
|
)
|
|
|
|
end
|
2022-11-06 06:02:12 -08:00
|
|
|
|
|
|
|
it "respects inbox locks" do
|
|
|
|
user.followers.first.update(privacy_lock_inbox: true)
|
|
|
|
|
|
|
|
expect { subject }
|
|
|
|
.to(
|
2022-11-06 06:23:05 -08:00
|
|
|
change { Inbox.where(user_id: user.followers.ids, question_id:, new: true).count }
|
2022-11-06 06:02:12 -08:00
|
|
|
.from(0)
|
|
|
|
.to(4)
|
|
|
|
)
|
|
|
|
end
|
2020-05-25 09:33:09 -07:00
|
|
|
end
|
|
|
|
end
|