From ed97827f4901781b4b9af315e711f4deba319c66 Mon Sep 17 00:00:00 2001 From: Roman Rizzi Date: Fri, 30 Aug 2024 17:16:11 -0300 Subject: [PATCH] FIX: Correctly display errors when parent module needs to be disabled 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 --------- Co-authored-by: Penar Musaraj --- lib/configuration/llm_validator.rb | 6 +++--- spec/configuration/llm_validator_spec.rb | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 spec/configuration/llm_validator_spec.rb diff --git a/lib/configuration/llm_validator.rb b/lib/configuration/llm_validator.rb index d3792eab..732a7af2 100644 --- a/lib/configuration/llm_validator.rb +++ b/lib/configuration/llm_validator.rb @@ -9,9 +9,9 @@ module DiscourseAi 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 @@ -42,7 +42,7 @@ module DiscourseAi return( I18n.t( "discourse_ai.llm.configuration.disable_module_first", - setting: parent_module_name, + setting: @parent_module_name, ) ) end diff --git a/spec/configuration/llm_validator_spec.rb b/spec/configuration/llm_validator_spec.rb new file mode 100644 index 00000000..5c9fdecc --- /dev/null +++ b/spec/configuration/llm_validator_spec.rb @@ -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