mirror of
https://github.com/discourse/discourse.git
synced 2024-12-02 02:53:42 +08:00
f0a46f8b6f
For performance reasons we don't automatically add fabricated users to trust level auto-groups. However, when explicitly passing a trust level to the fabricator, in 99% of cases it means that trust level is relevant for the test, and we need the groups. This change makes it so that when a trust level is explicitly passed to the fabricator, the auto-groups are refreshed. There's no longer a need to also pass refresh_auto_groups: true, which means clearer tests, fewer mistakes, and less confusion.
68 lines
2.3 KiB
Ruby
68 lines
2.3 KiB
Ruby
# encoding: UTF-8
|
|
# frozen_string_literal: true
|
|
|
|
RSpec.describe "spammers on same IP" do
|
|
let(:ip_address) { "182.189.119.174" }
|
|
let!(:spammer1) { Fabricate(:user, ip_address: ip_address, trust_level: TrustLevel[0]) }
|
|
let!(:spammer2) { Fabricate(:user, ip_address: ip_address, trust_level: TrustLevel[0]) }
|
|
let(:spammer3) { Fabricate(:user, ip_address: ip_address, trust_level: TrustLevel[0]) }
|
|
|
|
context "when flag_sockpuppets is disabled" do
|
|
let!(:first_post) { create_post(user: spammer1) }
|
|
let!(:second_post) { create_post(user: spammer2, topic: first_post.topic) }
|
|
|
|
it "should not increase spam count" do
|
|
expect(first_post.reload.spam_count).to eq(0)
|
|
expect(second_post.reload.spam_count).to eq(0)
|
|
end
|
|
end
|
|
|
|
context "when flag_sockpuppets is enabled" do
|
|
before { SiteSetting.flag_sockpuppets = true }
|
|
|
|
after { SiteSetting.flag_sockpuppets = false }
|
|
|
|
context "when first spammer starts a topic" do
|
|
let!(:first_post) { create_post(user: spammer1) }
|
|
|
|
context "when second spammer replies" do
|
|
let!(:second_post) { create_post(user: spammer2, topic: first_post.topic) }
|
|
|
|
it "should increase spam count" do
|
|
expect(first_post.reload.spam_count).to eq(1)
|
|
expect(second_post.reload.spam_count).to eq(1)
|
|
end
|
|
|
|
context "with third spam post" do
|
|
let!(:third_post) { create_post(user: spammer3, topic: first_post.topic) }
|
|
|
|
it "should increase spam count" do
|
|
expect(first_post.reload.spam_count).to eq(1)
|
|
expect(second_post.reload.spam_count).to eq(1)
|
|
expect(third_post.reload.spam_count).to eq(1)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
context "when first user is not new" do
|
|
let!(:old_user) do
|
|
Fabricate(:user, ip_address: ip_address, created_at: 2.days.ago, trust_level: TrustLevel[1])
|
|
end
|
|
|
|
context "when first user starts a topic" do
|
|
let!(:first_post) { create_post(user: old_user) }
|
|
|
|
context "with a reply by a new user at the same IP address" do
|
|
let!(:second_post) { create_post(user: spammer2, topic: first_post.topic) }
|
|
|
|
it "should increase the spam count correctly" do
|
|
expect(first_post.reload.spam_count).to eq(0)
|
|
expect(second_post.reload.spam_count).to eq(1)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|