dmails: factor out spam detector service.
This commit is contained in:
@@ -17,11 +17,8 @@ class DmailTest < ActiveSupport::TestCase
|
||||
|
||||
context "spam" do
|
||||
setup do
|
||||
Dmail.any_instance.stubs(:spam?).returns(true) unless Danbooru.config.rakismet_key.present?
|
||||
|
||||
# viagra-test-123 is guaranteed to be flagged as spam.
|
||||
# https://akismet.com/development/api/#detailed-docs
|
||||
@spammer = create(:user, name: "viagra-test-123")
|
||||
Dmail.any_instance.stubs(:spam?).returns(true)
|
||||
@spammer = create(:user)
|
||||
@recipient = create(:user)
|
||||
end
|
||||
|
||||
|
||||
31
test/unit/spam_detector.rb
Normal file
31
test/unit/spam_detector.rb
Normal file
@@ -0,0 +1,31 @@
|
||||
require "test_helper"
|
||||
|
||||
class SpamDetectorTest < ActiveSupport::TestCase
|
||||
context "SpamDetector" do
|
||||
setup do
|
||||
skip "SpamDetector not working: API key not configured, not valid, or akismet is down" if !SpamDetector.working?
|
||||
SpamDetector.stubs(:enabled?).returns(true)
|
||||
|
||||
@user = create(:gold_user)
|
||||
@spammer = create(:user, email: "akismet-guaranteed-spam@example.com")
|
||||
end
|
||||
|
||||
context "for dmails" do
|
||||
should "detect spam" do
|
||||
Dmail.create_split(from: @spammer, to: @user, title: "spam", body: "wonderful spam", creator_ip_addr: "127.0.0.1")
|
||||
|
||||
dmail = @user.dmails.last
|
||||
assert(SpamDetector.new(dmail).spam?)
|
||||
assert(dmail.is_spam?)
|
||||
end
|
||||
|
||||
should "not detect gold users as spammers" do
|
||||
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
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user