|
26 | 26 |
|
27 | 27 | let(:task) { 'podcasts:upsert' } |
28 | 28 |
|
29 | | - # TODO: This test is flaky? It seems fails depending on Internet and should work offline. |
30 | | - xit 'successfuly fetch from Anchor.fm RSS' do |
31 | | - allow_any_instance_of(Podcast).to receive(:id).and_return( |
32 | | - [ |
33 | | - { 'id' => 123456001, |
34 | | - 'title' => '999 - podcast title', |
35 | | - 'description' => '説明 999', |
36 | | - 'content_size' => 124542711, |
37 | | - 'duration' => 5189815, |
38 | | - 'user_id' => 123456789, |
39 | | - 'permalink' => '999-title', |
40 | | - 'permalink_url' => 'https://anchor.fm/coderdojo-japan/999-title', |
41 | | - 'created_at' => '2099/01/23 01:00:00 +0000' } |
42 | | - ] |
| 29 | + it 'successfuly fetch from RSS (mock)' do |
| 30 | + # RSSのモック |
| 31 | + rss_content = <<~RSS |
| 32 | + <?xml version="1.0" encoding="UTF-8"?> |
| 33 | + <rss version="2.0"> |
| 34 | + <channel> |
| 35 | + <item> |
| 36 | + <title>001 - 日本の CoderDojo の成り立ち</title> |
| 37 | + <description>jishihaの説明文</description> |
| 38 | + <link>https://anchor.fm/coderdojo-japan/episodes/001----CoderDojo-euhits</link> |
| 39 | + <pubDate>Sat, 25 Mar 2017 00:00:00 GMT</pubDate> |
| 40 | + <enclosure url="https://example.com/podcast.mp3" length="22887860" type="audio/mpeg"/> |
| 41 | + <itunes:duration>2857</itunes:duration> |
| 42 | + </item> |
| 43 | + </channel> |
| 44 | + </rss> |
| 45 | + RSS |
| 46 | + |
| 47 | + # RSS::Parserのモック |
| 48 | + rss_parser = instance_double(RSS::Rss) |
| 49 | + rss_item = instance_double(RSS::Rss::Channel::Item) |
| 50 | + allow(rss_item).to receive(:title).and_return('001 - 日本の CoderDojo の成り立ち') |
| 51 | + allow(rss_item).to receive(:description).and_return('jishihaの説明文') |
| 52 | + allow(rss_item).to receive(:link).and_return('https://anchor.fm/coderdojo-japan/episodes/001----CoderDojo-euhits') |
| 53 | + allow(rss_item).to receive(:pubDate).and_return(Time.parse('2017-03-25')) |
| 54 | + allow(rss_item).to receive(:enclosure).and_return( |
| 55 | + instance_double(RSS::Rss::Channel::Item::Enclosure, url: 'https://example.com/podcast.mp3', length: 22887860) |
43 | 56 | ) |
| 57 | + allow(rss_item).to receive(:itunes_duration).and_return(double(content: '2857', to_s: '2857')) |
| 58 | + allow(rss_parser).to receive(:items).and_return([rss_item]) |
| 59 | + allow(RSS::Parser).to receive(:parse).and_return(rss_parser) |
44 | 60 |
|
45 | 61 | # before |
46 | 62 | expect(Podcast.count).to eq(1) |
|
52 | 68 | # after |
53 | 69 | expect(Podcast.count).not_to eq(1) |
54 | 70 | new_records = Podcast.where.not(id: before_ids) |
55 | | - expect(new_records.count).not_to eq(1) |
56 | | - first_track = new_records.find(1) |
| 71 | + expect(new_records.count).to eq(1) |
| 72 | + first_track = new_records.first |
57 | 73 |
|
58 | 74 | expect(first_track.title).to eq('001 - 日本の CoderDojo の成り立ち') |
59 | 75 | expect(first_track.description).to start_with('jishiha') |
60 | 76 | expect(first_track.content_size).to eq(22887860) |
61 | | - expect(first_track.duration).to eq('2857') # eq('00:47:37') |
62 | | - expect(first_track.permalink).to eq('001----CoderDojo-euhits') # eq('999-title') |
| 77 | + expect(first_track.duration).to eq('2857') |
| 78 | + expect(first_track.permalink).to eq('001----CoderDojo-euhits') |
63 | 79 | expect(first_track.permalink_url).to eq('https://anchor.fm/coderdojo-japan/episodes/001----CoderDojo-euhits') |
64 | 80 | expect(first_track.published_date).to eq('2017-03-25'.to_date) |
65 | 81 | end |
|
0 commit comments