|
14 | 14 | end |
15 | 15 |
|
16 | 16 | describe 'podcasts:upsert' do |
17 | | - before :each do |
18 | | - Podcast.destroy_all |
19 | | - @episode = create(:podcast, |
20 | | - title: '999 - podcast 999', |
21 | | - duration: '00:16:40', |
22 | | - permalink: 'podcast-999', |
23 | | - enclosure_url: 'https://aaa.bbb/title.mp3', |
24 | | -) |
25 | | - end |
26 | | - |
27 | 17 | let(:task) { 'podcasts:upsert' } |
28 | 18 |
|
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) |
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) |
60 | | - |
61 | | - # before |
62 | | - expect(Podcast.count).to eq(1) |
63 | | - before_ids = Podcast.ids |
64 | | - |
65 | | - # exec |
66 | | - expect(@rake[task].invoke).to be_truthy |
67 | | - |
68 | | - # after |
69 | | - expect(Podcast.count).not_to eq(1) |
70 | | - new_records = Podcast.where.not(id: before_ids) |
71 | | - expect(new_records.count).to eq(1) |
72 | | - first_track = new_records.first |
73 | | - |
74 | | - expect(first_track.title).to eq('001 - 日本の CoderDojo の成り立ち') |
75 | | - expect(first_track.description).to start_with('jishiha') |
76 | | - expect(first_track.content_size).to eq(22887860) |
77 | | - expect(first_track.duration).to eq('2857') |
78 | | - expect(first_track.permalink).to eq('001----CoderDojo-euhits') |
79 | | - expect(first_track.permalink_url).to eq('https://anchor.fm/coderdojo-japan/episodes/001----CoderDojo-euhits') |
80 | | - expect(first_track.published_date).to eq('2017-03-25'.to_date) |
| 19 | + before :each do |
| 20 | + Podcast.destroy_all |
81 | 21 | end |
82 | 22 |
|
83 | | - it 'failed to fetch from Anchor.fm RSS' do |
84 | | - allow_any_instance_of(Podcast).to receive(:id).and_return( |
85 | | - [ |
86 | | - { 'id' => 123456001, |
87 | | - 'title' => 'podcast title 001', |
88 | | - 'description' => '説明 001', |
89 | | - 'content_size' => 124542711, |
90 | | - 'duration' => 5189815, |
91 | | - 'user_id' => 123456789, |
92 | | - 'permalink' => 'podcast-001', |
93 | | - 'permalink_url' => 'https://anchor.fm/coderdojo-japan/999-title', |
94 | | - 'created_at' => '2019/01/23 01:00:00 +0000' } |
95 | | - ] |
96 | | - ) |
97 | | - |
98 | | - # before |
99 | | - expect(Podcast.count).to eq(1) |
100 | | - before_ids = Podcast.ids |
| 23 | + it '既存のanchorfm_sample.rssでRakeタスクがエラーなく動作し、エピソードが複数登録される' do |
| 24 | + expect { Rake::Task['podcasts:upsert'].reenable; Rake::Task['podcasts:upsert'].invoke } |
| 25 | + .not_to raise_error |
101 | 26 |
|
102 | | - # after |
103 | | - expect(Podcast.count).to eq(1) |
104 | | - new_records = Podcast.where.not(id: before_ids) |
105 | | - expect(new_records.count).to eq(0) |
| 27 | + expect(Podcast.count).to be > 0 |
| 28 | + expect(Podcast.pluck(:title)).to include('001 - 日本の CoderDojo の成り立ち') |
106 | 29 | end |
107 | 30 | end |
108 | 31 | end |
0 commit comments