|
3 | 3 | require "rails_helper" |
4 | 4 |
|
5 | 5 | describe ::DiscourseTranslator::TranslatorSelectionValidator do |
6 | | - subject { described_class.new } |
7 | | - |
8 | | - fab!(:llm_model) { Fabricate(:llm_model) } |
| 6 | + fab!(:llm_model) |
9 | 7 |
|
10 | 8 | describe "#valid_value?" do |
11 | 9 | context "when value is blank" do |
12 | 10 | it "returns true" do |
13 | | - expect(subject.valid_value?(nil)).to eq(true) |
14 | | - expect(subject.valid_value?("")).to eq(true) |
| 11 | + expect(described_class.new.valid_value?(nil)).to eq(true) |
| 12 | + expect(described_class.new.valid_value?("")).to eq(true) |
15 | 13 | end |
16 | 14 | end |
17 | 15 |
|
18 | 16 | context "when value is 'DiscourseAi'" do |
19 | | - context "when DiscourseAutomation is not defined" do |
| 17 | + context "when DiscourseAi is not defined" do |
20 | 18 | it "returns false" do |
21 | | - hide_const("DiscourseAutomation") |
22 | | - expect(subject.valid_value?("DiscourseAi")).to eq(false) |
| 19 | + hide_const("DiscourseAi") |
| 20 | + expect(described_class.new.valid_value?("DiscourseAi")).to eq(false) |
23 | 21 | end |
24 | 22 | end |
25 | 23 |
|
26 | | - context "when DiscourseAutomation is defined but ai_helper_enabled is false" do |
| 24 | + context "when DiscourseAi is defined but ai_helper_enabled is false" do |
27 | 25 | it "returns false" do |
28 | 26 | SiteSetting.ai_helper_enabled = false |
29 | | - expect(subject.valid_value?("DiscourseAi")).to eq(false) |
| 27 | + expect(described_class.new.valid_value?("DiscourseAi")).to eq(false) |
30 | 28 | end |
31 | 29 | end |
32 | 30 |
|
33 | | - context "when DiscourseAutomation is defined and ai_helper_enabled is true" do |
| 31 | + context "when DiscourseAi is defined and ai_helper_enabled is true" do |
34 | 32 | it "returns true" do |
35 | 33 | DiscourseAi::Completions::Llm.with_prepared_responses(["OK"]) do |
36 | 34 | SiteSetting.ai_helper_model = "custom:#{llm_model.id}" |
37 | 35 | SiteSetting.ai_helper_enabled = true |
38 | 36 | end |
39 | | - expect(subject.valid_value?("DiscourseAi")).to eq(true) |
| 37 | + expect(described_class.new.valid_value?("DiscourseAi")).to eq(true) |
40 | 38 | end |
41 | 39 | end |
42 | 40 | end |
43 | 41 |
|
44 | 42 | context "when value is not 'DiscourseAi'" do |
45 | 43 | it "returns true" do |
46 | | - expect(subject.valid_value?("googly")).to eq(true) |
47 | | - expect(subject.valid_value?("poopy")).to eq(true) |
| 44 | + expect(described_class.new.valid_value?("googly")).to eq(true) |
| 45 | + expect(described_class.new.valid_value?("poopy")).to eq(true) |
48 | 46 | end |
49 | 47 | end |
50 | 48 | end |
51 | 49 |
|
52 | 50 | describe "#error_message" do |
53 | | - context "when DiscourseAutomation is not defined" do |
| 51 | + context "when DiscourseAi is not defined" do |
54 | 52 | it "returns the not_installed error message" do |
55 | | - hide_const("DiscourseAutomation") |
56 | | - expect(subject.error_message).to eq(I18n.t("translator.discourse_ai.not_installed")) |
| 53 | + hide_const("DiscourseAi") |
| 54 | + expect(described_class.new.error_message).to eq( |
| 55 | + I18n.t("translator.discourse_ai.not_installed"), |
| 56 | + ) |
57 | 57 | end |
58 | 58 | end |
59 | 59 |
|
60 | | - context "when DiscourseAutomation is defined but ai_helper_enabled is false" do |
| 60 | + context "when DiscourseAi is defined but ai_helper_enabled is false" do |
61 | 61 | it "returns the ai_helper_required error message" do |
62 | 62 | SiteSetting.ai_helper_enabled = false |
63 | | - expect(subject.error_message).to eq(I18n.t("translator.discourse_ai.ai_helper_required")) |
| 63 | + expect(described_class.new.error_message).to eq( |
| 64 | + I18n.t("translator.discourse_ai.ai_helper_required"), |
| 65 | + ) |
64 | 66 | end |
65 | 67 | end |
66 | 68 |
|
67 | | - context "when DiscourseAutomation is defined and ai_helper_enabled is true" do |
| 69 | + context "when DiscourseAi is defined and ai_helper_enabled is true" do |
68 | 70 | it "returns nil" do |
69 | 71 | DiscourseAi::Completions::Llm.with_prepared_responses(["OK"]) do |
70 | 72 | SiteSetting.ai_helper_model = "custom:#{llm_model.id}" |
71 | 73 | SiteSetting.ai_helper_enabled = true |
72 | 74 | end |
73 | | - expect(subject.error_message).to be_nil |
| 75 | + expect(described_class.new.error_message).to be_nil |
74 | 76 | end |
75 | 77 | end |
76 | 78 | end |
|
0 commit comments