2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe Jobs::IgnoredUsersSummary do
|
2023-06-21 10:00:19 -04:00
|
|
|
subject(:job) { Jobs::IgnoredUsersSummary.new.execute({}) }
|
|
|
|
|
2019-03-14 18:51:43 -04:00
|
|
|
before do
|
|
|
|
SiteSetting.ignored_users_count_message_threshold = 1
|
|
|
|
SiteSetting.ignored_users_message_gap_days = 365
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with no ignored users" do
|
|
|
|
it "does nothing" do
|
2023-06-21 10:00:19 -04:00
|
|
|
job
|
|
|
|
expect { job }.to_not change { Post.count }
|
2019-03-14 18:51:43 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when some ignored users exist" do
|
2019-05-06 23:12:20 -04:00
|
|
|
fab!(:tarek) { Fabricate(:user, username: "tarek") }
|
|
|
|
fab!(:matt) { Fabricate(:user, username: "matt") }
|
|
|
|
fab!(:john) { Fabricate(:user, username: "john") }
|
2019-03-14 18:51:43 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
Fabricate(:ignored_user, user: tarek, ignored_user: matt)
|
|
|
|
Fabricate(:ignored_user, user_id: tarek.id, ignored_user_id: john.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when no system message exists for the ignored users" do
|
|
|
|
context "when threshold is not hit" do
|
|
|
|
before { SiteSetting.ignored_users_count_message_threshold = 5 }
|
|
|
|
|
|
|
|
it "does nothing" do
|
2023-06-21 10:00:19 -04:00
|
|
|
job
|
|
|
|
expect { job }.to_not change { Post.count }
|
2019-03-14 18:51:43 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when threshold is hit" do
|
|
|
|
it "creates a system message" do
|
2023-06-21 10:00:19 -04:00
|
|
|
job
|
2019-03-14 18:51:43 -04:00
|
|
|
posts =
|
|
|
|
Post.joins(:topic).where(
|
|
|
|
topics: {
|
|
|
|
archetype: Archetype.private_message,
|
|
|
|
subtype: TopicSubtype.system_message,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
expect(posts.count).to eq(2)
|
2019-03-20 06:18:46 -04:00
|
|
|
expect(posts.find { |post| post.raw.include?(matt.username) }).to be_present
|
|
|
|
expect(posts.find { |post| post.raw.include?(john.username) }).to be_present
|
2019-03-14 18:51:43 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when a system message already exists for the ignored users" do
|
|
|
|
context "when threshold is not hit" do
|
|
|
|
before { SiteSetting.ignored_users_count_message_threshold = 5 }
|
|
|
|
|
|
|
|
it "does nothing" do
|
2023-06-21 10:00:19 -04:00
|
|
|
job
|
|
|
|
expect { job }.to_not change { Post.count }
|
2019-03-14 18:51:43 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when threshold is hit" do
|
|
|
|
it "does nothing" do
|
2023-06-21 10:00:19 -04:00
|
|
|
job
|
|
|
|
expect { job }.to_not change { Post.count }
|
2019-03-14 18:51:43 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|