From b482e7efc3b873640b5b19592974c6a31baabcd5 Mon Sep 17 00:00:00 2001 From: Pablo Brasero Date: Fri, 21 Nov 2025 15:32:10 +0000 Subject: [PATCH] Use spammy phrases from DB --- lib/spam_scorer.rb | 4 ---- lib/spam_scorer/rich_text.rb | 2 +- test/factories/spammy_phrase.rb | 7 +++++++ test/lib/spam_scorer_test.rb | 2 ++ 4 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 test/factories/spammy_phrase.rb diff --git a/lib/spam_scorer.rb b/lib/spam_scorer.rb index 6d62c6951..5086ce56c 100644 --- a/lib/spam_scorer.rb +++ b/lib/spam_scorer.rb @@ -1,10 +1,6 @@ # frozen_string_literal: true module SpamScorer - SPAMMY_PHRASES = [ - "Business Description:", "Additional Keywords:" - ].freeze - def self.new_from_rich_text(text) self::RichText.new(text) end diff --git a/lib/spam_scorer/rich_text.rb b/lib/spam_scorer/rich_text.rb index 5f53fb3df..c480366f1 100644 --- a/lib/spam_scorer/rich_text.rb +++ b/lib/spam_scorer/rich_text.rb @@ -23,7 +23,7 @@ module SpamScorer link_proportion = link_size.to_f / doc.content.length end - spammy_phrases = SPAMMY_PHRASES.count do |phrase| + spammy_phrases = SpammyPhrase.pluck(:phrase).count do |phrase| doc.content.include?(phrase) end diff --git a/test/factories/spammy_phrase.rb b/test/factories/spammy_phrase.rb new file mode 100644 index 000000000..364528b32 --- /dev/null +++ b/test/factories/spammy_phrase.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :spammy_phrase do + phrase { "Casino Enlargement" } + end +end diff --git a/test/lib/spam_scorer_test.rb b/test/lib/spam_scorer_test.rb index 53c790cd4..69b0c694c 100644 --- a/test/lib/spam_scorer_test.rb +++ b/test/lib/spam_scorer_test.rb @@ -28,6 +28,8 @@ class SpamScorerTest < ActiveSupport::TestCase end def test_spammy_phrases + create(:spammy_phrase, :phrase => "Business Description:") + create(:spammy_phrase, :phrase => "Additional Keywords:") r = RichText.new("markdown", "Business Description: totally legit beesknees. Additional Keywords: apiary joints") scorer = SpamScorer.new_from_rich_text(r) assert_equal 80, scorer.score.round -- 2.39.5