DEV: Fix new Rubocop offenses

This commit is contained in:
Loïc Guitaut 2024-03-05 16:48:28 +01:00 committed by Loïc Guitaut
parent 8b382d6098
commit 6ae4218a96
43 changed files with 88 additions and 66 deletions

View File

@ -1,11 +1,30 @@
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
activesupport (7.1.3.2)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
ast (2.4.2) ast (2.4.2)
base64 (0.2.0)
bigdecimal (3.1.6)
concurrent-ruby (1.2.3)
connection_pool (2.4.1)
drb (2.2.1)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
json (2.7.1) json (2.7.1)
language_server-protocol (3.17.0.3) language_server-protocol (3.17.0.3)
minitest (5.22.2)
mutex_m (0.2.0)
parallel (1.24.0) parallel (1.24.0)
parser (3.3.0.3) parser (3.3.0.5)
ast (~> 2.4.1) ast (~> 2.4.1)
racc racc
prettier_print (1.2.1) prettier_print (1.2.1)
@ -13,33 +32,38 @@ GEM
rainbow (3.1.1) rainbow (3.1.1)
regexp_parser (2.9.0) regexp_parser (2.9.0)
rexml (3.2.6) rexml (3.2.6)
rubocop (1.59.0) rubocop (1.61.0)
json (~> 2.3) json (~> 2.3)
language_server-protocol (>= 3.17.0) language_server-protocol (>= 3.17.0)
parallel (~> 1.10) parallel (~> 1.10)
parser (>= 3.2.2.4) parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0) rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0) regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0) rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.30.0, < 2.0) rubocop-ast (>= 1.30.0, < 2.0)
ruby-progressbar (~> 1.7) ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0) unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.30.0) rubocop-ast (1.31.1)
parser (>= 3.2.1.0) parser (>= 3.3.0.4)
rubocop-capybara (2.20.0) rubocop-capybara (2.20.0)
rubocop (~> 1.41) rubocop (~> 1.41)
rubocop-discourse (3.6.0) rubocop-discourse (3.7.1)
activesupport (>= 6.1)
rubocop (>= 1.59.0) rubocop (>= 1.59.0)
rubocop-capybara (>= 2.0.0)
rubocop-factory_bot (>= 2.0.0)
rubocop-rspec (>= 2.25.0) rubocop-rspec (>= 2.25.0)
rubocop-factory_bot (2.25.1) rubocop-factory_bot (2.25.1)
rubocop (~> 1.41) rubocop (~> 1.41)
rubocop-rspec (2.26.1) rubocop-rspec (2.27.1)
rubocop (~> 1.40) rubocop (~> 1.40)
rubocop-capybara (~> 2.17) rubocop-capybara (~> 2.17)
rubocop-factory_bot (~> 2.22) rubocop-factory_bot (~> 2.22)
ruby-progressbar (1.13.0) ruby-progressbar (1.13.0)
syntax_tree (6.2.0) syntax_tree (6.2.0)
prettier_print (>= 1.2.0) prettier_print (>= 1.2.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0) unicode-display_width (2.5.0)
PLATFORMS PLATFORMS

View File

@ -3,6 +3,8 @@
module DiscourseAi module DiscourseAi
module Admin module Admin
class AiPersonasController < ::Admin::AdminController class AiPersonasController < ::Admin::AdminController
requires_plugin ::DiscourseAi::PLUGIN_NAME
before_action :find_ai_persona, only: %i[show update destroy create_user] before_action :find_ai_persona, only: %i[show update destroy create_user]
def index def index

View File

@ -4,9 +4,7 @@ if defined?(DiscourseAutomation)
module DiscourseAutomation::LlmReport module DiscourseAutomation::LlmReport
end end
DiscourseAutomation::Scriptable::LLM_REPORT = "llm_report" DiscourseAutomation::Scriptable.add("llm_report") do
DiscourseAutomation::Scriptable.add(DiscourseAutomation::Scriptable::LLM_REPORT) do
version 1 version 1
triggerables %i[recurring] triggerables %i[recurring]

View File

@ -1,9 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
if defined?(DiscourseAutomation) if defined?(DiscourseAutomation)
DiscourseAutomation::Scriptable::LLM_TRIAGE = "llm_triage" DiscourseAutomation::Scriptable.add("llm_triage") do
DiscourseAutomation::Scriptable.add(DiscourseAutomation::Scriptable::LLM_TRIAGE) do
version 1 version 1
run_in_background run_in_background
@ -17,7 +15,7 @@ if defined?(DiscourseAutomation)
validator: ->(input) do validator: ->(input) do
if !input.include?("%%POST%%") if !input.include?("%%POST%%")
I18n.t( I18n.t(
"discourse_automation.scriptables.#{DiscourseAutomation::Scriptable::LLM_TRIAGE}.system_prompt_missing_post_placeholder", "discourse_automation.scriptables.llm_triage.system_prompt_missing_post_placeholder",
) )
end end
end, end,

View File

@ -6,7 +6,7 @@ RSpec.describe Jobs::StreamPostHelper do
before { SiteSetting.ai_helper_model = "fake:fake" } before { SiteSetting.ai_helper_model = "fake:fake" }
describe "#execute" do describe "#execute" do
fab!(:topic) { Fabricate(:topic) } fab!(:topic)
fab!(:post) do fab!(:post) do
Fabricate( Fabricate(
:post, :post,

View File

@ -56,7 +56,7 @@ end
RSpec.describe DiscourseAi::Completions::Endpoints::Anthropic do RSpec.describe DiscourseAi::Completions::Endpoints::Anthropic do
subject(:endpoint) { described_class.new("claude-2", DiscourseAi::Tokenizer::AnthropicTokenizer) } subject(:endpoint) { described_class.new("claude-2", DiscourseAi::Tokenizer::AnthropicTokenizer) }
fab!(:user) { Fabricate(:user) } fab!(:user)
let(:anthropic_mock) { AnthropicMock.new(endpoint) } let(:anthropic_mock) { AnthropicMock.new(endpoint) }

View File

@ -75,7 +75,7 @@ end
RSpec.describe DiscourseAi::Completions::Endpoints::AwsBedrock do RSpec.describe DiscourseAi::Completions::Endpoints::AwsBedrock do
subject(:endpoint) { described_class.new("claude-2", DiscourseAi::Tokenizer::AnthropicTokenizer) } subject(:endpoint) { described_class.new("claude-2", DiscourseAi::Tokenizer::AnthropicTokenizer) }
fab!(:user) { Fabricate(:user) } fab!(:user)
let(:bedrock_mock) { BedrockMock.new(endpoint) } let(:bedrock_mock) { BedrockMock.new(endpoint) }

View File

@ -130,7 +130,7 @@ end
RSpec.describe DiscourseAi::Completions::Endpoints::Gemini do RSpec.describe DiscourseAi::Completions::Endpoints::Gemini do
subject(:endpoint) { described_class.new("gemini-pro", DiscourseAi::Tokenizer::OpenAiTokenizer) } subject(:endpoint) { described_class.new("gemini-pro", DiscourseAi::Tokenizer::OpenAiTokenizer) }
fab!(:user) { Fabricate(:user) } fab!(:user)
let(:bedrock_mock) { GeminiMock.new(endpoint) } let(:bedrock_mock) { GeminiMock.new(endpoint) }

View File

@ -65,7 +65,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::HuggingFace do
before { SiteSetting.ai_hugging_face_api_url = "https://test.dev" } before { SiteSetting.ai_hugging_face_api_url = "https://test.dev" }
fab!(:user) { Fabricate(:user) } fab!(:user)
let(:hf_mock) { HuggingFaceMock.new(endpoint) } let(:hf_mock) { HuggingFaceMock.new(endpoint) }

View File

@ -62,7 +62,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::Vllm do
) )
end end
fab!(:user) { Fabricate(:user) } fab!(:user)
let(:anthropic_mock) { VllmMock.new(endpoint) } let(:anthropic_mock) { VllmMock.new(endpoint) }

View File

@ -9,7 +9,7 @@ RSpec.describe DiscourseAi::Completions::Llm do
) )
end end
fab!(:user) { Fabricate(:user) } fab!(:user)
describe ".proxy" do describe ".proxy" do
it "raises an exception when we can't proxy the model" do it "raises an exception when we can't proxy the model" do

View File

@ -3,7 +3,7 @@
return if !defined?(DiscourseAutomation) return if !defined?(DiscourseAutomation)
describe DiscourseAi::Automation::LlmTriage do describe DiscourseAi::Automation::LlmTriage do
fab!(:post) { Fabricate(:post) } fab!(:post)
let(:automation) { Fabricate(:automation, script: "llm_triage", enabled: true) } let(:automation) { Fabricate(:automation, script: "llm_triage", enabled: true) }

View File

@ -3,7 +3,7 @@
RSpec.describe DiscourseAi::AiBot::Bot do RSpec.describe DiscourseAi::AiBot::Bot do
subject(:bot) { described_class.as(bot_user) } subject(:bot) { described_class.as(bot_user) }
fab!(:admin) { Fabricate(:admin) } fab!(:admin)
before do before do
SiteSetting.ai_bot_enabled_chat_bots = "gpt-4" SiteSetting.ai_bot_enabled_chat_bots = "gpt-4"

View File

@ -3,7 +3,7 @@
RSpec.describe DiscourseAi::AiBot::EntryPoint do RSpec.describe DiscourseAi::AiBot::EntryPoint do
describe "#inject_into" do describe "#inject_into" do
describe "subscribes to the post_created event" do describe "subscribes to the post_created event" do
fab!(:admin) { Fabricate(:admin) } fab!(:admin)
let(:gpt_bot) { User.find(described_class::GPT4_ID) } let(:gpt_bot) { User.find(described_class::GPT4_ID) }
fab!(:bot_allowed_group) { Fabricate(:group) } fab!(:bot_allowed_group) { Fabricate(:group) }

View File

@ -4,7 +4,7 @@ RSpec.describe Jobs::CreateAiReply do
before { SiteSetting.ai_bot_enabled = true } before { SiteSetting.ai_bot_enabled = true }
describe "#execute" do describe "#execute" do
fab!(:topic) { Fabricate(:topic) } fab!(:topic)
fab!(:post) { Fabricate(:post, topic: topic) } fab!(:post) { Fabricate(:post, topic: topic) }
let(:expected_response) do let(:expected_response) do

View File

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
RSpec.describe DiscourseAi::AiHelper::Assistant do RSpec.describe DiscourseAi::AiHelper::Assistant do
fab!(:user) { Fabricate(:user) } fab!(:user)
let(:prompt) { CompletionPrompt.find_by(id: mode) } let(:prompt) { CompletionPrompt.find_by(id: mode) }
before { SiteSetting.ai_helper_model = "fake:fake" } before { SiteSetting.ai_helper_model = "fake:fake" }

View File

@ -7,7 +7,7 @@ RSpec.describe DiscourseAi::AiHelper::ChatThreadTitler do
fab!(:thread) { Fabricate(:chat_thread) } fab!(:thread) { Fabricate(:chat_thread) }
fab!(:chat_message) { Fabricate(:chat_message, thread: thread) } fab!(:chat_message) { Fabricate(:chat_message, thread: thread) }
fab!(:user) { Fabricate(:user) } fab!(:user)
describe "#cleanup" do describe "#cleanup" do
it "picks the first when there are multiple" do it "picks the first when there are multiple" do

View File

@ -3,7 +3,7 @@
RSpec.describe DiscourseAi::AiHelper::Painter do RSpec.describe DiscourseAi::AiHelper::Painter do
subject(:painter) { described_class.new } subject(:painter) { described_class.new }
fab!(:user) { Fabricate(:user) } fab!(:user)
before do before do
SiteSetting.ai_helper_model = "fake:fake" SiteSetting.ai_helper_model = "fake:fake"

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
describe DiscourseAi::Automation::LlmTriage do describe DiscourseAi::Automation::LlmTriage do
fab!(:post) { Fabricate(:post) } fab!(:post)
def triage(**args) def triage(**args)
DiscourseAi::Automation::LlmTriage.handle(**args) DiscourseAi::Automation::LlmTriage.handle(**args)

View File

@ -13,13 +13,13 @@ module DiscourseAi
fab!(:secure_topic) { Fabricate(:topic, category: secure_category) } fab!(:secure_topic) { Fabricate(:topic, category: secure_category) }
fab!(:secure_post) { Fabricate(:post, raw: "Top secret date !!!!", topic: secure_topic) } fab!(:secure_post) { Fabricate(:post, raw: "Top secret date !!!!", topic: secure_topic) }
fab!(:category) { Fabricate(:category) } fab!(:category)
fab!(:topic_in_category) { Fabricate(:topic, category: category) } fab!(:topic_in_category) { Fabricate(:topic, category: category) }
fab!(:post_in_category) do fab!(:post_in_category) do
Fabricate(:post, raw: "I am in a category", topic: topic_in_category) Fabricate(:post, raw: "I am in a category", topic: topic_in_category)
end end
fab!(:tag) { Fabricate(:tag) } fab!(:tag)
fab!(:topic_with_tag) { Fabricate(:topic, tags: [tag]) } fab!(:topic_with_tag) { Fabricate(:topic, tags: [tag]) }
fab!(:post_with_tag) { Fabricate(:post, raw: "I am in a tag", topic: topic_with_tag) } fab!(:post_with_tag) { Fabricate(:post, raw: "I am in a tag", topic: topic_with_tag) }

View File

@ -9,7 +9,7 @@ RSpec.describe Jobs::GenerateEmbeddings do
SiteSetting.ai_embeddings_enabled = true SiteSetting.ai_embeddings_enabled = true
end end
fab!(:topic) { Fabricate(:topic) } fab!(:topic)
fab!(:post) { Fabricate(:post, post_number: 1, topic: topic) } fab!(:post) { Fabricate(:post, post_number: 1, topic: topic) }
let(:truncation) { DiscourseAi::Embeddings::Strategies::Truncation.new } let(:truncation) { DiscourseAi::Embeddings::Strategies::Truncation.new }

View File

@ -1,8 +1,8 @@
# frozen_string_literal: true # frozen_string_literal: true
RSpec.describe DiscourseAi::Embeddings::SemanticSearch do RSpec.describe DiscourseAi::Embeddings::SemanticSearch do
fab!(:post) { Fabricate(:post) } fab!(:post)
fab!(:user) { Fabricate(:user) } fab!(:user)
let(:query) { "test_query" } let(:query) { "test_query" }
let(:subject) { described_class.new(Guardian.new(user)) } let(:subject) { described_class.new(Guardian.new(user)) }
@ -104,7 +104,7 @@ RSpec.describe DiscourseAi::Embeddings::SemanticSearch do
end end
context "when the post belongs to a secured category" do context "when the post belongs to a secured category" do
fab!(:group) { Fabricate(:group) } fab!(:group)
fab!(:private_category) { Fabricate(:private_category, group: group) } fab!(:private_category) { Fabricate(:private_category, group: group) }
before do before do

View File

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
describe DiscourseAi::Embeddings::EntryPoint do describe DiscourseAi::Embeddings::EntryPoint do
fab!(:user) { Fabricate(:user) } fab!(:user)
describe "SemanticTopicQuery extension" do describe "SemanticTopicQuery extension" do
describe "#list_semantic_related_topics" do describe "#list_semantic_related_topics" do
@ -39,7 +39,7 @@ describe DiscourseAi::Embeddings::EntryPoint do
end end
context "when the semantic search returns a topic from a restricted category" do context "when the semantic search returns a topic from a restricted category" do
fab!(:group) { Fabricate(:group) } fab!(:group)
fab!(:category) { Fabricate(:private_category, group: group) } fab!(:category) { Fabricate(:private_category, group: group) }
fab!(:secured_category_topic) { Fabricate(:topic, category: category) } fab!(:secured_category_topic) { Fabricate(:topic, category: category) }

View File

@ -7,7 +7,7 @@ RSpec.describe DiscourseAi::Embeddings::Strategies::Truncation do
context "when using vector from OpenAI" do context "when using vector from OpenAI" do
before { SiteSetting.max_post_length = 100_000 } before { SiteSetting.max_post_length = 100_000 }
fab!(:topic) { Fabricate(:topic) } fab!(:topic)
fab!(:post) do fab!(:post) do
Fabricate(:post, topic: topic, raw: "Baby, bird, bird, bird\nBird is the word\n" * 500) Fabricate(:post, topic: topic, raw: "Baby, bird, bird, bird\nBird is the word\n" * 500)
end end

View File

@ -53,7 +53,7 @@ describe DiscourseAi::Toxicity::EntryPoint do
context "when editing a chat message" do context "when editing a chat message" do
# This fabricator trigger events because it uses the UpdateMessage service. # This fabricator trigger events because it uses the UpdateMessage service.
# Using let makes the test fail. # Using let makes the test fail.
fab!(:chat_message) { Fabricate(:chat_message) } fab!(:chat_message)
let(:updater) do let(:updater) do
Chat::UpdateMessage.call( Chat::UpdateMessage.call(
guardian: Guardian.new(chat_message.user), guardian: Guardian.new(chat_message.user),

View File

@ -9,7 +9,7 @@ describe Jobs::ToxicityClassifyChatMessage do
SiteSetting.ai_toxicity_flag_automatically = true SiteSetting.ai_toxicity_flag_automatically = true
end end
fab!(:chat_message) { Fabricate(:chat_message) } fab!(:chat_message)
describe "scenarios where we return early without doing anything" do describe "scenarios where we return early without doing anything" do
it "does nothing when ai_toxicity_enabled is disabled" do it "does nothing when ai_toxicity_enabled is disabled" do

View File

@ -10,7 +10,7 @@ describe Jobs::ToxicityClassifyPost do
SiteSetting.ai_toxicity_flag_automatically = true SiteSetting.ai_toxicity_flag_automatically = true
end end
fab!(:post) { Fabricate(:post) } fab!(:post)
describe "scenarios where we return early without doing anything" do describe "scenarios where we return early without doing anything" do
it "does nothing when ai_toxicity_enabled is disabled" do it "does nothing when ai_toxicity_enabled is disabled" do

View File

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
describe DiscourseAi::Toxicity::ScanQueue do describe DiscourseAi::Toxicity::ScanQueue do
fab!(:group) { Fabricate(:group) } fab!(:group)
before do before do
SiteSetting.ai_toxicity_enabled = true SiteSetting.ai_toxicity_enabled = true
@ -9,7 +9,7 @@ describe DiscourseAi::Toxicity::ScanQueue do
end end
describe "#enqueue_post" do describe "#enqueue_post" do
fab!(:post) { Fabricate(:post) } fab!(:post)
it "queues a job" do it "queues a job" do
expect { described_class.enqueue_post(post) }.to change( expect { described_class.enqueue_post(post) }.to change(
@ -38,7 +38,7 @@ describe DiscourseAi::Toxicity::ScanQueue do
end end
describe "#enqueue_chat_message" do describe "#enqueue_chat_message" do
fab!(:chat_message) { Fabricate(:chat_message) } fab!(:chat_message)
it "queues a job" do it "queues a job" do
expect { described_class.enqueue_chat_message(chat_message) }.to change( expect { described_class.enqueue_chat_message(chat_message) }.to change(

View File

@ -1,9 +1,9 @@
# frozen_string_literal: true # frozen_string_literal: true
RSpec.describe ReviewableAiChatMessage, type: :model do RSpec.describe ReviewableAiChatMessage, type: :model do
fab!(:moderator) { Fabricate(:moderator) } fab!(:moderator)
fab!(:user) { Fabricate(:user) } fab!(:user)
fab!(:chat_channel) { Fabricate(:chat_channel) } fab!(:chat_channel)
fab!(:chat_message) { Fabricate(:chat_message, chat_channel: chat_channel, user: user) } fab!(:chat_message) { Fabricate(:chat_message, chat_channel: chat_channel, user: user) }
fab!(:reviewable) { described_class.needs_review!(target: chat_message, created_by: moderator) } fab!(:reviewable) { described_class.needs_review!(target: chat_message, created_by: moderator) }

View File

@ -121,7 +121,7 @@ describe ReviewableAiPost do
let(:reviewable) do let(:reviewable) do
described_class.needs_review!(target: target, created_by: Discourse.system_user) described_class.needs_review!(target: target, created_by: Discourse.system_user)
end end
fab!(:admin) { Fabricate(:admin) } fab!(:admin)
before do before do
reviewable.add_score( reviewable.add_score(

View File

@ -6,8 +6,8 @@ describe Plugin::Instance do
before { SiteSetting.discourse_ai_enabled = true } before { SiteSetting.discourse_ai_enabled = true }
describe "on reviewable_transitioned_to event" do describe "on reviewable_transitioned_to event" do
fab!(:post) { Fabricate(:post) } fab!(:post)
fab!(:admin) { Fabricate(:admin) } fab!(:admin)
it "adjusts model accuracy" do it "adjusts model accuracy" do
ToxicityInferenceStubs.stub_post_classification(post, toxic: true) ToxicityInferenceStubs.stub_post_classification(post, toxic: true)

View File

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
RSpec.describe DiscourseAi::AiBot::BotController do RSpec.describe DiscourseAi::AiBot::BotController do
fab!(:user) { Fabricate(:user) } fab!(:user)
before { sign_in(user) } before { sign_in(user) }
describe "#stop_streaming_response" do describe "#stop_streaming_response" do

View File

@ -32,7 +32,7 @@ RSpec.describe DiscourseAi::AiHelper::AssistantController do
end end
context "when logged in as an allowed user" do context "when logged in as an allowed user" do
fab!(:user) { Fabricate(:user) } fab!(:user)
before do before do
sign_in(user) sign_in(user)
@ -109,7 +109,7 @@ RSpec.describe DiscourseAi::AiHelper::AssistantController do
end end
describe "#caption_image" do describe "#caption_image" do
fab!(:upload) { Fabricate(:upload) } fab!(:upload)
let(:image_url) { "#{Discourse.base_url}#{upload.url}" } let(:image_url) { "#{Discourse.base_url}#{upload.url}" }
let(:caption) { "A picture of a cat sitting on a table" } let(:caption) { "A picture of a cat sitting on a table" }
let(:caption_with_attrs) do let(:caption_with_attrs) do
@ -161,7 +161,7 @@ RSpec.describe DiscourseAi::AiHelper::AssistantController do
end end
context "for secure uploads" do context "for secure uploads" do
fab!(:group) { Fabricate(:group) } fab!(:group)
fab!(:private_category) { Fabricate(:private_category, group: group) } fab!(:private_category) { Fabricate(:private_category, group: group) }
fab!(:post_in_secure_context) do fab!(:post_in_secure_context) do
Fabricate(:post, topic: Fabricate(:topic, category: private_category)) Fabricate(:post, topic: Fabricate(:topic, category: private_category))

View File

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
describe ::TopicsController do describe ::TopicsController do
fab!(:topic) { Fabricate(:topic) } fab!(:topic)
fab!(:topic1) { Fabricate(:topic) } fab!(:topic1) { Fabricate(:topic) }
fab!(:topic2) { Fabricate(:topic) } fab!(:topic2) { Fabricate(:topic) }
fab!(:topic3) { Fabricate(:topic) } fab!(:topic3) { Fabricate(:topic) }

View File

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
RSpec.describe AiChatChannelSerializer do RSpec.describe AiChatChannelSerializer do
fab!(:admin) { Fabricate(:admin) } fab!(:admin)
describe "#title" do describe "#title" do
context "when the channel is a DM" do context "when the channel is a DM" do

View File

@ -3,7 +3,7 @@
require_relative "../support/toxicity_inference_stubs" require_relative "../support/toxicity_inference_stubs"
describe DiscourseAi::ChatMessageClassificator do describe DiscourseAi::ChatMessageClassificator do
fab!(:chat_message) { Fabricate(:chat_message) } fab!(:chat_message)
let(:model) { DiscourseAi::Toxicity::ToxicityClassification.new } let(:model) { DiscourseAi::Toxicity::ToxicityClassification.new }
let(:classification) { described_class.new(model) } let(:classification) { described_class.new(model) }

View File

@ -3,7 +3,7 @@
require_relative "../support/toxicity_inference_stubs" require_relative "../support/toxicity_inference_stubs"
describe DiscourseAi::PostClassificator do describe DiscourseAi::PostClassificator do
fab!(:post) { Fabricate(:post) } fab!(:post)
let(:model) { DiscourseAi::Toxicity::ToxicityClassification.new } let(:model) { DiscourseAi::Toxicity::ToxicityClassification.new }
let(:classification) { described_class.new(model) } let(:classification) { described_class.new(model) }

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
RSpec.describe "AI chat channel summarization", type: :system, js: true do RSpec.describe "AI chat channel summarization", type: :system, js: true do
fab!(:user) { Fabricate(:user) } fab!(:user)
fab!(:group) { Fabricate(:group, visibility_level: Group.visibility_levels[:staff]) } fab!(:group) { Fabricate(:group, visibility_level: Group.visibility_levels[:staff]) }
before do before do

View File

@ -17,7 +17,7 @@ RSpec.describe "AI Composer helper", type: :system, js: true do
let(:ai_helper_context_menu) { PageObjects::Components::AIHelperContextMenu.new } let(:ai_helper_context_menu) { PageObjects::Components::AIHelperContextMenu.new }
let(:diff_modal) { PageObjects::Modals::DiffModal.new } let(:diff_modal) { PageObjects::Modals::DiffModal.new }
let(:ai_suggestion_dropdown) { PageObjects::Components::AISuggestionDropdown.new } let(:ai_suggestion_dropdown) { PageObjects::Components::AISuggestionDropdown.new }
fab!(:category) { Fabricate(:category) } fab!(:category)
fab!(:category_2) { Fabricate(:category) } fab!(:category_2) { Fabricate(:category) }
fab!(:video) { Fabricate(:tag) } fab!(:video) { Fabricate(:tag) }
fab!(:music) { Fabricate(:tag) } fab!(:music) { Fabricate(:tag) }

View File

@ -3,7 +3,7 @@
RSpec.describe "AI Post helper", type: :system, js: true do RSpec.describe "AI Post helper", type: :system, js: true do
fab!(:user) { Fabricate(:admin) } fab!(:user) { Fabricate(:admin) }
fab!(:non_member_group) { Fabricate(:group) } fab!(:non_member_group) { Fabricate(:group) }
fab!(:topic) { Fabricate(:topic) } fab!(:topic)
fab!(:post) do fab!(:post) do
Fabricate( Fabricate(
:post, :post,

View File

@ -3,8 +3,8 @@
RSpec.describe "AI Post helper", type: :system, js: true do RSpec.describe "AI Post helper", type: :system, js: true do
fab!(:user) { Fabricate(:admin) } fab!(:user) { Fabricate(:admin) }
fab!(:non_member_group) { Fabricate(:group) } fab!(:non_member_group) { Fabricate(:group) }
fab!(:topic) { Fabricate(:topic) } fab!(:topic)
fab!(:category) { Fabricate(:category) } fab!(:category)
fab!(:category_2) { Fabricate(:category) } fab!(:category_2) { Fabricate(:category) }
fab!(:post) do fab!(:post) do
Fabricate( Fabricate(

View File

@ -6,7 +6,7 @@ RSpec.describe "AI Composer helper", type: :system, js: true do
let(:hypothetical_post) { "This is an hypothetical post generated from the keyword apple_pie" } let(:hypothetical_post) { "This is an hypothetical post generated from the keyword apple_pie" }
fab!(:user) { Fabricate(:admin) } fab!(:user) { Fabricate(:admin) }
fab!(:topic) { Fabricate(:topic) } fab!(:topic)
fab!(:post) { Fabricate(:post, topic: topic, raw: "Apple pie is a delicious dessert to eat") } fab!(:post) { Fabricate(:post, topic: topic, raw: "Apple pie is a delicious dessert to eat") }
before do before do

View File

@ -3,8 +3,8 @@
require_relative "../../support/toxicity_inference_stubs" require_relative "../../support/toxicity_inference_stubs"
RSpec.describe "Toxicity-flagged chat messages", type: :system, js: true do RSpec.describe "Toxicity-flagged chat messages", type: :system, js: true do
fab!(:chat_message) { Fabricate(:chat_message) } fab!(:chat_message)
fab!(:admin) { Fabricate(:admin) } fab!(:admin)
before do before do
sign_in(admin) sign_in(admin)