Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions app/tasks/fetch_feed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ def fetch
begin
raw_feed = @parser.fetch_and_parse(@feed.url, user_agent: "Stringer", if_modified_since: @feed.last_fetched)

new_entries_from(raw_feed).each do |entry|
StoryRepository.add(entry, @feed)
if raw_feed == 304
@logger.info "Feed has not been modified since last fetch"
else
new_entries_from(raw_feed).each do |entry|
StoryRepository.add(entry, @feed)
end
end

FeedRepository.update_last_fetched(@feed, raw_feed.last_modified)
Expand Down
16 changes: 13 additions & 3 deletions spec/tasks/fetch_feed_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
describe FetchFeed do
describe "#fetch" do
let(:daring_fireball) do
stub(url: "http://daringfireball.com/feed",
stub(url: "http://daringfireball.com/feed",
last_fetched: Time.new(2013,1,1),
stories: [])
end
Expand All @@ -15,6 +15,16 @@
FeedRepository.stub(:set_status)
end

context "when feed has not been modified" do
it "should not try to fetch posts" do
parser = stub(fetch_and_parse: 304)

StoryRepository.should_not_receive(:add)

FetchFeed.new(daring_fireball, parser)
end
end

context "when no new posts have been added" do
it "should not add any new posts" do
fake_feed = stub(last_modified: Time.new(2012, 12, 31))
Expand Down Expand Up @@ -66,12 +76,12 @@

it "sets the status to red if things go wrong" do
parser = stub(fetch_and_parse: 404)

FeedRepository.should_receive(:set_status)
.with(:red, daring_fireball)

FetchFeed.new(daring_fireball, parser).fetch
end
end
end
end
end