jonleighton-bcms_feeds 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/app/models/feed.rb +4 -2
- data/test/unit/feed_test.rb +7 -5
- metadata +2 -2
data/app/models/feed.rb
CHANGED
@@ -17,9 +17,11 @@ class Feed < ActiveRecord::Base
|
|
17
17
|
if expires_at.nil? || expires_at < Time.now.utc
|
18
18
|
begin
|
19
19
|
self.expires_at = Time.now.utc + TTL
|
20
|
-
|
20
|
+
new_contents = remote_contents
|
21
|
+
SimpleRSS.parse(new_contents) # Check that we can actually parse it
|
22
|
+
write_attribute(:contents, new_contents)
|
21
23
|
save
|
22
|
-
rescue StandardError, Timeout::Error => exception
|
24
|
+
rescue StandardError, Timeout::Error, SimpleRSSError => exception
|
23
25
|
logger.error("Loading feed #{url} failed with #{exception.inspect}")
|
24
26
|
self.expires_at = Time.now.utc + TTL_ON_ERROR
|
25
27
|
save
|
data/test/unit/feed_test.rb
CHANGED
@@ -29,16 +29,18 @@ class FeedTest < ActiveSupport::TestCase
|
|
29
29
|
|
30
30
|
test "contents with no expiry should return the remote contents and save it" do
|
31
31
|
@feed.expires_at = nil
|
32
|
-
|
32
|
+
should_get_remote_contents_and_parse
|
33
33
|
end
|
34
34
|
|
35
35
|
test "contents with an expiry in the past return the remote contents and save it" do
|
36
36
|
@feed.expires_at = Time.now - 1.hour
|
37
|
-
|
37
|
+
should_get_remote_contents_and_parse
|
38
38
|
end
|
39
39
|
|
40
|
-
def
|
40
|
+
def should_get_remote_contents_and_parse
|
41
41
|
@feed.stubs(:remote_contents).returns(@contents)
|
42
|
+
SimpleRSS.expects(:parse).with(@contents)
|
43
|
+
|
42
44
|
assert_equal @contents, @feed.contents
|
43
45
|
@feed.reload
|
44
46
|
assert_equal @contents, @feed.read_attribute(:contents)
|
@@ -55,8 +57,8 @@ class FeedTest < ActiveSupport::TestCase
|
|
55
57
|
assert_equal @contents, @feed.contents
|
56
58
|
end
|
57
59
|
|
58
|
-
test "TTL of cached contents should be extended if there is an error fetching the remote contents" do
|
59
|
-
[StandardError, Timeout::Error].each do |exception|
|
60
|
+
test "TTL of cached contents should be extended if there is an error fetching the remote contents, or parsing the feed" do
|
61
|
+
[StandardError, Timeout::Error, SimpleRSSError].each do |exception|
|
60
62
|
@feed.expires_at = Time.now - 1.hour
|
61
63
|
@feed.stubs(:remote_contents).raises(exception)
|
62
64
|
@feed.write_attribute(:contents, @contents)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jonleighton-bcms_feeds
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Leighton
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-08-
|
12
|
+
date: 2009-08-16 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|