This repository was archived by the owner on Jul 22, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +33
-1
lines changed Expand file tree Collapse file tree 3 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -412,6 +412,7 @@ discourse_ai:
412412
413413 ai_spam_detection_enabled :
414414 default : false
415+ validator : " DiscourseAi::Configuration::SpamDetectionValidator"
415416 ai_spam_detection_user_id :
416417 default : " "
417418 hidden : true
Original file line number Diff line number Diff line change @@ -8,7 +8,8 @@ def initialize(opts = {})
88 end
99
1010 def valid_value? ( val )
11- return true if Rails . env . test?
11+ # only validate when enabling spam detection
12+ return true if val == "f" || val == "false"
1213 return true if AiModerationSetting . spam
1314
1415 false
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ RSpec . describe DiscourseAi ::Configuration ::SpamDetectionValidator do
4+ let ( :validator ) { described_class . new }
5+
6+ it "always returns true if setting the value to false" do
7+ expect ( validator . valid_value? ( "f" ) ) . to eq ( true )
8+ end
9+
10+ context "when a moderation setting exists" do
11+ fab! ( :llm_model )
12+ before { AiModerationSetting . create! ( setting_type : "spam" , llm_model_id : llm_model . id ) }
13+
14+ it "returns true if a moderation setting for spam exists" do
15+ expect ( validator . valid_value? ( "t" ) ) . to eq ( true )
16+ end
17+ end
18+
19+ context "when no moderation setting exists" do
20+ it "returns false if a moderation setting for spam does not exist" do
21+ expect ( validator . valid_value? ( "t" ) ) . to eq ( false )
22+ end
23+
24+ it "returns an error message when no moderation setting exists" do
25+ expect ( validator . error_message ) . to eq (
26+ I18n . t ( "discourse_ai.spam_detection.configuration_missing" ) ,
27+ )
28+ end
29+ end
30+ end
You can’t perform that action at this time.
0 commit comments