mirror of
https://github.com/discourse/discourse.git
synced 2024-12-16 16:10:15 +08:00
59d04c0695
Changed internals so trust levels are referred to with TrustLevel[1], TrustLevel[2] etc. This gives us much better flexibility naming trust levels, these names are meant to be controlled by various communities.
60 lines
2.0 KiB
Ruby
60 lines
2.0 KiB
Ruby
# encoding: UTF-8
|
|
|
|
require 'spec_helper'
|
|
|
|
describe SpamRulesEnforcer do
|
|
|
|
Given(:ip_address) { '182.189.119.174' }
|
|
Given!(:spammer1) { Fabricate(:user, ip_address: ip_address) }
|
|
Given!(:spammer2) { Fabricate(:user, ip_address: ip_address) }
|
|
Given(:spammer3) { Fabricate(:user, ip_address: ip_address) }
|
|
|
|
context 'flag_sockpuppets is disabled' do
|
|
Given { SiteSetting.stubs(:flag_sockpuppets).returns(false) }
|
|
Given!(:first_post) { create_post(user: spammer1) }
|
|
Given!(:second_post) { create_post(user: spammer2, topic: first_post.topic) }
|
|
|
|
Then { first_post.reload.spam_count.should == 0 }
|
|
And { second_post.reload.spam_count.should == 0 }
|
|
end
|
|
|
|
context 'flag_sockpuppets is enabled' do
|
|
Given { SiteSetting.stubs(:flag_sockpuppets).returns(true) }
|
|
|
|
context 'first spammer starts a topic' do
|
|
Given!(:first_post) { create_post(user: spammer1) }
|
|
|
|
context 'second spammer replies' do
|
|
Given!(:second_post) { create_post(user: spammer2, topic: first_post.topic) }
|
|
|
|
Then { first_post.reload.spam_count.should == 1 }
|
|
And { second_post.reload.spam_count.should == 1 }
|
|
|
|
context 'third spam post' do
|
|
Given!(:third_post) { create_post(user: spammer3, topic: first_post.topic) }
|
|
|
|
Then { first_post.reload.spam_count.should == 1 }
|
|
And { second_post.reload.spam_count.should == 1 }
|
|
And { third_post.reload.spam_count.should == 1 }
|
|
end
|
|
end
|
|
end
|
|
|
|
context 'first user is not new' do
|
|
Given!(:old_user) { Fabricate(:user, ip_address: ip_address, created_at: 2.days.ago, trust_level: TrustLevel[1]) }
|
|
|
|
context 'first user starts a topic' do
|
|
Given!(:first_post) { create_post(user: old_user) }
|
|
|
|
context 'a reply by a new user at the same IP address' do
|
|
Given!(:second_post) { create_post(user: spammer2, topic: first_post.topic) }
|
|
|
|
Then { first_post.reload.spam_count.should == 0 }
|
|
And { second_post.reload.spam_count.should == 1 }
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
end
|