Skip to content

Commit 706943c

Browse files
committed
Lint
1 parent a8030aa commit 706943c

File tree

2 files changed

+27
-23
lines changed

2 files changed

+27
-23
lines changed

spec/lib/translator_selection_validator_spec.rb

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,28 @@
33
require "rails_helper"
44

55
describe ::DiscourseTranslator::TranslatorSelectionValidator do
6-
subject { described_class.new }
7-
8-
fab!(:llm_model) { Fabricate(:llm_model) }
6+
fab!(:llm_model)
97

108
describe "#valid_value?" do
119
context "when value is blank" do
1210
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)
1513
end
1614
end
1715

1816
context "when value is 'DiscourseAi'" do
1917
context "when DiscourseAutomation is not defined" do
2018
it "returns false" do
2119
hide_const("DiscourseAutomation")
22-
expect(subject.valid_value?("DiscourseAi")).to eq(false)
20+
expect(described_class.new.valid_value?("DiscourseAi")).to eq(false)
2321
end
2422
end
2523

2624
context "when DiscourseAutomation is defined but ai_helper_enabled is false" do
2725
it "returns false" do
2826
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)
3028
end
3129
end
3230

@@ -36,15 +34,15 @@
3634
SiteSetting.ai_helper_model = "custom:#{llm_model.id}"
3735
SiteSetting.ai_helper_enabled = true
3836
end
39-
expect(subject.valid_value?("DiscourseAi")).to eq(true)
37+
expect(described_class.new.valid_value?("DiscourseAi")).to eq(true)
4038
end
4139
end
4240
end
4341

4442
context "when value is not 'DiscourseAi'" do
4543
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)
4846
end
4947
end
5048
end
@@ -53,14 +51,18 @@
5351
context "when DiscourseAutomation is not defined" do
5452
it "returns the not_installed error message" do
5553
hide_const("DiscourseAutomation")
56-
expect(subject.error_message).to eq(I18n.t("translator.discourse_ai.not_installed"))
54+
expect(described_class.new.error_message).to eq(
55+
I18n.t("translator.discourse_ai.not_installed"),
56+
)
5757
end
5858
end
5959

6060
context "when DiscourseAutomation is defined but ai_helper_enabled is false" do
6161
it "returns the ai_helper_required error message" do
6262
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+
)
6466
end
6567
end
6668

@@ -70,7 +72,7 @@
7072
SiteSetting.ai_helper_model = "custom:#{llm_model.id}"
7173
SiteSetting.ai_helper_enabled = true
7274
end
73-
expect(subject.error_message).to be_nil
75+
expect(described_class.new.error_message).to be_nil
7476
end
7577
end
7678
end

spec/services/discourse_ai_spec.rb

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,31 @@
2323
end
2424

2525
it "truncates to MAX LENGTH" do
26-
truncated_text = post.cooked.truncate(DiscourseTranslator::DiscourseAi::MAX_DETECT_LOCALE_TEXT_LENGTH)
27-
expect_any_instance_of(::DiscourseAi::AiHelper::Assistant)
28-
.to receive(:generate_and_send_prompt)
29-
.with(
30-
CompletionPrompt.find_by(id: CompletionPrompt::DETECT_TEXT_LOCALE),
31-
truncated_text,
32-
Discourse.system_user
33-
).and_call_original
26+
truncated_text =
27+
post.cooked.truncate(DiscourseTranslator::DiscourseAi::MAX_DETECT_LOCALE_TEXT_LENGTH)
28+
expect_any_instance_of(::DiscourseAi::AiHelper::Assistant).to receive(
29+
:generate_and_send_prompt,
30+
).with(
31+
CompletionPrompt.find_by(id: CompletionPrompt::DETECT_TEXT_LOCALE),
32+
truncated_text,
33+
Discourse.system_user,
34+
).and_call_original
3435

3536
DiscourseAi::Completions::Llm.with_prepared_responses(["<output>de</output>"]) do
3637
DiscourseTranslator::DiscourseAi.detect(post)
3738
end
3839
end
3940

4041
it "returns if settings are not correct" do
41-
4242
end
4343
end
4444

4545
describe ".translate" do
4646
it "translates the post and returns [locale, translated_text]" do
4747
post = Fabricate(:post)
48-
DiscourseAi::Completions::Llm.with_prepared_responses(["<output>some translated text</output>", "<output>translated</output>"]) do
48+
DiscourseAi::Completions::Llm.with_prepared_responses(
49+
["<output>some translated text</output>", "<output>translated</output>"],
50+
) do
4951
locale, translated_text = DiscourseTranslator::DiscourseAi.translate(post)
5052
expect(locale).to eq "de"
5153
expect(translated_text).to eq "some translated text"

0 commit comments

Comments
 (0)