Permalink
Browse files

Merge pull request #131 from bhaak/fix_new_entries_by_using_id

Fix: not getting entire feed on url change
  • Loading branch information...
2 parents 9681b63 + ef09a50 commit 71721ddaeba18383ae283600b6a2eb8a717d7b58 @pauldix pauldix committed Jan 4, 2013
Showing with 48 additions and 5 deletions.
  1. +4 −4 lib/feedzirra/feed_utilities.rb
  2. +44 −1 spec/feedzirra/feed_utilities_spec.rb
@@ -54,19 +54,19 @@ def find_new_entries_for(feed)
# it's to get around the fact that not all feeds have a published date.
# however, they're always ordered with the newest one first.
# So we go through the entries just parsed and insert each one as a new entry
- # until we get to one that has the same url as the the newest for the feed
+ # until we get to one that has the same id as the the newest for the feed
return feed.entries if self.entries.length == 0
latest_entry = self.entries.first
found_new_entries = []
feed.entries.each do |entry|
- break if entry.url == latest_entry.url
+ break if entry.id == latest_entry.id
found_new_entries << entry
end
found_new_entries
end
def existing_entry?(test_entry)
- entries.any? { |entry| entry.url == test_entry.url }
+ entries.any? { |entry| entry.id == test_entry.id }
end
end
-end
+end
@@ -146,5 +146,48 @@
@feed.entries.should include(@old_entry)
end
end
+
+ describe "changing the url of an existing entry" do
+ before(:each) do
+ # I'm using the Atom class when I know I should be using a different one. However, this update_from_feed
+ # method would only be called against a feed item.
+ @feed = Feedzirra::Parser::Atom.new
+ @feed.title = "A title"
+ @feed.url = "http://pauldix.net"
+ @feed.feed_url = "http://feeds.feedburner.com/PaulDixExplainsNothing"
+ @feed.updated = false
+ @updated_feed = @feed.dup
+
+ @old_entry = Feedzirra::Parser::AtomEntry.new
+ @old_entry.url = "http://pauldix.net/old.html"
+ @old_entry.published = (Time.now - 10).to_s
+
+ @entry = Feedzirra::Parser::AtomEntry.new
+ @entry.published = (Time.now + 10).to_s
+ @entry.entry_id = "entry_id"
+ @entry.url = "http://pauldix.net/entry.html"
+
+ # only difference is a changed url
+ @entry_changed_url = @entry.dup
+ @entry_changed_url.url = "http://pauldix.net/updated.html"
+
+ # entry with changed url must be first
+ @feed.entries << @entry
+ @feed.entries << @old_entry
+ @updated_feed.entries << @entry_changed_url
+ @updated_feed.entries << @old_entry
+ end
+
+ it "should not put the complete feed into new_entries" do
+ @feed.update_from_feed(@updated_feed)
+
+ @feed.new_entries.should_not include(@entry_changed_url)
+ @feed.new_entries.should_not include(@old_entry)
+
+ # don't return complete feed
+ @feed.new_entries.size.should == 0
+ @feed.new_entries.size.should_not == 2
+ end
+ end
end
-end
+end

0 comments on commit 71721dd

Please sign in to comment.