Skip to content

Commit

Permalink
accept 304 responses too
Browse files Browse the repository at this point in the history
  • Loading branch information
technoweenie committed Sep 1, 2012
1 parent 219a7d3 commit fccf0e7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ namespace :seinfeld do
user.destroy
end
end

desc "Update the calendar of USER"
task :update => :init do
ENV['FEED_PAGE'] ||= '1'
Expand Down
2 changes: 1 addition & 1 deletion lib/seinfeld/feed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def initialize(login, data, url = nil)
@disabled = false
@login = login.to_s
if data.respond_to?(:body)
if !data.success?
if !(data.success? || data.status == 304)
@disabled = true
@items = []
return
Expand Down
14 changes: 11 additions & 3 deletions test/feed_test.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
require File.join(File.dirname(__FILE__), "test_helper")

class FeedTest < ActiveSupport::TestCase
class Response < Struct.new(:body, :header_values, :error)
class Response < Struct.new(:body, :header_values, :status)
def headers
self.header_values ||= {}
end

def success?
!error
!status
end
end

Expand Down Expand Up @@ -38,8 +38,15 @@ def success?
assert_equal 9, feed.items.size
end

test "parses from Faraday 304 Response" do
res = Response.new(data, nil, 304)
feed = Seinfeld::Feed.new :technoweenie, res
assert !feed.disabled?
assert_equal 9, feed.items.size
end

test "disables 404 response" do
res = Response.new(data, nil, true)
res = Response.new(data, nil, 404)
feed = Seinfeld::Feed.new :technoweenie, res
assert feed.disabled?
assert_equal 0, feed.items.size
Expand All @@ -58,3 +65,4 @@ def success?
Date.civil(2009, 12, 12)], @feed.committed_days
end
end

0 comments on commit fccf0e7

Please sign in to comment.