Add AlgoliaSearchable to Podcast (#20890)
* Create AlgoliaSearchable::SearchablePodcastEpisode * Refactor * Remove pre-mature methods
This commit is contained in:
parent
755939733d
commit
1895237c24
3 changed files with 35 additions and 0 deletions
|
|
@ -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
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
class PodcastEpisode < ApplicationRecord
|
||||
include PgSearch::Model
|
||||
include AlgoliaSearchable
|
||||
|
||||
acts_as_taggable
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue