discourse-ai/spec/plugin_helper.rb
Bianca Nenciu c5b323fc07
DEV: Fix mismatched column types in tests (#826)
The primary key is usually a bigint column, but the foreign key columns
usually are of integer type. This can lead to issues when joining these
columns due to mismatched types and different value ranges.

In a recent core change, all bigint sequences will start at a very high
value in the test environment to surface this type of errors. The same
change also added a temporary API that changes the column type to bigint
in order to allow for the tests to run.

The plugin API is only temporary and it is important for these plugins
to migrate their columns to bigint to avoid issues in the future.
2024-10-10 18:39:36 +03:00

28 lines
851 B
Ruby

# frozen_string_literal: true
module DiscourseAi::ChatBotHelper
def toggle_enabled_bots(bots: [])
LlmModel.update_all(enabled_chat_bot: false)
bots.each { |b| b.update!(enabled_chat_bot: true) }
DiscourseAi::AiBot::SiteSettingsExtension.enable_or_disable_ai_bots
end
def assign_fake_provider_to(setting_name)
Fabricate(:fake_model).tap do |fake_llm|
SiteSetting.public_send("#{setting_name}=", "custom:#{fake_llm.id}")
end
end
end
RSpec.configure do |config|
config.include DiscourseAi::ChatBotHelper
config.before(:suite) do
if defined?(migrate_column_to_bigint)
migrate_column_to_bigint(RagDocumentFragment, :target_id)
migrate_column_to_bigint("ai_document_fragment_embeddings", "rag_document_fragment_id")
migrate_column_to_bigint(ClassificationResult, :target_id)
end
end
end