Skip to content
Permalink
Browse files

Make XML parsing test not hit the internet.

  • Loading branch information
jasonswett committed Nov 13, 2018
1 parent d67f9ca commit 35e1db998867450a94920a670eb12a2a701e73a4
Showing with 17 additions and 16 deletions.
  1. +3 −10 app/models/show.rb
  2. +14 −6 spec/models/show_spec.rb
@@ -5,19 +5,12 @@ class Show < ApplicationRecord
presence: true,
format: URI::regexp(%w(http https))

def parse_xml_feed!
def save_and_parse!(xml_feed_contents)
save!

PodcastRSSFile.new(
show: self,
contents: xml_feed_contents
).consume!
end

def xml_feed_contents
Net::HTTP.get(URI.parse(xml_feed_url))
end

def save_and_parse!
save!
parse_xml_feed!
end
end
@@ -7,15 +7,23 @@
it { should validate_presence_of(:xml_feed_url) }

describe 'XML feed parsing' do
it 'gets parsed upon show creation' do
show = Show.new(
name: 'The Tim Ferriss Show',
xml_feed_url: 'https://rss.art19.com/tim-ferriss-show'
let(:filename) do
Rails.root.join('spec', 'files', 'ruby_testing_podcast.xml')
end

let(:xml_feed_contents) { File.read(filename) }

let(:show) do
Show.new(
name: 'The Ruby Testing Podcast',
xml_feed_url: 'https://example.com/rss'
)
end

expect { show.save_and_parse! }.to change {
it 'gets parsed upon show creation' do
expect { show.save_and_parse!(xml_feed_contents) }.to change {
show.episodes.count
}.from(0).to(349)
}.from(0).to(15)
end
end

0 comments on commit 35e1db9

Please sign in to comment.
You can’t perform that action at this time.