Permalink
Browse files

be a new entry if feed not have entry id and only difference is a url

  • Loading branch information...
1 parent 6e075a8 commit 293b49a59c4258f59b7ca131554f38fcc2379181 @taketin taketin committed Feb 2, 2014
Showing with 30 additions and 10 deletions.
  1. +5 −1 lib/feedzirra/feed_utilities.rb
  2. +25 −9 spec/feedzirra/feed_utilities_spec.rb
View
6 lib/feedzirra/feed_utilities.rb
@@ -86,7 +86,11 @@ def find_new_entries_for(feed)
latest_entry = self.entries.first
found_new_entries = []
feed.entries.each do |entry|
- break if entry.entry_id == latest_entry.entry_id || entry.url == latest_entry.url
+ if entry.entry_id.nil? && latest_entry.entry_id.nil?
+ break if entry.url == latest_entry.url
+ else
+ break if entry.entry_id == latest_entry.entry_id || entry.url == latest_entry.url
+ end
found_new_entries << entry
end
found_new_entries
View
34 spec/feedzirra/feed_utilities_spec.rb
@@ -169,7 +169,10 @@
end
end
- describe "changing the url of an existing entry" do
+ describe "#update_from_feed" do
+ let(:recent_entry_id) { 'entry_id' }
+ let(:old_entry_id) { nil }
+
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.
@@ -182,11 +185,12 @@
@old_entry = Feedzirra::Parser::AtomEntry.new
@old_entry.url = "http://pauldix.net/old.html"
+ @old_entry.entry_id = old_entry_id
@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.entry_id = recent_entry_id
@entry.url = "http://pauldix.net/entry.html"
# only difference is a changed url
@@ -200,15 +204,27 @@
@updated_feed.entries << @old_entry
end
- it "should not put the complete feed into new_entries" do
- @feed.update_from_feed(@updated_feed)
+ context "changing the url of an existing entry" do
+ 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)
+ @feed.new_entries.size.should == 0
+ @feed.new_entries.size.should_not == 2
+ end
+ end
- @feed.new_entries.should_not include(@entry_changed_url)
- @feed.new_entries.should_not include(@old_entry)
+ context "feed not have entry id and only difference is a url" do
+ let(:recent_entry_id) { nil }
+ let(:old_entry_id) { nil }
- # don't return complete feed
- @feed.new_entries.size.should == 0
- @feed.new_entries.size.should_not == 2
+ it "should put the complete feed into new_entries" do
+ @feed.update_from_feed(@updated_feed)
+ @feed.new_entries.should include(@entry_changed_url)
+ @feed.new_entries.should include(@old_entry)
+ @feed.new_entries.size.should == 2
+ @feed.new_entries.size.should_not == 0
+ end
end
end

0 comments on commit 293b49a

Please sign in to comment.