Add AlgoliaSearchable to Podcast (#20890)

* Create AlgoliaSearchable::SearchablePodcastEpisode

* Refactor

* Remove pre-mature methods
This commit is contained in:
Mac Siri 2024-04-24 11:14:10 -04:00 committed by GitHub
parent 755939733d
commit 1895237c24
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 35 additions and 0 deletions

View file

@ -0,0 +1,25 @@
module AlgoliaSearchable
module SearchablePodcastEpisode
extend ActiveSupport::Concern
included do
include AlgoliaSearch
algoliasearch(**DEFAULT_ALGOLIA_SETTINGS, if: :published) do
attribute :title, :summary, :path
attribute :podcast_name do
podcast.title
end
attribute :podcast_image do
profile_image_url
end
end
end
class_methods do
def trigger_sidekiq_worker(record, delete)
AlgoliaSearch::SearchIndexWorker.perform_async(record.class.name, record.id, delete)
end
end
end
end

View file

@ -1,5 +1,6 @@
class PodcastEpisode < ApplicationRecord
include PgSearch::Model
include AlgoliaSearchable
acts_as_taggable

View file

@ -131,4 +131,13 @@ RSpec.describe PodcastEpisode do
end
end
end
context "when indexing with Algolia", :algolia do
it "triggers indexing on save" do
allow(AlgoliaSearch::SearchIndexWorker).to receive(:perform_async)
create(:podcast_episode)
expect(AlgoliaSearch::SearchIndexWorker).to have_received(:perform_async).with("PodcastEpisode",
kind_of(Integer), false)
end
end
end