fix(search): guard reindex_for_search when searchkick is not loaded

searchkick (which defines #reindex) is only mixed into Message at class-load time
when advanced_search_allowed? (enterprise + OPENSEARCH_URL) is true at boot. A spec
that stubs advanced_search_allowed? true without a loaded index makes should_index?
true and fires the reindex callback, raising NoMethodError. Guard on respond_to?
so it no-ops when no index is available (real deployments without search index
already have should_index? false, so behavior is unchanged).
This commit is contained in:
Tanmay Deep Sharma
2026-07-15 14:50:39 +05:30
parent e2cd372d2d
commit 40b77ca001
+4
View File
@@ -452,6 +452,10 @@ class Message < ApplicationRecord
end
def reindex_for_search
# searchkick (which defines #reindex) is only mixed in when advanced_search_allowed? is true
# at boot; guard so a should_index? true without a loaded index can't raise NoMethodError.
return unless respond_to?(:reindex)
reindex(mode: :async)
end
end