feed_cache 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/feed_cache.rb CHANGED
@@ -2,6 +2,8 @@ module FeedCache
2
2
  DEFAULT_ENTRIES_LIMIT = 10
3
3
  DEFAULT_EXPIRES_IN = 900
4
4
 
5
+ class MissingEntries < StandardError; end
6
+
5
7
  class << self
6
8
  attr_accessor :cache
7
9
  attr_writer :default_entries_limit, :default_expires_in
@@ -28,8 +30,12 @@ module FeedCache
28
30
 
29
31
  def self.entries_for(url, options = {})
30
32
  limit = options.delete(:limit) || default_entries_limit
31
- feed = fetch(url, options)
32
- (feed ? feed.entries : []).take(limit)
33
+ begin
34
+ feed = fetch(url, options)
35
+ (feed ? feed.entries : []).take(limit)
36
+ rescue TypeError
37
+ raise FeedCache::MissingEntries
38
+ end
33
39
  end
34
40
  end
35
41
 
@@ -1,3 +1,3 @@
1
1
  module FeedCache
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -9,14 +9,29 @@ describe FeedCache do
9
9
  let(:blog_feed) { YAML.load_file(File.join File.dirname(__FILE__), "./fixtures/blog_feed.yaml") }
10
10
  let(:cache) { ActiveSupport::Cache::MemoryStore.new }
11
11
 
12
- before do
12
+ def stub_feedzirra
13
13
  Feedzirra::Feed.stub(:fetch_and_parse).with(blog_url).and_return(blog_feed)
14
+ end
15
+
16
+ def unstub_feedzirra
17
+ begin
18
+ Feedzirra::Feed.unstub(:fetch_and_parse)
19
+ rescue RSpec::Mocks::MockExpectationError => e
20
+ $stderr.puts e.message
21
+ end
22
+ end
23
+
24
+ before do
14
25
  FeedCache.configure do |fc|
15
26
  fc.cache = cache
16
27
  end
17
28
  end
18
29
 
30
+ after { unstub_feedzirra }
31
+
19
32
  describe "fetching a feed" do
33
+ before { stub_feedzirra }
34
+
20
35
  context "for a valid feed grab" do
21
36
  it "returns the feed with entries" do
22
37
  feed = FeedCache.fetch(blog_url)
@@ -39,6 +54,8 @@ describe FeedCache do
39
54
  end
40
55
 
41
56
  describe "getting just the entries for a feed" do
57
+ before { stub_feedzirra }
58
+
42
59
  context "for a valid feed grab" do
43
60
  it "returns the entries array" do
44
61
  FeedCache.entries_for(blog_url).length.should == 10
@@ -60,5 +77,19 @@ describe FeedCache do
60
77
  FeedCache.entries_for(blog_url).should == []
61
78
  end
62
79
  end
80
+
81
+ # There's a bug where TypeError is raised, but I can't replicated it
82
+ # by using FakeWeb, so I want to cover it with an explicit raise for now
83
+ context "for a feed that raises TypeError when fetching entries" do
84
+ let(:no_entry_feed_url) { "http://example.com/no_entry_feed.xml" }
85
+ let(:no_entry_feed) { File.read(File.join(File.dirname(__FILE__), "./fixtures/no_entry_feed.xml")) }
86
+
87
+ it "raises FeedCache::MissingEntries" do
88
+ Feedzirra::Feed.stub(:fetch_and_parse).and_raise(TypeError)
89
+ lambda {
90
+ FeedCache.entries_for(no_entry_feed_url)
91
+ }.should raise_error(FeedCache::MissingEntries)
92
+ end
93
+ end
63
94
  end
64
95
  end
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
3
+ <channel>
4
+ <title>Recent posts | Kajabi Support</title>
5
+ <description>posts</description>
6
+ <link>http://support.kajabi.com/posts</link>
7
+ <language>en-us</language>
8
+ <ttl>60</ttl>
9
+ <atom:link href="support.kajabi.com/categories/3610-knowledge-base/posts.rss" rel="self" type="application/rss+xml"/>
10
+ </channel>
11
+ </rss>
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: feed_cache
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 0
9
8
  - 1
10
- version: 0.0.1
9
+ - 0
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brendon Murphy
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-12-06 00:00:00 -08:00
18
+ date: 2012-04-04 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -84,6 +84,7 @@ files:
84
84
  - lib/feed_cache/version.rb
85
85
  - spec/feed_cache_spec.rb
86
86
  - spec/fixtures/blog_feed.yaml
87
+ - spec/fixtures/no_entry_feed.xml
87
88
  - spec/spec_helper.rb
88
89
  has_rdoc: true
89
90
  homepage: ""
@@ -122,4 +123,5 @@ summary: A thin wrapper over Feedzirra with injected caching
122
123
  test_files:
123
124
  - spec/feed_cache_spec.rb
124
125
  - spec/fixtures/blog_feed.yaml
126
+ - spec/fixtures/no_entry_feed.xml
125
127
  - spec/spec_helper.rb