From 6ae4218a964de15902e78441178eb607a478e0f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Guitaut?= Date: Tue, 5 Mar 2024 16:48:28 +0100 Subject: [PATCH] DEV: Fix new Rubocop offenses --- Gemfile.lock | 38 +++++++++++++++---- .../admin/ai_personas_controller.rb | 2 + discourse_automation/llm_report.rb | 4 +- discourse_automation/llm_triage.rb | 6 +-- spec/jobs/regular/stream_post_helper_spec.rb | 2 +- .../completions/endpoints/anthropic_spec.rb | 2 +- .../completions/endpoints/aws_bedrock_spec.rb | 2 +- spec/lib/completions/endpoints/gemini_spec.rb | 2 +- .../endpoints/hugging_face_spec.rb | 2 +- spec/lib/completions/endpoints/vllm_spec.rb | 2 +- spec/lib/completions/llm_spec.rb | 2 +- .../discourse_automation/llm_triage_spec.rb | 2 +- spec/lib/modules/ai_bot/bot_spec.rb | 2 +- spec/lib/modules/ai_bot/entry_point_spec.rb | 2 +- .../jobs/regular/create_ai_reply_spec.rb | 2 +- spec/lib/modules/ai_helper/assistant_spec.rb | 2 +- .../ai_helper/chat_thread_titler_spec.rb | 2 +- spec/lib/modules/ai_helper/painter_spec.rb | 2 +- .../lib/modules/automation/llm_triage_spec.rb | 2 +- .../modules/automation/report_runner_spec.rb | 4 +- .../jobs/generate_embeddings_spec.rb | 2 +- .../embeddings/semantic_search_spec.rb | 6 +-- .../embeddings/semantic_topic_query_spec.rb | 4 +- .../embeddings/strategies/truncation_spec.rb | 2 +- spec/lib/modules/toxicity/entry_point_spec.rb | 2 +- .../toxicity_classify_chat_message_spec.rb | 2 +- .../regular/toxicity_classify_post_spec.rb | 2 +- spec/lib/modules/toxicity/scan_queue_spec.rb | 6 +-- .../models/reviewable_ai_chat_message_spec.rb | 6 +-- spec/models/reviewable_ai_post_spec.rb | 2 +- spec/plugin_spec.rb | 4 +- spec/requests/ai_bot/bot_controller_spec.rb | 2 +- .../ai_helper/assistant_controller_spec.rb | 6 +-- spec/requests/topic_spec.rb | 2 +- .../ai_chat_channel_serializer_spec.rb | 2 +- .../shared/chat_message_classificator_spec.rb | 2 +- spec/shared/post_classificator_spec.rb | 2 +- spec/system/ai_bot/ai_bot_helper_spec.rb | 2 +- .../ai_helper/ai_composer_helper_spec.rb | 2 +- spec/system/ai_helper/ai_post_helper_spec.rb | 2 +- .../ai_split_topic_suggestion_spec.rb | 4 +- .../system/embeddings/semantic_search_spec.rb | 2 +- .../reviewable_ai_chat_message_spec.rb | 4 +- 43 files changed, 88 insertions(+), 66 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 23ad67df..4c42077d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,11 +1,30 @@ GEM remote: https://rubygems.org/ 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) + 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) language_server-protocol (3.17.0.3) + minitest (5.22.2) + mutex_m (0.2.0) parallel (1.24.0) - parser (3.3.0.3) + parser (3.3.0.5) ast (~> 2.4.1) racc prettier_print (1.2.1) @@ -13,33 +32,38 @@ GEM rainbow (3.1.1) regexp_parser (2.9.0) rexml (3.2.6) - rubocop (1.59.0) + rubocop (1.61.0) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.2.2.4) + parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.30.0) - parser (>= 3.2.1.0) + rubocop-ast (1.31.1) + parser (>= 3.3.0.4) rubocop-capybara (2.20.0) rubocop (~> 1.41) - rubocop-discourse (3.6.0) + rubocop-discourse (3.7.1) + activesupport (>= 6.1) rubocop (>= 1.59.0) + rubocop-capybara (>= 2.0.0) + rubocop-factory_bot (>= 2.0.0) rubocop-rspec (>= 2.25.0) rubocop-factory_bot (2.25.1) rubocop (~> 1.41) - rubocop-rspec (2.26.1) + rubocop-rspec (2.27.1) rubocop (~> 1.40) rubocop-capybara (~> 2.17) rubocop-factory_bot (~> 2.22) ruby-progressbar (1.13.0) syntax_tree (6.2.0) prettier_print (>= 1.2.0) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) unicode-display_width (2.5.0) PLATFORMS diff --git a/app/controllers/discourse_ai/admin/ai_personas_controller.rb b/app/controllers/discourse_ai/admin/ai_personas_controller.rb index 0c5b75b1..20208dd7 100644 --- a/app/controllers/discourse_ai/admin/ai_personas_controller.rb +++ b/app/controllers/discourse_ai/admin/ai_personas_controller.rb @@ -3,6 +3,8 @@ module DiscourseAi module Admin class AiPersonasController < ::Admin::AdminController + requires_plugin ::DiscourseAi::PLUGIN_NAME + before_action :find_ai_persona, only: %i[show update destroy create_user] def index diff --git a/discourse_automation/llm_report.rb b/discourse_automation/llm_report.rb index 7c6332ba..bed4e157 100644 --- a/discourse_automation/llm_report.rb +++ b/discourse_automation/llm_report.rb @@ -4,9 +4,7 @@ if defined?(DiscourseAutomation) module DiscourseAutomation::LlmReport end - DiscourseAutomation::Scriptable::LLM_REPORT = "llm_report" - - DiscourseAutomation::Scriptable.add(DiscourseAutomation::Scriptable::LLM_REPORT) do + DiscourseAutomation::Scriptable.add("llm_report") do version 1 triggerables %i[recurring] diff --git a/discourse_automation/llm_triage.rb b/discourse_automation/llm_triage.rb index a290a0b3..2ba73c08 100644 --- a/discourse_automation/llm_triage.rb +++ b/discourse_automation/llm_triage.rb @@ -1,9 +1,7 @@ # frozen_string_literal: true if defined?(DiscourseAutomation) - DiscourseAutomation::Scriptable::LLM_TRIAGE = "llm_triage" - - DiscourseAutomation::Scriptable.add(DiscourseAutomation::Scriptable::LLM_TRIAGE) do + DiscourseAutomation::Scriptable.add("llm_triage") do version 1 run_in_background @@ -17,7 +15,7 @@ if defined?(DiscourseAutomation) validator: ->(input) do if !input.include?("%%POST%%") 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, diff --git a/spec/jobs/regular/stream_post_helper_spec.rb b/spec/jobs/regular/stream_post_helper_spec.rb index b842b684..581a57f4 100644 --- a/spec/jobs/regular/stream_post_helper_spec.rb +++ b/spec/jobs/regular/stream_post_helper_spec.rb @@ -6,7 +6,7 @@ RSpec.describe Jobs::StreamPostHelper do before { SiteSetting.ai_helper_model = "fake:fake" } describe "#execute" do - fab!(:topic) { Fabricate(:topic) } + fab!(:topic) fab!(:post) do Fabricate( :post, diff --git a/spec/lib/completions/endpoints/anthropic_spec.rb b/spec/lib/completions/endpoints/anthropic_spec.rb index ccee7177..b05b79b0 100644 --- a/spec/lib/completions/endpoints/anthropic_spec.rb +++ b/spec/lib/completions/endpoints/anthropic_spec.rb @@ -56,7 +56,7 @@ end RSpec.describe DiscourseAi::Completions::Endpoints::Anthropic do subject(:endpoint) { described_class.new("claude-2", DiscourseAi::Tokenizer::AnthropicTokenizer) } - fab!(:user) { Fabricate(:user) } + fab!(:user) let(:anthropic_mock) { AnthropicMock.new(endpoint) } diff --git a/spec/lib/completions/endpoints/aws_bedrock_spec.rb b/spec/lib/completions/endpoints/aws_bedrock_spec.rb index 77fa3949..2461941b 100644 --- a/spec/lib/completions/endpoints/aws_bedrock_spec.rb +++ b/spec/lib/completions/endpoints/aws_bedrock_spec.rb @@ -75,7 +75,7 @@ end RSpec.describe DiscourseAi::Completions::Endpoints::AwsBedrock do subject(:endpoint) { described_class.new("claude-2", DiscourseAi::Tokenizer::AnthropicTokenizer) } - fab!(:user) { Fabricate(:user) } + fab!(:user) let(:bedrock_mock) { BedrockMock.new(endpoint) } diff --git a/spec/lib/completions/endpoints/gemini_spec.rb b/spec/lib/completions/endpoints/gemini_spec.rb index 65763845..8f9cb367 100644 --- a/spec/lib/completions/endpoints/gemini_spec.rb +++ b/spec/lib/completions/endpoints/gemini_spec.rb @@ -130,7 +130,7 @@ end RSpec.describe DiscourseAi::Completions::Endpoints::Gemini do subject(:endpoint) { described_class.new("gemini-pro", DiscourseAi::Tokenizer::OpenAiTokenizer) } - fab!(:user) { Fabricate(:user) } + fab!(:user) let(:bedrock_mock) { GeminiMock.new(endpoint) } diff --git a/spec/lib/completions/endpoints/hugging_face_spec.rb b/spec/lib/completions/endpoints/hugging_face_spec.rb index 6247e42f..bfdfa74e 100644 --- a/spec/lib/completions/endpoints/hugging_face_spec.rb +++ b/spec/lib/completions/endpoints/hugging_face_spec.rb @@ -65,7 +65,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::HuggingFace do before { SiteSetting.ai_hugging_face_api_url = "https://test.dev" } - fab!(:user) { Fabricate(:user) } + fab!(:user) let(:hf_mock) { HuggingFaceMock.new(endpoint) } diff --git a/spec/lib/completions/endpoints/vllm_spec.rb b/spec/lib/completions/endpoints/vllm_spec.rb index 245e816a..52d87007 100644 --- a/spec/lib/completions/endpoints/vllm_spec.rb +++ b/spec/lib/completions/endpoints/vllm_spec.rb @@ -62,7 +62,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::Vllm do ) end - fab!(:user) { Fabricate(:user) } + fab!(:user) let(:anthropic_mock) { VllmMock.new(endpoint) } diff --git a/spec/lib/completions/llm_spec.rb b/spec/lib/completions/llm_spec.rb index 10c7d8ee..4b99b4db 100644 --- a/spec/lib/completions/llm_spec.rb +++ b/spec/lib/completions/llm_spec.rb @@ -9,7 +9,7 @@ RSpec.describe DiscourseAi::Completions::Llm do ) end - fab!(:user) { Fabricate(:user) } + fab!(:user) describe ".proxy" do it "raises an exception when we can't proxy the model" do diff --git a/spec/lib/discourse_automation/llm_triage_spec.rb b/spec/lib/discourse_automation/llm_triage_spec.rb index 4aef5a57..ddb46e16 100644 --- a/spec/lib/discourse_automation/llm_triage_spec.rb +++ b/spec/lib/discourse_automation/llm_triage_spec.rb @@ -3,7 +3,7 @@ return if !defined?(DiscourseAutomation) describe DiscourseAi::Automation::LlmTriage do - fab!(:post) { Fabricate(:post) } + fab!(:post) let(:automation) { Fabricate(:automation, script: "llm_triage", enabled: true) } diff --git a/spec/lib/modules/ai_bot/bot_spec.rb b/spec/lib/modules/ai_bot/bot_spec.rb index 2f2d7520..7211b04d 100644 --- a/spec/lib/modules/ai_bot/bot_spec.rb +++ b/spec/lib/modules/ai_bot/bot_spec.rb @@ -3,7 +3,7 @@ RSpec.describe DiscourseAi::AiBot::Bot do subject(:bot) { described_class.as(bot_user) } - fab!(:admin) { Fabricate(:admin) } + fab!(:admin) before do SiteSetting.ai_bot_enabled_chat_bots = "gpt-4" diff --git a/spec/lib/modules/ai_bot/entry_point_spec.rb b/spec/lib/modules/ai_bot/entry_point_spec.rb index ed9c38ce..357758e6 100644 --- a/spec/lib/modules/ai_bot/entry_point_spec.rb +++ b/spec/lib/modules/ai_bot/entry_point_spec.rb @@ -3,7 +3,7 @@ RSpec.describe DiscourseAi::AiBot::EntryPoint do describe "#inject_into" do describe "subscribes to the post_created event" do - fab!(:admin) { Fabricate(:admin) } + fab!(:admin) let(:gpt_bot) { User.find(described_class::GPT4_ID) } fab!(:bot_allowed_group) { Fabricate(:group) } diff --git a/spec/lib/modules/ai_bot/jobs/regular/create_ai_reply_spec.rb b/spec/lib/modules/ai_bot/jobs/regular/create_ai_reply_spec.rb index ce78af12..8a008dcd 100644 --- a/spec/lib/modules/ai_bot/jobs/regular/create_ai_reply_spec.rb +++ b/spec/lib/modules/ai_bot/jobs/regular/create_ai_reply_spec.rb @@ -4,7 +4,7 @@ RSpec.describe Jobs::CreateAiReply do before { SiteSetting.ai_bot_enabled = true } describe "#execute" do - fab!(:topic) { Fabricate(:topic) } + fab!(:topic) fab!(:post) { Fabricate(:post, topic: topic) } let(:expected_response) do diff --git a/spec/lib/modules/ai_helper/assistant_spec.rb b/spec/lib/modules/ai_helper/assistant_spec.rb index bd55194c..9c582ec0 100644 --- a/spec/lib/modules/ai_helper/assistant_spec.rb +++ b/spec/lib/modules/ai_helper/assistant_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe DiscourseAi::AiHelper::Assistant do - fab!(:user) { Fabricate(:user) } + fab!(:user) let(:prompt) { CompletionPrompt.find_by(id: mode) } before { SiteSetting.ai_helper_model = "fake:fake" } diff --git a/spec/lib/modules/ai_helper/chat_thread_titler_spec.rb b/spec/lib/modules/ai_helper/chat_thread_titler_spec.rb index 3ff9a4a3..c4be774a 100644 --- a/spec/lib/modules/ai_helper/chat_thread_titler_spec.rb +++ b/spec/lib/modules/ai_helper/chat_thread_titler_spec.rb @@ -7,7 +7,7 @@ RSpec.describe DiscourseAi::AiHelper::ChatThreadTitler do fab!(:thread) { Fabricate(:chat_thread) } fab!(:chat_message) { Fabricate(:chat_message, thread: thread) } - fab!(:user) { Fabricate(:user) } + fab!(:user) describe "#cleanup" do it "picks the first when there are multiple" do diff --git a/spec/lib/modules/ai_helper/painter_spec.rb b/spec/lib/modules/ai_helper/painter_spec.rb index 91126732..9daa550d 100644 --- a/spec/lib/modules/ai_helper/painter_spec.rb +++ b/spec/lib/modules/ai_helper/painter_spec.rb @@ -3,7 +3,7 @@ RSpec.describe DiscourseAi::AiHelper::Painter do subject(:painter) { described_class.new } - fab!(:user) { Fabricate(:user) } + fab!(:user) before do SiteSetting.ai_helper_model = "fake:fake" diff --git a/spec/lib/modules/automation/llm_triage_spec.rb b/spec/lib/modules/automation/llm_triage_spec.rb index 69f2c706..1f981ae2 100644 --- a/spec/lib/modules/automation/llm_triage_spec.rb +++ b/spec/lib/modules/automation/llm_triage_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true describe DiscourseAi::Automation::LlmTriage do - fab!(:post) { Fabricate(:post) } + fab!(:post) def triage(**args) DiscourseAi::Automation::LlmTriage.handle(**args) diff --git a/spec/lib/modules/automation/report_runner_spec.rb b/spec/lib/modules/automation/report_runner_spec.rb index 8b80edc4..1a2b1df9 100644 --- a/spec/lib/modules/automation/report_runner_spec.rb +++ b/spec/lib/modules/automation/report_runner_spec.rb @@ -13,13 +13,13 @@ module DiscourseAi fab!(:secure_topic) { Fabricate(:topic, category: secure_category) } 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!(:post_in_category) do Fabricate(:post, raw: "I am in a category", topic: topic_in_category) end - fab!(:tag) { Fabricate(:tag) } + fab!(: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) } diff --git a/spec/lib/modules/embeddings/jobs/generate_embeddings_spec.rb b/spec/lib/modules/embeddings/jobs/generate_embeddings_spec.rb index 38f6fb0d..0013f22b 100644 --- a/spec/lib/modules/embeddings/jobs/generate_embeddings_spec.rb +++ b/spec/lib/modules/embeddings/jobs/generate_embeddings_spec.rb @@ -9,7 +9,7 @@ RSpec.describe Jobs::GenerateEmbeddings do SiteSetting.ai_embeddings_enabled = true end - fab!(:topic) { Fabricate(:topic) } + fab!(:topic) fab!(:post) { Fabricate(:post, post_number: 1, topic: topic) } let(:truncation) { DiscourseAi::Embeddings::Strategies::Truncation.new } diff --git a/spec/lib/modules/embeddings/semantic_search_spec.rb b/spec/lib/modules/embeddings/semantic_search_spec.rb index 07df3821..4ec264c9 100644 --- a/spec/lib/modules/embeddings/semantic_search_spec.rb +++ b/spec/lib/modules/embeddings/semantic_search_spec.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true RSpec.describe DiscourseAi::Embeddings::SemanticSearch do - fab!(:post) { Fabricate(:post) } - fab!(:user) { Fabricate(:user) } + fab!(:post) + fab!(:user) let(:query) { "test_query" } let(:subject) { described_class.new(Guardian.new(user)) } @@ -104,7 +104,7 @@ RSpec.describe DiscourseAi::Embeddings::SemanticSearch do end context "when the post belongs to a secured category" do - fab!(:group) { Fabricate(:group) } + fab!(:group) fab!(:private_category) { Fabricate(:private_category, group: group) } before do diff --git a/spec/lib/modules/embeddings/semantic_topic_query_spec.rb b/spec/lib/modules/embeddings/semantic_topic_query_spec.rb index 7b7bb9e7..325df307 100644 --- a/spec/lib/modules/embeddings/semantic_topic_query_spec.rb +++ b/spec/lib/modules/embeddings/semantic_topic_query_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true describe DiscourseAi::Embeddings::EntryPoint do - fab!(:user) { Fabricate(:user) } + fab!(:user) describe "SemanticTopicQuery extension" do describe "#list_semantic_related_topics" do @@ -39,7 +39,7 @@ describe DiscourseAi::Embeddings::EntryPoint do end 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!(:secured_category_topic) { Fabricate(:topic, category: category) } diff --git a/spec/lib/modules/embeddings/strategies/truncation_spec.rb b/spec/lib/modules/embeddings/strategies/truncation_spec.rb index 850db322..b0498023 100644 --- a/spec/lib/modules/embeddings/strategies/truncation_spec.rb +++ b/spec/lib/modules/embeddings/strategies/truncation_spec.rb @@ -7,7 +7,7 @@ RSpec.describe DiscourseAi::Embeddings::Strategies::Truncation do context "when using vector from OpenAI" do before { SiteSetting.max_post_length = 100_000 } - fab!(:topic) { Fabricate(:topic) } + fab!(:topic) fab!(:post) do Fabricate(:post, topic: topic, raw: "Baby, bird, bird, bird\nBird is the word\n" * 500) end diff --git a/spec/lib/modules/toxicity/entry_point_spec.rb b/spec/lib/modules/toxicity/entry_point_spec.rb index f20c6a5b..60ce6f49 100644 --- a/spec/lib/modules/toxicity/entry_point_spec.rb +++ b/spec/lib/modules/toxicity/entry_point_spec.rb @@ -53,7 +53,7 @@ describe DiscourseAi::Toxicity::EntryPoint do context "when editing a chat message" do # This fabricator trigger events because it uses the UpdateMessage service. # Using let makes the test fail. - fab!(:chat_message) { Fabricate(:chat_message) } + fab!(:chat_message) let(:updater) do Chat::UpdateMessage.call( guardian: Guardian.new(chat_message.user), diff --git a/spec/lib/modules/toxicity/jobs/regular/toxicity_classify_chat_message_spec.rb b/spec/lib/modules/toxicity/jobs/regular/toxicity_classify_chat_message_spec.rb index dd16c889..78c50504 100644 --- a/spec/lib/modules/toxicity/jobs/regular/toxicity_classify_chat_message_spec.rb +++ b/spec/lib/modules/toxicity/jobs/regular/toxicity_classify_chat_message_spec.rb @@ -9,7 +9,7 @@ describe Jobs::ToxicityClassifyChatMessage do SiteSetting.ai_toxicity_flag_automatically = true end - fab!(:chat_message) { Fabricate(:chat_message) } + fab!(:chat_message) describe "scenarios where we return early without doing anything" do it "does nothing when ai_toxicity_enabled is disabled" do diff --git a/spec/lib/modules/toxicity/jobs/regular/toxicity_classify_post_spec.rb b/spec/lib/modules/toxicity/jobs/regular/toxicity_classify_post_spec.rb index e129af51..9f11ad2a 100644 --- a/spec/lib/modules/toxicity/jobs/regular/toxicity_classify_post_spec.rb +++ b/spec/lib/modules/toxicity/jobs/regular/toxicity_classify_post_spec.rb @@ -10,7 +10,7 @@ describe Jobs::ToxicityClassifyPost do SiteSetting.ai_toxicity_flag_automatically = true end - fab!(:post) { Fabricate(:post) } + fab!(:post) describe "scenarios where we return early without doing anything" do it "does nothing when ai_toxicity_enabled is disabled" do diff --git a/spec/lib/modules/toxicity/scan_queue_spec.rb b/spec/lib/modules/toxicity/scan_queue_spec.rb index 86c36e85..5fc82ad2 100644 --- a/spec/lib/modules/toxicity/scan_queue_spec.rb +++ b/spec/lib/modules/toxicity/scan_queue_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true describe DiscourseAi::Toxicity::ScanQueue do - fab!(:group) { Fabricate(:group) } + fab!(:group) before do SiteSetting.ai_toxicity_enabled = true @@ -9,7 +9,7 @@ describe DiscourseAi::Toxicity::ScanQueue do end describe "#enqueue_post" do - fab!(:post) { Fabricate(:post) } + fab!(:post) it "queues a job" do expect { described_class.enqueue_post(post) }.to change( @@ -38,7 +38,7 @@ describe DiscourseAi::Toxicity::ScanQueue do end describe "#enqueue_chat_message" do - fab!(:chat_message) { Fabricate(:chat_message) } + fab!(:chat_message) it "queues a job" do expect { described_class.enqueue_chat_message(chat_message) }.to change( diff --git a/spec/models/reviewable_ai_chat_message_spec.rb b/spec/models/reviewable_ai_chat_message_spec.rb index 6ddb3f5c..6069587e 100644 --- a/spec/models/reviewable_ai_chat_message_spec.rb +++ b/spec/models/reviewable_ai_chat_message_spec.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true RSpec.describe ReviewableAiChatMessage, type: :model do - fab!(:moderator) { Fabricate(:moderator) } - fab!(:user) { Fabricate(:user) } - fab!(:chat_channel) { Fabricate(:chat_channel) } + fab!(:moderator) + fab!(:user) + fab!(:chat_channel) fab!(:chat_message) { Fabricate(:chat_message, chat_channel: chat_channel, user: user) } fab!(:reviewable) { described_class.needs_review!(target: chat_message, created_by: moderator) } diff --git a/spec/models/reviewable_ai_post_spec.rb b/spec/models/reviewable_ai_post_spec.rb index 060ec0ce..4e2d04e8 100644 --- a/spec/models/reviewable_ai_post_spec.rb +++ b/spec/models/reviewable_ai_post_spec.rb @@ -121,7 +121,7 @@ describe ReviewableAiPost do let(:reviewable) do described_class.needs_review!(target: target, created_by: Discourse.system_user) end - fab!(:admin) { Fabricate(:admin) } + fab!(:admin) before do reviewable.add_score( diff --git a/spec/plugin_spec.rb b/spec/plugin_spec.rb index f52d9cfa..37dc7d16 100644 --- a/spec/plugin_spec.rb +++ b/spec/plugin_spec.rb @@ -6,8 +6,8 @@ describe Plugin::Instance do before { SiteSetting.discourse_ai_enabled = true } describe "on reviewable_transitioned_to event" do - fab!(:post) { Fabricate(:post) } - fab!(:admin) { Fabricate(:admin) } + fab!(:post) + fab!(:admin) it "adjusts model accuracy" do ToxicityInferenceStubs.stub_post_classification(post, toxic: true) diff --git a/spec/requests/ai_bot/bot_controller_spec.rb b/spec/requests/ai_bot/bot_controller_spec.rb index 32722e46..efd85a6f 100644 --- a/spec/requests/ai_bot/bot_controller_spec.rb +++ b/spec/requests/ai_bot/bot_controller_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe DiscourseAi::AiBot::BotController do - fab!(:user) { Fabricate(:user) } + fab!(:user) before { sign_in(user) } describe "#stop_streaming_response" do diff --git a/spec/requests/ai_helper/assistant_controller_spec.rb b/spec/requests/ai_helper/assistant_controller_spec.rb index 005fc501..833fed17 100644 --- a/spec/requests/ai_helper/assistant_controller_spec.rb +++ b/spec/requests/ai_helper/assistant_controller_spec.rb @@ -32,7 +32,7 @@ RSpec.describe DiscourseAi::AiHelper::AssistantController do end context "when logged in as an allowed user" do - fab!(:user) { Fabricate(:user) } + fab!(:user) before do sign_in(user) @@ -109,7 +109,7 @@ RSpec.describe DiscourseAi::AiHelper::AssistantController do end describe "#caption_image" do - fab!(:upload) { Fabricate(:upload) } + fab!(:upload) let(:image_url) { "#{Discourse.base_url}#{upload.url}" } let(:caption) { "A picture of a cat sitting on a table" } let(:caption_with_attrs) do @@ -161,7 +161,7 @@ RSpec.describe DiscourseAi::AiHelper::AssistantController do end context "for secure uploads" do - fab!(:group) { Fabricate(:group) } + fab!(:group) fab!(:private_category) { Fabricate(:private_category, group: group) } fab!(:post_in_secure_context) do Fabricate(:post, topic: Fabricate(:topic, category: private_category)) diff --git a/spec/requests/topic_spec.rb b/spec/requests/topic_spec.rb index 603dabd8..b3cd8851 100644 --- a/spec/requests/topic_spec.rb +++ b/spec/requests/topic_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true describe ::TopicsController do - fab!(:topic) { Fabricate(:topic) } + fab!(:topic) fab!(:topic1) { Fabricate(:topic) } fab!(:topic2) { Fabricate(:topic) } fab!(:topic3) { Fabricate(:topic) } diff --git a/spec/serializers/ai_chat_channel_serializer_spec.rb b/spec/serializers/ai_chat_channel_serializer_spec.rb index 0ef48983..9680538f 100644 --- a/spec/serializers/ai_chat_channel_serializer_spec.rb +++ b/spec/serializers/ai_chat_channel_serializer_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe AiChatChannelSerializer do - fab!(:admin) { Fabricate(:admin) } + fab!(:admin) describe "#title" do context "when the channel is a DM" do diff --git a/spec/shared/chat_message_classificator_spec.rb b/spec/shared/chat_message_classificator_spec.rb index 120e92c4..763473f6 100644 --- a/spec/shared/chat_message_classificator_spec.rb +++ b/spec/shared/chat_message_classificator_spec.rb @@ -3,7 +3,7 @@ require_relative "../support/toxicity_inference_stubs" describe DiscourseAi::ChatMessageClassificator do - fab!(:chat_message) { Fabricate(:chat_message) } + fab!(:chat_message) let(:model) { DiscourseAi::Toxicity::ToxicityClassification.new } let(:classification) { described_class.new(model) } diff --git a/spec/shared/post_classificator_spec.rb b/spec/shared/post_classificator_spec.rb index b56bd0d3..575ed256 100644 --- a/spec/shared/post_classificator_spec.rb +++ b/spec/shared/post_classificator_spec.rb @@ -3,7 +3,7 @@ require_relative "../support/toxicity_inference_stubs" describe DiscourseAi::PostClassificator do - fab!(:post) { Fabricate(:post) } + fab!(:post) let(:model) { DiscourseAi::Toxicity::ToxicityClassification.new } let(:classification) { described_class.new(model) } diff --git a/spec/system/ai_bot/ai_bot_helper_spec.rb b/spec/system/ai_bot/ai_bot_helper_spec.rb index 359899ed..630fa56d 100644 --- a/spec/system/ai_bot/ai_bot_helper_spec.rb +++ b/spec/system/ai_bot/ai_bot_helper_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true 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]) } before do diff --git a/spec/system/ai_helper/ai_composer_helper_spec.rb b/spec/system/ai_helper/ai_composer_helper_spec.rb index 4a727d00..50771478 100644 --- a/spec/system/ai_helper/ai_composer_helper_spec.rb +++ b/spec/system/ai_helper/ai_composer_helper_spec.rb @@ -17,7 +17,7 @@ RSpec.describe "AI Composer helper", type: :system, js: true do let(:ai_helper_context_menu) { PageObjects::Components::AIHelperContextMenu.new } let(:diff_modal) { PageObjects::Modals::DiffModal.new } let(:ai_suggestion_dropdown) { PageObjects::Components::AISuggestionDropdown.new } - fab!(:category) { Fabricate(:category) } + fab!(:category) fab!(:category_2) { Fabricate(:category) } fab!(:video) { Fabricate(:tag) } fab!(:music) { Fabricate(:tag) } diff --git a/spec/system/ai_helper/ai_post_helper_spec.rb b/spec/system/ai_helper/ai_post_helper_spec.rb index 628bf23a..771ac986 100644 --- a/spec/system/ai_helper/ai_post_helper_spec.rb +++ b/spec/system/ai_helper/ai_post_helper_spec.rb @@ -3,7 +3,7 @@ RSpec.describe "AI Post helper", type: :system, js: true do fab!(:user) { Fabricate(:admin) } fab!(:non_member_group) { Fabricate(:group) } - fab!(:topic) { Fabricate(:topic) } + fab!(:topic) fab!(:post) do Fabricate( :post, diff --git a/spec/system/ai_helper/ai_split_topic_suggestion_spec.rb b/spec/system/ai_helper/ai_split_topic_suggestion_spec.rb index b280a16a..a95637c5 100644 --- a/spec/system/ai_helper/ai_split_topic_suggestion_spec.rb +++ b/spec/system/ai_helper/ai_split_topic_suggestion_spec.rb @@ -3,8 +3,8 @@ RSpec.describe "AI Post helper", type: :system, js: true do fab!(:user) { Fabricate(:admin) } fab!(:non_member_group) { Fabricate(:group) } - fab!(:topic) { Fabricate(:topic) } - fab!(:category) { Fabricate(:category) } + fab!(:topic) + fab!(:category) fab!(:category_2) { Fabricate(:category) } fab!(:post) do Fabricate( diff --git a/spec/system/embeddings/semantic_search_spec.rb b/spec/system/embeddings/semantic_search_spec.rb index af5b5708..fcf124c3 100644 --- a/spec/system/embeddings/semantic_search_spec.rb +++ b/spec/system/embeddings/semantic_search_spec.rb @@ -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" } 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") } before do diff --git a/spec/system/toxicity/reviewable_ai_chat_message_spec.rb b/spec/system/toxicity/reviewable_ai_chat_message_spec.rb index 99c4ba15..40add4fe 100644 --- a/spec/system/toxicity/reviewable_ai_chat_message_spec.rb +++ b/spec/system/toxicity/reviewable_ai_chat_message_spec.rb @@ -3,8 +3,8 @@ require_relative "../../support/toxicity_inference_stubs" RSpec.describe "Toxicity-flagged chat messages", type: :system, js: true do - fab!(:chat_message) { Fabricate(:chat_message) } - fab!(:admin) { Fabricate(:admin) } + fab!(:chat_message) + fab!(:admin) before do sign_in(admin)