spam detection: whitelist users more than 1 month old.
This commit is contained in:
@@ -52,6 +52,7 @@ class SpamDetector
|
|||||||
def spam?
|
def spam?
|
||||||
return false if !SpamDetector.enabled?
|
return false if !SpamDetector.enabled?
|
||||||
return false if user.is_gold?
|
return false if user.is_gold?
|
||||||
|
return false if user.created_at < 1.month.ago
|
||||||
|
|
||||||
is_spam = super
|
is_spam = super
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ class SpamDetectorTest < ActiveSupport::TestCase
|
|||||||
SpamDetector.stubs(:enabled?).returns(true)
|
SpamDetector.stubs(:enabled?).returns(true)
|
||||||
|
|
||||||
@user = create(:gold_user, created_at: 1.month.ago)
|
@user = create(:gold_user, created_at: 1.month.ago)
|
||||||
@spammer = create(:user, created_at: 1.month.ago, email: "akismet-guaranteed-spam@example.com")
|
@spammer = create(:user, created_at: 2.weeks.ago, email: "akismet-guaranteed-spam@example.com")
|
||||||
end
|
end
|
||||||
|
|
||||||
context "for dmails" do
|
context "for dmails" do
|
||||||
@@ -27,6 +27,15 @@ class SpamDetectorTest < ActiveSupport::TestCase
|
|||||||
refute(dmail.is_spam?)
|
refute(dmail.is_spam?)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "not detect old users as spammers" do
|
||||||
|
@spammer.update!(created_at: 2.months.ago)
|
||||||
|
Dmail.create_split(from: @user, to: @spammer, title: "spam", body: "wonderful spam", creator_ip_addr: "127.0.0.1")
|
||||||
|
|
||||||
|
dmail = @spammer.dmails.last
|
||||||
|
refute(SpamDetector.new(dmail).spam?)
|
||||||
|
refute(dmail.is_spam?)
|
||||||
|
end
|
||||||
|
|
||||||
should "log a message when spam is detected" do
|
should "log a message when spam is detected" do
|
||||||
Rails.logger.expects(:info)
|
Rails.logger.expects(:info)
|
||||||
Dmail.create_split(from: @spammer, to: @user, title: "spam", body: "wonderful spam", creator_ip_addr: "127.0.0.1")
|
Dmail.create_split(from: @spammer, to: @user, title: "spam", body: "wonderful spam", creator_ip_addr: "127.0.0.1")
|
||||||
|
|||||||
Reference in New Issue
Block a user