discourse/plugins/discourse-ai/spec/plugin_helper.rb
Jarek Radosz a54e3208cb
DEV: Hand-pick Rails/WhereNot autofixes (#35117)
We can't enable `Rails/WhereNot` lint/autofix, because it would break
code that uses mini_sql instead of AR (which rubocop, and tbh also we,
can't easily differentiate)

Those are safe because they either:
* are executed in AR model scope definitions
* are clearly chained starting from a AR model
* are less-clearly chained, but still can be traced to a AR model/scope

---------

Co-authored-by: Loïc Guitaut <loic@discourse.org>
2025-10-03 13:29:22 +02:00

26 lines
828 B
Ruby
Vendored

# frozen_string_literal: true
module DiscourseAi::ChatBotHelper
def toggle_enabled_bots(bots: [])
models = LlmModel.all
models = models.where.not(id: bots.map(&:id)) if bots.present?
models.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}=", "#{fake_llm.id}")
end
end
def assign_persona_to(setting_name, allowed_group_ids)
Fabricate(:ai_persona, allowed_group_ids: allowed_group_ids).tap do |p|
SiteSetting.public_send("#{setting_name}=", p.id)
end
end
end
RSpec.configure { |config| config.include DiscourseAi::ChatBotHelper }