]> git.openstreetmap.org Git - rails.git/blob - test/lib/spam_scorer_test.rb
Merge remote-tracking branch 'upstream/pull/6549'
[rails.git] / test / lib / spam_scorer_test.rb
1 # frozen_string_literal: true
2
3 require "test_helper"
4
5 class SpamScorerTest < ActiveSupport::TestCase
6   def test_html_spam_score
7     r = RichText.new("html", "foo <a href='http://example.com/'>bar</a> baz")
8     scorer = SpamScorer.new_from_rich_text(r)
9     assert_equal 55, scorer.score.round
10   end
11
12   def test_markdown_spam_score
13     r = RichText.new("markdown", "foo [bar](http://example.com/) baz")
14     scorer = SpamScorer.new_from_rich_text(r)
15     assert_equal 50, scorer.score.round
16   end
17
18   def test_text_spam_score
19     r = RichText.new("text", "foo http://example.com/ bar")
20     scorer = SpamScorer.new_from_rich_text(r)
21     assert_equal 141, scorer.score.round
22   end
23
24   def test_user_spam_score
25     user = build(:user, :description => "foo [bar](http://example.com/) baz")
26     scorer = SpamScorer.new_from_user(user)
27     assert_equal 12, scorer.score
28   end
29
30   def test_spammy_phrases
31     create(:spammy_phrase, :phrase => "Business Description:")
32     create(:spammy_phrase, :phrase => "Additional Keywords:")
33     create(:spammy_phrase, :phrase => "Große Preise")
34     create(:spammy_phrase, :phrase => "Relevant Experience:")
35     r = RichText.new(
36       "markdown",
37       <<~SPAM
38         BUSINESS DESCRIPTION: totally legit beesknees.
39         Additional Keywords: apiary joints.
40         GROSSE PREISE: VIEL GELD.
41         RELEVANT EⅩPERIENCE: disguising latin characters as roman numerals.
42       SPAM
43     )
44     scorer = SpamScorer.new_from_rich_text(r)
45     assert_equal 160, scorer.score.round
46   end
47 end