From a2a2785f0b85f1ea90f2cea2d358b20500ee224d Mon Sep 17 00:00:00 2001 From: Bianca Nenciu Date: Fri, 9 Feb 2024 19:59:38 +0200 Subject: [PATCH] FIX: Look up all channel hashtags (#25617) --- plugins/chat/lib/chat/channel_fetcher.rb | 1 - .../hashtag_autocomplete_service_spec.rb | 26 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 plugins/chat/spec/services/hashtag_autocomplete_service_spec.rb diff --git a/plugins/chat/lib/chat/channel_fetcher.rb b/plugins/chat/lib/chat/channel_fetcher.rb index 9daaf6908f1..6680aed3f9f 100644 --- a/plugins/chat/lib/chat/channel_fetcher.rb +++ b/plugins/chat/lib/chat/channel_fetcher.rb @@ -80,7 +80,6 @@ module Chat .where(chatable_type: Chat::Channel.public_channel_chatable_types) .where("chat_channels.id IN (#{allowed_channel_ids})") .where("chat_channels.slug IN (:slugs)", slugs: slugs) - .limit(1) end def self.secured_public_channel_search(guardian, options = {}) diff --git a/plugins/chat/spec/services/hashtag_autocomplete_service_spec.rb b/plugins/chat/spec/services/hashtag_autocomplete_service_spec.rb new file mode 100644 index 00000000000..da3075b304e --- /dev/null +++ b/plugins/chat/spec/services/hashtag_autocomplete_service_spec.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +RSpec.describe HashtagAutocompleteService do + subject(:service) { described_class.new(guardian) } + + fab!(:channel1) { Fabricate(:chat_channel, name: "Music Lounge", slug: "music") } + fab!(:channel2) { Fabricate(:chat_channel, name: "Random", slug: "random") } + + fab!(:admin) + let(:guardian) { Guardian.new(admin) } + + describe ".enabled_data_sources" do + it "only returns data sources that are enabled" do + expect(HashtagAutocompleteService.enabled_data_sources).to include( + Chat::ChannelHashtagDataSource, + ) + end + end + + describe "#lookup" do + it "returns hashtags for channels" do + result = service.lookup(%w[music::channel random::channel], ["channel"]) + expect(result[:channel].map(&:slug)).to contain_exactly("music", "random") + end + end +end