Move create PodcastEpisode callbacks to create Podcast Service (#7077) [deploy]
* move create podcast callbacks to create podcast service * add indexing spec to creator
This commit is contained in:
parent
eaefd588aa
commit
6f95744698
3 changed files with 17 additions and 4 deletions
|
|
@ -30,12 +30,13 @@ class PodcastEpisode < ApplicationRecord
|
|||
validates :media_url, presence: true, uniqueness: true
|
||||
validates :guid, presence: true, uniqueness: true
|
||||
|
||||
# NOTE: Any create callbacks will not be run since we use activerecord-import to create episodes
|
||||
# https://github.com/zdennis/activerecord-import#callbacks
|
||||
after_update :purge
|
||||
after_create :purge_all
|
||||
after_destroy :purge, :purge_all
|
||||
after_save :bust_cache
|
||||
after_save :bust_cache
|
||||
|
||||
after_commit :index_to_elasticsearch, on: %i[create update]
|
||||
after_commit :index_to_elasticsearch, on: %i[update]
|
||||
after_commit :remove_from_elasticsearch, on: [:destroy]
|
||||
|
||||
before_validation :process_html_and_prefix_all_images
|
||||
|
|
|
|||
|
|
@ -29,7 +29,9 @@ module Podcasts
|
|||
conflict_target: %i[media_url],
|
||||
columns: %i[title slug subtitle summary website_url published_at reachable media_url https body]
|
||||
}
|
||||
PodcastEpisode.find(import_result.ids.first)
|
||||
episode = PodcastEpisode.find(import_result.ids.first)
|
||||
finalize(episode)
|
||||
episode
|
||||
end
|
||||
|
||||
private
|
||||
|
|
@ -42,5 +44,10 @@ module Podcasts
|
|||
episode.media_url = result.url
|
||||
episode.https = result.https
|
||||
end
|
||||
|
||||
def finalize(episode)
|
||||
episode.purge_all
|
||||
episode.index_to_elasticsearch
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -19,6 +19,11 @@ RSpec.describe Podcasts::CreateEpisode, type: :service do
|
|||
end.to change(PodcastEpisode, :count).by(1)
|
||||
end
|
||||
|
||||
it "indexes the episode" do
|
||||
sidekiq_perform_enqueued_jobs { described_class.call(podcast.id, item) }
|
||||
expect { podcast.podcast_episodes.each(&:elasticsearch_doc) }.not_to raise_error
|
||||
end
|
||||
|
||||
it "creates an episode with correct data" do
|
||||
episode = described_class.call(podcast.id, item)
|
||||
expect(episode.title).to eq("Individual Contributor Career Growth w/ Matt Klein (part 1)")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue