Skip to content

Commit

Permalink
FIX: Correctly display errors when parent module needs to be disabled…
Browse files Browse the repository at this point in the history
… first (#788)

* FIX: Correctly display errors when parent module needs to be disabled first

* Update spec/configuration/llm_validator_spec.rb

Co-authored-by: Penar Musaraj <[email protected]>

---------

Co-authored-by: Penar Musaraj <[email protected]>
  • Loading branch information
romanrizzi and pmusaraj authored Aug 30, 2024
1 parent e408cd0 commit ed97827
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/configuration/llm_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ def initialize(opts = {})

def valid_value?(val)
if val == ""
parent_module_name = modules_and_choose_llm_settings.invert[@opts[:name]]
@parent_module_name = modules_and_choose_llm_settings.invert[@opts[:name]]

@parent_enabled = SiteSetting.public_send(parent_module_name)
@parent_enabled = SiteSetting.public_send(@parent_module_name)
return !@parent_enabled
end

Expand Down Expand Up @@ -42,7 +42,7 @@ def error_message
return(
I18n.t(
"discourse_ai.llm.configuration.disable_module_first",
setting: parent_module_name,
setting: @parent_module_name,
)
)
end
Expand Down
21 changes: 21 additions & 0 deletions spec/configuration/llm_validator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

RSpec.describe DiscourseAi::Configuration::LlmValidator do
describe "#valid_value?" do
context "when the parent module is enabled and we try to reset the selected model" do
before do
assign_fake_provider_to(:ai_summarization_model)
SiteSetting.ai_summarization_enabled = true
end

it "returns false and displays an error message" do
validator = described_class.new(name: :ai_summarization_model)

value = validator.valid_value?("")

expect(value).to eq(false)
expect(validator.error_message).to include("ai_summarization_enabled")
end
end
end
end

0 comments on commit ed97827

Please sign in to comment.