Commit 2ab03d08ebbce1fc7c04c0ed823180b1d75f1a1f
1 parent
52142058
Exists in
master
and in
23 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,9 +19,15 @@ class ExternalFeed < ActiveRecord::Base | ||
| 19 | article.valid? | 19 | article.valid? |
| 20 | end | 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 | def clear | 27 | def clear |
| 23 | # do nothing | 28 | # do nothing |
| 24 | end | 29 | end |
| 30 | + | ||
| 25 | def finish_fetch | 31 | def finish_fetch |
| 26 | if self.only_once && self.update_errors.zero? | 32 | if self.only_once && self.update_errors.zero? |
| 27 | self.enabled = false | 33 | self.enabled = false |
test/unit/external_feed_test.rb
| @@ -83,6 +83,7 @@ class ExternalFeedTest < ActiveSupport::TestCase | @@ -83,6 +83,7 @@ class ExternalFeedTest < ActiveSupport::TestCase | ||
| 83 | should 'have empty fetch date by default' do | 83 | should 'have empty fetch date by default' do |
| 84 | assert_nil ExternalFeed.new.fetched_at | 84 | assert_nil ExternalFeed.new.fetched_at |
| 85 | end | 85 | end |
| 86 | + | ||
| 86 | should 'set fetch date when finishing fetch' do | 87 | should 'set fetch date when finishing fetch' do |
| 87 | feed = ExternalFeed.new | 88 | feed = ExternalFeed.new |
| 88 | feed.stubs(:save!) | 89 | feed.stubs(:save!) |
| @@ -90,6 +91,16 @@ class ExternalFeedTest < ActiveSupport::TestCase | @@ -90,6 +91,16 @@ class ExternalFeedTest < ActiveSupport::TestCase | ||
| 90 | assert_not_nil feed.fetched_at | 91 | assert_not_nil feed.fetched_at |
| 91 | end | 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 | should 'expire feeds after a certain period' do | 104 | should 'expire feeds after a certain period' do |
| 94 | # save current time | 105 | # save current time |
| 95 | now = Time.now | 106 | now = Time.now |