Skip to content

A platform for community discussion. Free, open, simple.

DEV: Fix deprecations in plugins specs and silence output (#39257)

Jarek Radoszbd13d858b0cf
diff --git a/plugins/automation/app/jobs/scheduled/discourse_automation/tracker.rb b/plugins/automation/app/jobs/scheduled/discourse_automation/tracker.rb
index e8c47f47daa..0ad2f54aec3 100644
--- a/plugins/automation/app/jobs/scheduled/discourse_automation/tracker.rb
+++ b/plugins/automation/app/jobs/scheduled/discourse_automation/tracker.rb
@@ -67,7 +67,7 @@ module Jobs
pending_automation.automation.trigger!(
"kind" => pending_automation.automation.trigger,
- "execute_at" => pending_automation.execute_at,
+ "execute_at" => pending_automation.execute_at.iso8601,
)
pending_automation.destroy!
diff --git a/plugins/chat/spec/lib/chat/channel_archive_service_spec.rb b/plugins/chat/spec/lib/chat/channel_archive_service_spec.rb
index 40fed129255..9378935c54a 100644
--- a/plugins/chat/spec/lib/chat/channel_archive_service_spec.rb
+++ b/plugins/chat/spec/lib/chat/channel_archive_service_spec.rb
@@ -237,6 +237,7 @@ describe Chat::ChannelArchiveService do
create_messages(3) && start_archive
@channel_archive.update!(destination_topic_title: "Wow this is the new title :tada: :joy:")
+ Discourse.expects(:warn_exception).once
described_class.new(@channel_archive).execute
expect(@channel_archive.reload.complete?).to eq(false)
expect(@channel_archive.reload.failed?).to eq(true)
@@ -420,6 +421,7 @@ describe Chat::ChannelArchiveService do
.stubs(:create_post)
.raises(FakeArchiveError.new("this is a test error"))
+ Discourse.expects(:warn_exception).once
stub_const(Chat::ChannelArchiveService, "ARCHIVED_MESSAGES_PER_POST", 5) do
expect { described_class.new(@channel_archive).execute }.to raise_error(FakeArchiveError)
end
diff --git a/plugins/chat/spec/requests/chat_controller_spec.rb b/plugins/chat/spec/requests/chat_controller_spec.rb
index 58c67622df3..6342f9e730d 100644
--- a/plugins/chat/spec/requests/chat_controller_spec.rb
+++ b/plugins/chat/spec/requests/chat_controller_spec.rb
@@ -350,7 +350,7 @@ RSpec.describe Chat::ChatController do
let(:message3) { Fabricate(:chat_message, user: user, chat_channel: channel, message: "aw :(") }
it "returns a 403 if the user can't chat" do
- SiteSetting.chat_allowed_groups = nil
+ SiteSetting.chat_allowed_groups = ""
sign_in(user)
post "/chat/#{channel.id}/quote.json",
params: {
diff --git a/plugins/chat/spec/requests/direct_messages_controller_spec.rb b/plugins/chat/spec/requests/direct_messages_controller_spec.rb
index ab2f2be4238..961718f89d4 100644
--- a/plugins/chat/spec/requests/direct_messages_controller_spec.rb
+++ b/plugins/chat/spec/requests/direct_messages_controller_spec.rb
@@ -22,7 +22,7 @@ RSpec.describe Chat::DirectMessagesController do
describe "#index" do
context "when user is not allowed to chat" do
- before { SiteSetting.chat_allowed_groups = nil }
+ before { SiteSetting.chat_allowed_groups = "" }
it "returns a forbidden error" do
get "/chat/direct_messages.json", params: { usernames: user1.username }
diff --git a/plugins/discourse-affiliate/spec/db/migrate/20250722101702_enable_affiliate_if_already_installed_spec.rb b/plugins/discourse-affiliate/spec/db/migrate/20250722101702_enable_affiliate_if_already_installed_spec.rb
index 3db8e67048a..fffe45968e0 100644
--- a/plugins/discourse-affiliate/spec/db/migrate/20250722101702_enable_affiliate_if_already_installed_spec.rb
+++ b/plugins/discourse-affiliate/spec/db/migrate/20250722101702_enable_affiliate_if_already_installed_spec.rb
@@ -5,6 +5,8 @@ require_relative "../../../db/migrate/20250722101702_enable_affiliate_if_already
RSpec.describe EnableAffiliateIfAlreadyInstalled do
let(:connection) { ActiveRecord::Base.connection }
+ around { |example| ActiveRecord::Migration.suppress_messages { example.run } }
+
before do
@provider = SiteSetting.provider
SiteSetting.provider = SiteSettings::DbProvider.new(SiteSetting)
diff --git a/plugins/discourse-ai/lib/agents/artifact_update_strategies/diff.rb b/plugins/discourse-ai/lib/agents/artifact_update_strategies/diff.rb
index 430b99e5c8c..d7f9b5d25ce 100644
--- a/plugins/discourse-ai/lib/agents/artifact_update_strategies/diff.rb
+++ b/plugins/discourse-ai/lib/agents/artifact_update_strategies/diff.rb
@@ -72,7 +72,7 @@ module DiscourseAi
@failed_searches << { section: section, search: block[:search] }
# TODO, we may need to inform caller here, LLM made a mistake which it
# should correct
- puts "Failed to find search: #{block[:search]}"
+ Rails.logger.warn("Failed to find search: #{block[:search]}")
end
end
updated_content[section == :javascript ? :js : section] = content
diff --git a/plugins/discourse-ai/lib/ai_bot/playground.rb b/plugins/discourse-ai/lib/ai_bot/playground.rb
index 5a39b8ce0ba..b81ed34bd1f 100644
--- a/plugins/discourse-ai/lib/ai_bot/playground.rb
+++ b/plugins/discourse-ai/lib/ai_bot/playground.rb
@@ -215,12 +215,7 @@ module DiscourseAi
feature_context: feature_context,
)
rescue => e
- if Rails.env.test?
- p e
- puts e.backtrace[0..10]
- else
- raise e
- end
+ raise e
end
def initialize(bot)
diff --git a/plugins/discourse-ai/spec/db/migrate/20241031041242_migrate_sentiment_classification_result_format_spec.rb b/plugins/discourse-ai/spec/db/migrate/20241031041242_migrate_sentiment_classification_result_format_spec.rb
index 1244fa268df..9cf6051b8fc 100644
--- a/plugins/discourse-ai/spec/db/migrate/20241031041242_migrate_sentiment_classification_result_format_spec.rb
+++ b/plugins/discourse-ai/spec/db/migrate/20241031041242_migrate_sentiment_classification_result_format_spec.rb
@@ -7,6 +7,8 @@ require Rails.root.join(
RSpec.describe MigrateSentimentClassificationResultFormat do
let(:connection) { ActiveRecord::Base.connection }
+ around { |example| ActiveRecord::Migration.suppress_messages { example.run } }
+
before do
enable_current_plugin
connection.execute(<<~SQL)
diff --git a/plugins/discourse-ai/spec/db/migrate/20250125162658_fix_broken_open_ai_embeddings_config_spec.rb b/plugins/discourse-ai/spec/db/migrate/20250125162658_fix_broken_open_ai_embeddings_config_spec.rb
index e3203f477e2..29dc80a8f00 100644
--- a/plugins/discourse-ai/spec/db/migrate/20250125162658_fix_broken_open_ai_embeddings_config_spec.rb
+++ b/plugins/discourse-ai/spec/db/migrate/20250125162658_fix_broken_open_ai_embeddings_config_spec.rb
@@ -22,6 +22,8 @@ RSpec.describe FixBrokenOpenAiEmbeddingsConfig do
).first
end
+ around { |example| ActiveRecord::Migration.suppress_messages { example.run } }
+
before { enable_current_plugin }
describe "#up" do
diff --git a/plugins/discourse-ai/spec/db/migrate/20250127145305_clean_unused_embedding_search_indexes_spec.rb b/plugins/discourse-ai/spec/db/migrate/20250127145305_clean_unused_embedding_search_indexes_spec.rb
index c2e657ba327..76c32801bed 100644
--- a/plugins/discourse-ai/spec/db/migrate/20250127145305_clean_unused_embedding_search_indexes_spec.rb
+++ b/plugins/discourse-ai/spec/db/migrate/20250127145305_clean_unused_embedding_search_indexes_spec.rb
@@ -9,6 +9,8 @@ RSpec.describe CleanUnusedEmbeddingSearchIndexes do
let(:connection) { ActiveRecord::Base.connection }
+ around { |example| ActiveRecord::Migration.suppress_messages { example.run } }
+
before { enable_current_plugin }
describe "#up" do
diff --git a/plugins/discourse-ai/spec/db/migrate/20260331024139_split_translation_public_content_setting_spec.rb b/plugins/discourse-ai/spec/db/migrate/20260331024139_split_translation_public_content_setting_spec.rb
index ff995759b7d..0bedfb289b7 100644
--- a/plugins/discourse-ai/spec/db/migrate/20260331024139_split_translation_public_content_setting_spec.rb
+++ b/plugins/discourse-ai/spec/db/migrate/20260331024139_split_translation_public_content_setting_spec.rb
@@ -27,6 +27,8 @@ RSpec.describe SplitTranslationPublicContentSetting do
fab!(:public_category) { Fabricate(:category, read_restricted: false) }
fab!(:private_category) { Fabricate(:category, read_restricted: true) }
+ around { |example| ActiveRecord::Migration.suppress_messages { example.run } }
+
before { enable_current_plugin }
after do
diff --git a/plugins/discourse-ai/spec/jobs/scheduled/generate_concepts_from_popular_items_spec.rb b/plugins/discourse-ai/spec/jobs/scheduled/generate_concepts_from_popular_items_spec.rb
index 1734c171c73..e9ddc8ce097 100644
--- a/plugins/discourse-ai/spec/jobs/scheduled/generate_concepts_from_popular_items_spec.rb
+++ b/plugins/discourse-ai/spec/jobs/scheduled/generate_concepts_from_popular_items_spec.rb
@@ -205,6 +205,7 @@ RSpec.describe Jobs::GenerateConceptsFromPopularItems do
end
it "handles nil site setting values gracefully" do
+ Discourse.expects(:deprecate).times(6)
SiteSetting.inferred_concepts_daily_topics_limit = nil
SiteSetting.inferred_concepts_daily_posts_limit = nil
SiteSetting.inferred_concepts_min_posts = nil
diff --git a/plugins/discourse-ai/spec/lib/agents/tools/setting_context_spec.rb b/plugins/discourse-ai/spec/lib/agents/tools/setting_context_spec.rb
index 60eebe80d79..2bbaa4a66e3 100644
--- a/plugins/discourse-ai/spec/lib/agents/tools/setting_context_spec.rb
+++ b/plugins/discourse-ai/spec/lib/agents/tools/setting_context_spec.rb
@@ -4,7 +4,7 @@ def has_rg?
if defined?(@has_rg)
@has_rg
else
- @has_rg |= system("which rg")
+ @has_rg |= system("which rg", out: File::NULL)
end
end
diff --git a/plugins/discourse-ai/spec/tasks/scan_spec.rb b/plugins/discourse-ai/spec/tasks/scan_spec.rb
index a6876419f9e..554632f4793 100644
--- a/plugins/discourse-ai/spec/tasks/scan_spec.rb
+++ b/plugins/discourse-ai/spec/tasks/scan_spec.rb
@@ -15,7 +15,7 @@ RSpec.describe "ai:spam rake tasks" do
end_date = Time.now.to_s
expect_enqueued_with(job: :ai_spam_scan, args: { post_id: post2.id }) do
- Rake::Task["ai:spam:scan_posts"].invoke(start_date, end_date)
+ capture_stdout { Rake::Task["ai:spam:scan_posts"].invoke(start_date, end_date) }
end
expect_not_enqueued_with(job: :ai_spam_scan, args: { post_id: post1.id })
@@ -30,7 +30,7 @@ RSpec.describe "ai:spam rake tasks" do
end_date = Time.now.to_s
expect_enqueued_with(job: :ai_spam_scan, args: { post_id: topic2.first_post.id }) do
- Rake::Task["ai:spam:scan_topics"].invoke(start_date, end_date)
+ capture_stdout { Rake::Task["ai:spam:scan_topics"].invoke(start_date, end_date) }
end
expect_not_enqueued_with(job: :ai_spam_scan, args: { post_id: topic1.first_post.id })
diff --git a/plugins/discourse-assign/lib/pending_assigns_reminder.rb b/plugins/discourse-assign/lib/pending_assigns_reminder.rb
index 49db18c7860..fb65e0a7c70 100644
--- a/plugins/discourse-assign/lib/pending_assigns_reminder.rb
+++ b/plugins/discourse-assign/lib/pending_assigns_reminder.rb
@@ -52,7 +52,13 @@ class PendingAssignsReminder
.joins(topic: :_custom_fields)
.where(topic_custom_fields: { name: CUSTOM_FIELD_NAME })
- posts.find_each { |post| PostDestroyer.new(Discourse.system_user, post).destroy }
+ posts.find_each do |post|
+ PostDestroyer.new(
+ Discourse.system_user,
+ post,
+ context: "cleaning up pending assigns reminder",
+ ).destroy
+ end
end
def visible_topics(user)
diff --git a/plugins/discourse-assign/lib/random_assign_utils.rb b/plugins/discourse-assign/lib/random_assign_utils.rb
index 470f96af846..b53c1b99fd1 100644
--- a/plugins/discourse-assign/lib/random_assign_utils.rb
+++ b/plugins/discourse-assign/lib/random_assign_utils.rb
@@ -107,7 +107,7 @@ class RandomAssignUtils
.assign(assigned_user, allow_self_reassign: true)
.then do |result|
next if result[:success]
- PostDestroyer.new(Discourse.system_user, post).destroy
+ PostDestroyer.new(Discourse.system_user, post, context: "random assign rollback").destroy
no_one!
end
end
diff --git a/plugins/discourse-calendar/app/models/discourse_post_event/event.rb b/plugins/discourse-calendar/app/models/discourse_post_event/event.rb
index 0a59bbc7899..bf4ade08fa7 100644
--- a/plugins/discourse-calendar/app/models/discourse_post_event/event.rb
+++ b/plugins/discourse-calendar/app/models/discourse_post_event/event.rb
@@ -107,7 +107,11 @@ module DiscoursePostEvent
end
return if date.blank?
- Jobs.enqueue(:discourse_post_event_bump_topic, topic_id: self.post.topic_id, date: date)
+ Jobs.enqueue(
+ :discourse_post_event_bump_topic,
+ topic_id: self.post.topic_id,
+ date: date.iso8601,
+ )
end
def validate_reminder_unit(input)
diff --git a/plugins/discourse-data-explorer/spec/tasks/data_explorer_spec.rb b/plugins/discourse-data-explorer/spec/tasks/data_explorer_spec.rb
index 4bb8c7d558e..27be6319aef 100644
--- a/plugins/discourse-data-explorer/spec/tasks/data_explorer_spec.rb
+++ b/plugins/discourse-data-explorer/spec/tasks/data_explorer_spec.rb
@@ -3,7 +3,7 @@
describe "Data Explorer rake tasks" do
before do
Rake::Task.clear
- Discourse::Application.load_tasks
+ silence_warnings { Discourse::Application.load_tasks }
end
def make_query(sql, opts = {}, group_ids = [])
diff --git a/plugins/discourse-data-explorer/spec/tasks/fix_query_ids_spec.rb b/plugins/discourse-data-explorer/spec/tasks/fix_query_ids_spec.rb
index de7f74d98b2..8c6697d719b 100644
--- a/plugins/discourse-data-explorer/spec/tasks/fix_query_ids_spec.rb
+++ b/plugins/discourse-data-explorer/spec/tasks/fix_query_ids_spec.rb
@@ -3,7 +3,7 @@
describe "fix query ids rake task" do
before do
Rake::Task.clear
- Discourse::Application.load_tasks
+ silence_warnings { Discourse::Application.load_tasks }
end
let(:query_name) { "Awesome query" }
diff --git a/plugins/discourse-presence/spec/integration/presence_spec.rb b/plugins/discourse-presence/spec/integration/presence_spec.rb
index 74fd8f57694..28507494c03 100644
--- a/plugins/discourse-presence/spec/integration/presence_spec.rb
+++ b/plugins/discourse-presence/spec/integration/presence_spec.rb
@@ -66,7 +66,7 @@ RSpec.describe "discourse-presence" do
end
it "handles category moderators for edit" do
- SiteSetting.edit_all_post_groups = nil
+ SiteSetting.edit_all_post_groups = ""
p = Fabricate(:post, topic: private_topic, user: private_topic.user)
c = PresenceChannel.new("/discourse-presence/edit/#{p.id}")
diff --git a/plugins/discourse-subscriptions/spec/requests/subscribe_controller_spec.rb b/plugins/discourse-subscriptions/spec/requests/subscribe_controller_spec.rb
index cbc814d2dfb..74b9a58e59a 100644
--- a/plugins/discourse-subscriptions/spec/requests/subscribe_controller_spec.rb
+++ b/plugins/discourse-subscriptions/spec/requests/subscribe_controller_spec.rb
@@ -158,7 +158,7 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
end
it "shows all purchases if campaign product not set" do
- SiteSetting.discourse_subscriptions_campaign_product = nil
+ SiteSetting.discourse_subscriptions_campaign_product = ""
get "/s/contributors.json"
diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb
index 23229cac3c0..b05b3a84b56 100644
--- a/spec/support/helpers.rb
+++ b/spec/support/helpers.rb
@@ -191,7 +191,12 @@ module Helpers
File.write("#{repo_dir}/#{name}", data)
system("git -C #{repo_dir} add #{name}", exception: true)
end
- system("git -C #{repo_dir} commit -q -am 'first commit'", exception: false)
+ system(
+ "git -C #{repo_dir} commit -q -am 'first commit'",
+ out: File::NULL,
+ err: File::NULL,
+ exception: false,
+ )
repo_dir
end