Commit 2ab03d08ebbce1fc7c04c0ed823180b1d75f1a1f
1 parent
52142058
Exists in
master
and in
28 other branches
Fixes delayed feed fetch after change address
Sets fetched_at to nil after change external feed address so the feed is fetched right after the address change and without waiting the feed to be expired.
Showing
2 changed files
with
17 additions
and
0 deletions
Show diff stats
app/models/external_feed.rb
... | ... | @@ -19,9 +19,15 @@ class ExternalFeed < ActiveRecord::Base |
19 | 19 | article.valid? |
20 | 20 | end |
21 | 21 | |
22 | + def address=(new_address) | |
23 | + self.fetched_at = nil unless address == new_address | |
24 | + super(new_address) | |
25 | + end | |
26 | + | |
22 | 27 | def clear |
23 | 28 | # do nothing |
24 | 29 | end |
30 | + | |
25 | 31 | def finish_fetch |
26 | 32 | if self.only_once && self.update_errors.zero? |
27 | 33 | self.enabled = false | ... | ... |
test/unit/external_feed_test.rb
... | ... | @@ -83,6 +83,7 @@ class ExternalFeedTest < ActiveSupport::TestCase |
83 | 83 | should 'have empty fetch date by default' do |
84 | 84 | assert_nil ExternalFeed.new.fetched_at |
85 | 85 | end |
86 | + | |
86 | 87 | should 'set fetch date when finishing fetch' do |
87 | 88 | feed = ExternalFeed.new |
88 | 89 | feed.stubs(:save!) |
... | ... | @@ -90,6 +91,16 @@ class ExternalFeedTest < ActiveSupport::TestCase |
90 | 91 | assert_not_nil feed.fetched_at |
91 | 92 | end |
92 | 93 | |
94 | + should 'have empty fetch when change address' do | |
95 | + feed = ExternalFeed.new | |
96 | + feed.stubs(:save!) | |
97 | + feed.address = 'http://localhost/example_feed' | |
98 | + feed.finish_fetch | |
99 | + assert_not_nil feed.fetched_at | |
100 | + feed.address = 'http://localhost/other_example_feed' | |
101 | + assert_nil feed.fetched_at | |
102 | + end | |
103 | + | |
93 | 104 | should 'expire feeds after a certain period' do |
94 | 105 | # save current time |
95 | 106 | now = Time.now | ... | ... |