Fix podcast episode validation error (#4967) [deploy]

* Started fixing podcast episode bug

* Fix the specs for create podcast episode
This commit is contained in:
Anna Buianova 2019-11-30 00:16:19 +03:00 committed by Ben Halpern
parent 5fc0a12f26
commit bff6cd6985
2 changed files with 25 additions and 2 deletions

View file

@ -25,8 +25,11 @@ module Podcasts
Rails.logger.error("not a valid date: #{e}")
end
ep.body = item.body
ep.save!
ep
import_result = PodcastEpisode.import! [ep], on_duplicate_key_update: {
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)
end
private

View file

@ -70,4 +70,24 @@ RSpec.describe Podcasts::CreateEpisode, type: :service do
expect(episode.reachable).to be true
end
end
context "when attempting to create duplicate episodes" do
let(:rss_item) { RSS::Parser.parse("spec/support/fixtures/podcasts/developertea.rss", false).items.first }
let(:item) { Podcasts::EpisodeRssItem.from_item(rss_item) }
let!(:episode) { create(:podcast_episode, title: "outdated title", media_url: item.enclosure_url) }
before do
stub_request(:head, item.enclosure_url).to_return(status: 200)
end
it "updates existing episode" do
new_episode = described_class.call(podcast.id, item)
expect(new_episode.id).to eq(episode.id)
end
it "updates columns" do
new_episode = described_class.call(podcast.id, item)
expect(new_episode.title).to eq(item.title)
end
end
end