feedzirra 0.0.18.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,149 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Feedzirra::FeedUtilities do
4
+ before(:each) do
5
+ @klass = Class.new do
6
+ include Feedzirra::FeedUtilities
7
+ end
8
+ end
9
+
10
+ describe "instance methods" do
11
+ it "should provide an updated? accessor" do
12
+ feed = @klass.new
13
+ feed.should_not be_updated
14
+ feed.updated = true
15
+ feed.should be_updated
16
+ end
17
+
18
+ it "should provide a new_entries accessor" do
19
+ feed = @klass.new
20
+ feed.new_entries.should == []
21
+ feed.new_entries = [:foo]
22
+ feed.new_entries.should == [:foo]
23
+ end
24
+
25
+ it "should provide an etag accessor" do
26
+ feed = @klass.new
27
+ feed.etag = "foo"
28
+ feed.etag.should == "foo"
29
+ end
30
+
31
+ it "should provide a last_modified accessor" do
32
+ feed = @klass.new
33
+ time = Time.now
34
+ feed.last_modified = time
35
+ feed.last_modified.should == time
36
+ end
37
+
38
+ it "should return new_entries? as true when entries are put into new_entries" do
39
+ feed = @klass.new
40
+ feed.new_entries << :foo
41
+ feed.should have_new_entries
42
+ end
43
+
44
+ it "should return a last_modified value from the entry with the most recent published date if the last_modified date hasn't been set" do
45
+ feed = Feedzirra::Parser::Atom.new
46
+ entry =Feedzirra::Parser::AtomEntry.new
47
+ entry.published = Time.now.to_s
48
+ feed.entries << entry
49
+ feed.last_modified.should == entry.published
50
+ end
51
+
52
+ it "should not throw an error if one of the entries has published date of nil" do
53
+ feed = Feedzirra::Parser::Atom.new
54
+ entry = Feedzirra::Parser::AtomEntry.new
55
+ entry.published = Time.now.to_s
56
+ feed.entries << entry
57
+ feed.entries << Feedzirra::Parser::AtomEntry.new
58
+ feed.last_modified.should == entry.published
59
+ end
60
+ end
61
+
62
+ describe "#update_from_feed" do
63
+ describe "updating feed attributes" do
64
+ before(:each) do
65
+ # I'm using the Atom class when I know I should be using a different one. However, this update_from_feed
66
+ # method would only be called against a feed item.
67
+ @feed = Feedzirra::Parser::Atom.new
68
+ @feed.title = "A title"
69
+ @feed.url = "http://pauldix.net"
70
+ @feed.feed_url = "http://feeds.feedburner.com/PaulDixExplainsNothing"
71
+ @feed.updated = false
72
+ @updated_feed = @feed.dup
73
+ end
74
+
75
+ it "should update the title if changed" do
76
+ @updated_feed.title = "new title"
77
+ @feed.update_from_feed(@updated_feed)
78
+ @feed.title.should == @updated_feed.title
79
+ @feed.should be_updated
80
+ end
81
+
82
+ it "should not update the title if the same" do
83
+ @feed.update_from_feed(@updated_feed)
84
+ @feed.should_not be_updated
85
+ end
86
+
87
+ it "should update the feed_url if changed" do
88
+ @updated_feed.feed_url = "a new feed url"
89
+ @feed.update_from_feed(@updated_feed)
90
+ @feed.feed_url.should == @updated_feed.feed_url
91
+ @feed.should be_updated
92
+ end
93
+
94
+ it "should not update the feed_url if the same" do
95
+ @feed.update_from_feed(@updated_feed)
96
+ @feed.should_not be_updated
97
+ end
98
+
99
+ it "should update the url if changed" do
100
+ @updated_feed.url = "a new url"
101
+ @feed.update_from_feed(@updated_feed)
102
+ @feed.url.should == @updated_feed.url
103
+ end
104
+
105
+ it "should not update the url if not changed" do
106
+ @feed.update_from_feed(@updated_feed)
107
+ @feed.should_not be_updated
108
+ end
109
+ end
110
+
111
+ describe "updating entries" do
112
+ before(:each) do
113
+ # I'm using the Atom class when I know I should be using a different one. However, this update_from_feed
114
+ # method would only be called against a feed item.
115
+ @feed = Feedzirra::Parser::Atom.new
116
+ @feed.title = "A title"
117
+ @feed.url = "http://pauldix.net"
118
+ @feed.feed_url = "http://feeds.feedburner.com/PaulDixExplainsNothing"
119
+ @feed.updated = false
120
+ @updated_feed = @feed.dup
121
+ @old_entry = Feedzirra::Parser::AtomEntry.new
122
+ @old_entry.url = "http://pauldix.net/old.html"
123
+ @old_entry.published = Time.now.to_s
124
+ @new_entry = Feedzirra::Parser::AtomEntry.new
125
+ @new_entry.url = "http://pauldix.net/new.html"
126
+ @new_entry.published = (Time.now + 10).to_s
127
+ @feed.entries << @old_entry
128
+ @updated_feed.entries << @new_entry
129
+ @updated_feed.entries << @old_entry
130
+ end
131
+
132
+ it "should update last-modified from the latest entry date" do
133
+ @feed.update_from_feed(@updated_feed)
134
+ @feed.last_modified.should == @new_entry.published
135
+ end
136
+
137
+ it "should put new entries into new_entries" do
138
+ @feed.update_from_feed(@updated_feed)
139
+ @feed.new_entries.should == [@new_entry]
140
+ end
141
+
142
+ it "should also put new entries into the entries collection" do
143
+ @feed.update_from_feed(@updated_feed)
144
+ @feed.entries.should include(@new_entry)
145
+ @feed.entries.should include(@old_entry)
146
+ end
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,49 @@
1
+ require File.join(File.dirname(__FILE__), %w[.. .. spec_helper])
2
+
3
+ describe Feedzirra::Parser::AtomEntry do
4
+ before(:each) do
5
+ # I don't really like doing it this way because these unit test should only rely on AtomEntry,
6
+ # but this is actually how it should work. You would never just pass entry xml straight to the AtomEnry
7
+ @entry = Feedzirra::Parser::Atom.parse(sample_atom_feed).entries.first
8
+ end
9
+
10
+ it "should parse the title" do
11
+ @entry.title.should == "AWS Job: Architect & Designer Position in Turkey"
12
+ end
13
+
14
+ it "should parse the url" do
15
+ @entry.url.should == "http://aws.typepad.com/aws/2009/01/aws-job-architect-designer-position-in-turkey.html"
16
+ end
17
+
18
+ it "should parse the url even when" do
19
+ Feedzirra::Parser::Atom.parse(load_sample("atom_with_link_tag_for_url_unmarked.xml")).entries.first.url.should == "http://www.innoq.com/blog/phaus/2009/07/ja.html"
20
+ end
21
+
22
+ it "should parse the author" do
23
+ @entry.author.should == "AWS Editor"
24
+ end
25
+
26
+ it "should parse the content" do
27
+ @entry.content.should == sample_atom_entry_content
28
+ end
29
+
30
+ it "should provide a summary" do
31
+ @entry.summary.should == "Late last year an entrepreneur from Turkey visited me at Amazon HQ in Seattle. We talked about his plans to use AWS as part of his new social video portal startup. I won't spill any beans before he's ready to..."
32
+ end
33
+
34
+ it "should parse the published date" do
35
+ @entry.published.to_s.should == "Fri Jan 16 18:21:00 UTC 2009"
36
+ end
37
+
38
+ it "should parse the categories" do
39
+ @entry.categories.should == ['Turkey', 'Seattle']
40
+ end
41
+
42
+ it "should parse the updated date" do
43
+ @entry.updated.to_s.should == "Fri Jan 16 18:21:00 UTC 2009"
44
+ end
45
+
46
+ it "should parse the id" do
47
+ @entry.id.should == "tag:typepad.com,2003:post-61484736"
48
+ end
49
+ end
@@ -0,0 +1,42 @@
1
+ require File.join(File.dirname(__FILE__), %w[.. .. spec_helper])
2
+
3
+ describe Feedzirra::Parser::AtomFeedBurnerEntry do
4
+ before(:each) do
5
+ # I don't really like doing it this way because these unit test should only rely on AtomEntry,
6
+ # but this is actually how it should work. You would never just pass entry xml straight to the AtomEnry
7
+ @entry = Feedzirra::Parser::AtomFeedBurner.parse(sample_feedburner_atom_feed).entries.first
8
+ end
9
+
10
+ it "should parse the title" do
11
+ @entry.title.should == "Making a Ruby C library even faster"
12
+ end
13
+
14
+ it "should be able to fetch a url via the 'alternate' rel if no origLink exists" do
15
+ entry = Feedzirra::Parser::AtomFeedBurner.parse(File.read("#{File.dirname(__FILE__)}/../../sample_feeds/PaulDixExplainsNothingAlternate.xml")).entries.first
16
+ entry.url.should == 'http://feeds.feedburner.com/~r/PaulDixExplainsNothing/~3/519925023/making-a-ruby-c-library-even-faster.html'
17
+ end
18
+
19
+ it "should parse the url" do
20
+ @entry.url.should == "http://www.pauldix.net/2009/01/making-a-ruby-c-library-even-faster.html"
21
+ end
22
+
23
+ it "should parse the author" do
24
+ @entry.author.should == "Paul Dix"
25
+ end
26
+
27
+ it "should parse the content" do
28
+ @entry.content.should == sample_feedburner_atom_entry_content
29
+ end
30
+
31
+ it "should provide a summary" do
32
+ @entry.summary.should == "Last week I released the first version of a SAX based XML parsing library called SAX-Machine. It uses Nokogiri, which uses libxml, so it's pretty fast. However, I felt that it could be even faster. The only question was how..."
33
+ end
34
+
35
+ it "should parse the published date" do
36
+ @entry.published.to_s.should == "Thu Jan 22 15:50:22 UTC 2009"
37
+ end
38
+
39
+ it "should parse the categories" do
40
+ @entry.categories.should == ['Ruby', 'Another Category']
41
+ end
42
+ end
@@ -0,0 +1,39 @@
1
+ require File.join(File.dirname(__FILE__), %w[.. .. spec_helper])
2
+
3
+ describe Feedzirra::Parser::AtomFeedBurner do
4
+ describe "#will_parse?" do
5
+ it "should return true for a feedburner atom feed" do
6
+ Feedzirra::Parser::AtomFeedBurner.should be_able_to_parse(sample_feedburner_atom_feed)
7
+ end
8
+
9
+ it "should return false for an rdf feed" do
10
+ Feedzirra::Parser::AtomFeedBurner.should_not be_able_to_parse(sample_rdf_feed)
11
+ end
12
+
13
+ it "should return false for a regular atom feed" do
14
+ Feedzirra::Parser::AtomFeedBurner.should_not be_able_to_parse(sample_atom_feed)
15
+ end
16
+ end
17
+
18
+ describe "parsing" do
19
+ before(:each) do
20
+ @feed = Feedzirra::Parser::AtomFeedBurner.parse(sample_feedburner_atom_feed)
21
+ end
22
+
23
+ it "should parse the title" do
24
+ @feed.title.should == "Paul Dix Explains Nothing"
25
+ end
26
+
27
+ it "should parse the url" do
28
+ @feed.url.should == "http://www.pauldix.net/"
29
+ end
30
+
31
+ it "should parse the feed_url" do
32
+ @feed.feed_url.should == "http://feeds.feedburner.com/PaulDixExplainsNothing"
33
+ end
34
+
35
+ it "should parse entries" do
36
+ @feed.entries.size.should == 5
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,63 @@
1
+ require File.join(File.dirname(__FILE__), %w[.. .. spec_helper])
2
+
3
+ describe Feedzirra::Parser::Atom do
4
+ describe "#will_parse?" do
5
+ it "should return true for an atom feed" do
6
+ Feedzirra::Parser::Atom.should be_able_to_parse(sample_atom_feed)
7
+ end
8
+
9
+ it "should return false for an rdf feed" do
10
+ Feedzirra::Parser::Atom.should_not be_able_to_parse(sample_rdf_feed)
11
+ end
12
+ end
13
+
14
+ describe "parsing" do
15
+ before(:each) do
16
+ @feed = Feedzirra::Parser::Atom.parse(sample_atom_feed)
17
+ end
18
+
19
+ it "should parse the title" do
20
+ @feed.title.should == "Amazon Web Services Blog"
21
+ end
22
+
23
+ it "should parse the url" do
24
+ @feed.url.should == "http://aws.typepad.com/aws/"
25
+ end
26
+
27
+ it "should parse updated" do
28
+ @feed.updated.should == "2009-01-16T18:21:00Z"
29
+ end
30
+
31
+ it "should parse the subtitle" do
32
+ @feed.subtitle.should == "Amazon Web Services, Products, Tools, and Developer Information..."
33
+ end
34
+
35
+ it "should parse the url even when it doesn't have the type='text/html' attribute" do
36
+ Feedzirra::Parser::Atom.parse(load_sample("atom_with_link_tag_for_url_unmarked.xml")).url.should == "http://www.innoq.com/planet/"
37
+ end
38
+
39
+ it "should parse the feed_url even when it doesn't have the type='application/atom+xml' attribute" do
40
+ Feedzirra::Parser::Atom.parse(load_sample("atom_with_link_tag_for_url_unmarked.xml")).feed_url.should == "http://www.innoq.com/planet/atom.xml"
41
+ end
42
+
43
+ it "should parse the feed_url" do
44
+ @feed.feed_url.should == "http://aws.typepad.com/aws/atom.xml"
45
+ end
46
+
47
+ it "should parse the prev atom:link" do
48
+ @feed.prev_page.should == "http://aws.typepad.com/aws/atom.xml?page=1"
49
+ end
50
+
51
+ it "should parse the next atom:link" do
52
+ @feed.next_page.should == "http://aws.typepad.com/aws/atom.xml?page=3"
53
+ end
54
+
55
+ it "should parse the last atom:link" do
56
+ @feed.last_page.should == "http://aws.typepad.com/aws/atom.xml?page=5"
57
+ end
58
+
59
+ it "should parse entries" do
60
+ @feed.entries.size.should == 10
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,48 @@
1
+ require File.join(File.dirname(__FILE__), %w[.. .. spec_helper])
2
+
3
+ describe Feedzirra::Parser::ITunesRSSItem do
4
+ before(:each) do
5
+ # I don't really like doing it this way because these unit test should only rely on ITunesRssItem,
6
+ # but this is actually how it should work. You would never just pass entry xml straight to the ITunesRssItem
7
+ @item = Feedzirra::Parser::ITunesRSS.parse(sample_itunes_feed).entries.first
8
+ end
9
+
10
+ it "should parse the title" do
11
+ @item.title.should == "Shake Shake Shake Your Spices"
12
+ end
13
+
14
+ it "should parse the author" do
15
+ @item.itunes_author.should == "John Doe"
16
+ end
17
+
18
+ it "should parse the subtitle" do
19
+ @item.itunes_subtitle.should == "A short primer on table spices"
20
+ end
21
+
22
+ it "should parse the summary" do
23
+ @item.itunes_summary.should == "This week we talk about salt and pepper shakers, comparing and contrasting pour rates, construction materials, and overall aesthetics. Come and join the party!"
24
+ end
25
+
26
+ it "should parse the enclosure" do
27
+ @item.enclosure_length.should == "8727310"
28
+ @item.enclosure_type.should == "audio/x-m4a"
29
+ @item.enclosure_url.should == "http://example.com/podcasts/everything/AllAboutEverythingEpisode3.m4a"
30
+ end
31
+
32
+ it "should parse the guid" do
33
+ @item.guid.should == "http://example.com/podcasts/archive/aae20050615.m4a"
34
+ end
35
+
36
+ it "should parse the published date" do
37
+ @item.published.should == "Wed, 15 Jun 2005 19:00:00 GMT"
38
+ end
39
+
40
+ it "should parse the duration" do
41
+ @item.itunes_duration.should == "7:04"
42
+ end
43
+
44
+ it "should parse the keywords" do
45
+ @item.itunes_keywords.should == "salt, pepper, shaker, exciting"
46
+ end
47
+
48
+ end
@@ -0,0 +1,18 @@
1
+ require File.join(File.dirname(__FILE__), %w[.. .. spec_helper])
2
+
3
+ describe Feedzirra::Parser::ITunesRSSOwner do
4
+ before(:each) do
5
+ # I don't really like doing it this way because these unit test should only rely on RSSEntry,
6
+ # but this is actually how it should work. You would never just pass entry xml straight to the ITunesRssOwner
7
+ @owner = Feedzirra::Parser::ITunesRSS.parse(sample_itunes_feed).itunes_owners.first
8
+ end
9
+
10
+ it "should parse the name" do
11
+ @owner.name.should == "John Doe"
12
+ end
13
+
14
+ it "should parse the email" do
15
+ @owner.email.should == "john.doe@example.com"
16
+ end
17
+
18
+ end
@@ -0,0 +1,50 @@
1
+ require File.join(File.dirname(__FILE__), %w[.. .. spec_helper])
2
+
3
+ describe Feedzirra::Parser::ITunesRSS do
4
+ describe "#will_parse?" do
5
+ it "should return true for an itunes RSS feed" do
6
+ Feedzirra::Parser::ITunesRSS.should be_able_to_parse(sample_itunes_feed)
7
+ end
8
+
9
+ it "should return fase for an atom feed" do
10
+ Feedzirra::Parser::ITunesRSS.should_not be_able_to_parse(sample_atom_feed)
11
+ end
12
+ end
13
+
14
+ describe "parsing" do
15
+ before(:each) do
16
+ @feed = Feedzirra::Parser::ITunesRSS.parse(sample_itunes_feed)
17
+ end
18
+
19
+ it "should parse the subtitle" do
20
+ @feed.itunes_subtitle.should == "A show about everything"
21
+ end
22
+
23
+ it "should parse the author" do
24
+ @feed.itunes_author.should == "John Doe"
25
+ end
26
+
27
+ it "should parse an owner" do
28
+ @feed.itunes_owners.size.should == 1
29
+ end
30
+
31
+ it "should parse an image" do
32
+ @feed.itunes_image.should == "http://example.com/podcasts/everything/AllAboutEverything.jpg"
33
+ end
34
+
35
+ it "should parse categories" do
36
+ @feed.itunes_categories.size == 3
37
+ @feed.itunes_categories[0] == "Technology"
38
+ @feed.itunes_categories[1] == "Gadgets"
39
+ @feed.itunes_categories[2] == "TV &amp; Film"
40
+ end
41
+
42
+ it "should parse the summary" do
43
+ @feed.itunes_summary.should == "All About Everything is a show about everything. Each week we dive into any subject known to man and talk about it as much as we can. Look for our Podcast in the iTunes Music Store"
44
+ end
45
+
46
+ it "should parse entries" do
47
+ @feed.entries.size.should == 3
48
+ end
49
+ end
50
+ end