feedzirra 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +3 -1
- data/.travis.yml +3 -3
- data/{HISTORY.md → CHANGELOG.md} +32 -7
- data/Gemfile +4 -1
- data/Guardfile +0 -1
- data/README.md +102 -87
- data/Rakefile +1 -1
- data/feedzirra.gemspec +2 -1
- data/lib/feedzirra/core_ext/date.rb +1 -1
- data/lib/feedzirra/core_ext/string.rb +2 -2
- data/lib/feedzirra/feed.rb +16 -16
- data/lib/feedzirra/feed_entry_utilities.rb +5 -5
- data/lib/feedzirra/parser/atom_entry.rb +2 -2
- data/lib/feedzirra/parser/atom_feed_burner.rb +1 -1
- data/lib/feedzirra/parser/atom_feed_burner_entry.rb +2 -2
- data/lib/feedzirra/parser/google_docs_atom_entry.rb +1 -1
- data/lib/feedzirra/parser/itunes_rss_item.rb +2 -2
- data/lib/feedzirra/parser/itunes_rss_owner.rb +3 -3
- data/lib/feedzirra/parser/rss.rb +1 -1
- data/lib/feedzirra/parser/rss_entry.rb +7 -6
- data/lib/feedzirra/parser/rss_feed_burner.rb +1 -1
- data/lib/feedzirra/parser/rss_feed_burner_entry.rb +1 -1
- data/lib/feedzirra/parser.rb +1 -1
- data/lib/feedzirra/version.rb +1 -1
- data/lib/feedzirra.rb +1 -1
- data/spec/benchmarks/feed_benchmarks.rb +7 -7
- data/spec/benchmarks/feedzirra_benchmarks.rb +1 -1
- data/spec/benchmarks/fetching_benchmarks.rb +3 -3
- data/spec/benchmarks/parsing_benchmark.rb +1 -1
- data/spec/benchmarks/updating_benchmarks.rb +6 -6
- data/spec/feedzirra/feed_entry_utilities_spec.rb +11 -7
- data/spec/feedzirra/feed_spec.rb +85 -85
- data/spec/feedzirra/feed_utilities_spec.rb +22 -22
- data/spec/feedzirra/parser/atom_entry_spec.rb +1 -1
- data/spec/feedzirra/parser/atom_feed_burner_entry_spec.rb +7 -7
- data/spec/feedzirra/parser/atom_feed_burner_spec.rb +7 -7
- data/spec/feedzirra/parser/atom_spec.rb +9 -9
- data/spec/feedzirra/parser/itunes_rss_item_spec.rb +11 -11
- data/spec/feedzirra/parser/itunes_rss_owner_spec.rb +4 -4
- data/spec/feedzirra/parser/itunes_rss_spec.rb +8 -8
- data/spec/feedzirra/parser/rss_feed_burner_entry_spec.rb +1 -1
- data/spec/feedzirra/parser/rss_feed_burner_spec.rb +8 -8
- data/spec/feedzirra/parser/rss_spec.rb +6 -6
- data/spec/spec_helper.rb +4 -3
- metadata +10 -21
data/spec/feedzirra/feed_spec.rb
CHANGED
@@ -24,20 +24,20 @@ describe Feedzirra::Feed do
|
|
24
24
|
before(:all) do
|
25
25
|
Feedzirra::Feed.add_common_feed_entry_element("wfw:commentRss", :as => :comment_rss)
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
it "should parse the added element out of Atom feeds entries" do
|
29
29
|
Feedzirra::Feed.parse(sample_wfw_feed).entries.first.comment_rss.should == "this is the new val"
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
it "should parse the added element out of Atom Feedburner feeds entries" do
|
33
33
|
Feedzirra::Parser::AtomEntry.new.should respond_to(:comment_rss)
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
it "should parse the added element out of RSS feeds entries" do
|
37
37
|
Feedzirra::Parser::RSSEntry.new.should respond_to(:comment_rss)
|
38
38
|
end
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
describe "#parse" do # many of these tests are redundant with the specific feed type tests, but I put them here for completeness
|
42
42
|
context "when there's an available parser" do
|
43
43
|
it "should parse an rdf feed" do
|
@@ -66,7 +66,7 @@ describe Feedzirra::Feed do
|
|
66
66
|
feed.title.should == "Paul Dix Explains Nothing"
|
67
67
|
feed.entries.first.published.should == Time.parse_safely("Thu Jan 22 15:50:22 UTC 2009")
|
68
68
|
feed.entries.size.should == 5
|
69
|
-
end
|
69
|
+
end
|
70
70
|
|
71
71
|
it "should parse an itunes feed" do
|
72
72
|
feed = Feedzirra::Feed.parse(sample_itunes_feed)
|
@@ -126,13 +126,13 @@ describe Feedzirra::Feed do
|
|
126
126
|
describe "when adding feed types" do
|
127
127
|
it "should prioritize added types over the built in ones" do
|
128
128
|
feed_text = "Atom asdf"
|
129
|
-
Feedzirra::Parser::Atom.stub
|
129
|
+
Feedzirra::Parser::Atom.stub(:able_to_parse?).and_return(true)
|
130
130
|
new_feed_type = Class.new do
|
131
131
|
def self.able_to_parse?(val)
|
132
132
|
true
|
133
133
|
end
|
134
134
|
end
|
135
|
-
|
135
|
+
|
136
136
|
new_feed_type.should be_able_to_parse(feed_text)
|
137
137
|
Feedzirra::Feed.add_feed_class(new_feed_type)
|
138
138
|
Feedzirra::Feed.determine_feed_parser_for_xml(feed_text).should == new_feed_type
|
@@ -179,14 +179,14 @@ describe Feedzirra::Feed do
|
|
179
179
|
|
180
180
|
describe "#fetch_raw" do
|
181
181
|
before(:each) do
|
182
|
-
@cmock =
|
183
|
-
@multi =
|
184
|
-
@curl_easy =
|
185
|
-
@curl =
|
186
|
-
@curl.stub
|
187
|
-
|
188
|
-
Curl::Multi.stub
|
189
|
-
Curl::Easy.stub
|
182
|
+
@cmock = double('cmock', :header_str => '', :body_str => @paul_feed[:xml] )
|
183
|
+
@multi = double('curl_multi', :add => true, :perform => true)
|
184
|
+
@curl_easy = double('curl_easy')
|
185
|
+
@curl = double('curl', :headers => {}, :follow_location= => true, :on_failure => true)
|
186
|
+
@curl.stub(:on_success).and_yield(@cmock)
|
187
|
+
|
188
|
+
Curl::Multi.stub(:new).and_return(@multi)
|
189
|
+
Curl::Easy.stub(:new).and_yield(@curl).and_return(@curl_easy)
|
190
190
|
end
|
191
191
|
|
192
192
|
it "should set user agent if it's passed as an option" do
|
@@ -198,7 +198,7 @@ describe Feedzirra::Feed do
|
|
198
198
|
Feedzirra::Feed.fetch_raw(@paul_feed[:url])
|
199
199
|
@curl.headers['User-Agent'].should == Feedzirra::Feed::USER_AGENT
|
200
200
|
end
|
201
|
-
|
201
|
+
|
202
202
|
it "should set if modified since as an option if passed" do
|
203
203
|
Feedzirra::Feed.fetch_raw(@paul_feed[:url], :if_modified_since => Time.parse_safely("Wed, 28 Jan 2009 04:10:32 GMT"))
|
204
204
|
@curl.headers["If-Modified-Since"].should == 'Wed, 28 Jan 2009 04:10:32 GMT'
|
@@ -208,7 +208,7 @@ describe Feedzirra::Feed do
|
|
208
208
|
Feedzirra::Feed.fetch_raw(@paul_feed[:url], :if_none_match => 'ziEyTl4q9GH04BR4jgkImd0GvSE')
|
209
209
|
@curl.headers["If-None-Match"].should == 'ziEyTl4q9GH04BR4jgkImd0GvSE'
|
210
210
|
end
|
211
|
-
|
211
|
+
|
212
212
|
it 'should set userpwd for http basic authentication if :http_authentication is passed' do
|
213
213
|
@curl.should_receive(:userpwd=).with('username:password')
|
214
214
|
Feedzirra::Feed.fetch_raw(@paul_feed[:url], :http_authentication => ['username', 'password'])
|
@@ -224,21 +224,21 @@ describe Feedzirra::Feed do
|
|
224
224
|
end
|
225
225
|
|
226
226
|
it "should take multiple feed urls and return a hash of urls and response xml" do
|
227
|
-
multi =
|
228
|
-
Curl::Multi.stub
|
229
|
-
|
230
|
-
paul_response =
|
231
|
-
trotter_response =
|
232
|
-
|
233
|
-
paul_curl =
|
234
|
-
paul_curl.stub
|
235
|
-
|
236
|
-
trotter_curl =
|
237
|
-
trotter_curl.stub
|
238
|
-
|
227
|
+
multi = double('curl_multi', :add => true, :perform => true)
|
228
|
+
Curl::Multi.stub(:new).and_return(multi)
|
229
|
+
|
230
|
+
paul_response = double('paul_response', :header_str => '', :body_str => @paul_feed[:xml] )
|
231
|
+
trotter_response = double('trotter_response', :header_str => '', :body_str => @trotter_feed[:xml] )
|
232
|
+
|
233
|
+
paul_curl = double('paul_curl', :headers => {}, :follow_location= => true, :on_failure => true)
|
234
|
+
paul_curl.stub(:on_success).and_yield(paul_response)
|
235
|
+
|
236
|
+
trotter_curl = double('trotter_curl', :headers => {}, :follow_location= => true, :on_failure => true)
|
237
|
+
trotter_curl.stub(:on_success).and_yield(trotter_response)
|
238
|
+
|
239
239
|
Curl::Easy.should_receive(:new).with(@paul_feed[:url]).ordered.and_yield(paul_curl)
|
240
240
|
Curl::Easy.should_receive(:new).with(@trotter_feed[:url]).ordered.and_yield(trotter_curl)
|
241
|
-
|
241
|
+
|
242
242
|
results = Feedzirra::Feed.fetch_raw([@paul_feed[:url], @trotter_feed[:url]])
|
243
243
|
results.keys.should include(@paul_feed[:url])
|
244
244
|
results.keys.should include(@trotter_feed[:url])
|
@@ -256,9 +256,9 @@ describe Feedzirra::Feed do
|
|
256
256
|
before(:each) do
|
257
257
|
allow_message_expectations_on_nil
|
258
258
|
@multi = Curl::Multi.get([@paul_feed[:url]], {:follow_location => true}, {:pipeline => true})
|
259
|
-
@multi.stub
|
259
|
+
@multi.stub(:add)
|
260
260
|
@easy_curl = Curl::Easy.new(@paul_feed[:url])
|
261
|
-
|
261
|
+
|
262
262
|
Curl::Easy.should_receive(:new).and_yield(@easy_curl)
|
263
263
|
end
|
264
264
|
|
@@ -266,12 +266,12 @@ describe Feedzirra::Feed do
|
|
266
266
|
Feedzirra::Feed.add_url_to_multi(@multi, @paul_feed[:url], [], {}, :user_agent => 'My cool application')
|
267
267
|
@easy_curl.headers["User-Agent"].should == 'My cool application'
|
268
268
|
end
|
269
|
-
|
269
|
+
|
270
270
|
it "should set user agent to default if it's not passed as an option" do
|
271
271
|
Feedzirra::Feed.add_url_to_multi(@multi, @paul_feed[:url], [], {}, {})
|
272
272
|
@easy_curl.headers["User-Agent"].should == Feedzirra::Feed::USER_AGENT
|
273
273
|
end
|
274
|
-
|
274
|
+
|
275
275
|
it "should set if modified since as an option if passed" do
|
276
276
|
Feedzirra::Feed.add_url_to_multi(@multi, @paul_feed[:url], [], {}, :if_modified_since => Time.parse_safely("Jan 25 2009 04:10:32 GMT"))
|
277
277
|
@easy_curl.headers["If-Modified-Since"].should == 'Sun, 25 Jan 2009 04:10:32 GMT'
|
@@ -281,12 +281,12 @@ describe Feedzirra::Feed do
|
|
281
281
|
@easy_curl.should_receive(:follow_location=).with(true)
|
282
282
|
Feedzirra::Feed.add_url_to_multi(@multi, @paul_feed[:url], [], {}, {})
|
283
283
|
end
|
284
|
-
|
284
|
+
|
285
285
|
it 'should set userpwd for http basic authentication if :http_authentication is passed' do
|
286
286
|
Feedzirra::Feed.add_url_to_multi(@multi, @paul_feed[:url], [], {}, :http_authentication => ['myusername', 'mypassword'])
|
287
287
|
@easy_curl.userpwd.should == 'myusername:mypassword'
|
288
288
|
end
|
289
|
-
|
289
|
+
|
290
290
|
it 'should set accepted encodings' do
|
291
291
|
Feedzirra::Feed.add_url_to_multi(@multi, @paul_feed[:url], [], {}, {:compress => true})
|
292
292
|
@easy_curl.headers["Accept-encoding"].should == 'gzip, deflate'
|
@@ -296,15 +296,15 @@ describe Feedzirra::Feed do
|
|
296
296
|
Feedzirra::Feed.add_url_to_multi(@multi, @paul_feed[:url], [], {}, :if_none_match => 'ziEyTl4q9GH04BR4jgkImd0GvSE')
|
297
297
|
@easy_curl.headers["If-None-Match"].should == 'ziEyTl4q9GH04BR4jgkImd0GvSE'
|
298
298
|
end
|
299
|
-
|
299
|
+
|
300
300
|
describe 'on success' do
|
301
301
|
before(:each) do
|
302
|
-
@feed =
|
303
|
-
Feedzirra::Feed.stub
|
304
|
-
Feedzirra::Feed.stub
|
305
|
-
Feedzirra::Parser::AtomFeedBurner.stub
|
306
|
-
Feedzirra::Feed.stub
|
307
|
-
Feedzirra::Feed.stub
|
302
|
+
@feed = double('feed', :feed_url= => true, :etag= => true, :last_modified= => true)
|
303
|
+
Feedzirra::Feed.stub(:decode_content).and_return(@paul_feed[:xml])
|
304
|
+
Feedzirra::Feed.stub(:determine_feed_parser_for_xml).and_return(Feedzirra::Parser::AtomFeedBurner)
|
305
|
+
Feedzirra::Parser::AtomFeedBurner.stub(:parse).and_return(@feed)
|
306
|
+
Feedzirra::Feed.stub(:etag_from_header).and_return('ziEyTl4q9GH04BR4jgkImd0GvSE')
|
307
|
+
Feedzirra::Feed.stub(:last_modified_from_header).and_return('Wed, 28 Jan 2009 04:10:32 GMT')
|
308
308
|
end
|
309
309
|
|
310
310
|
it 'should decode the response body' do
|
@@ -312,7 +312,7 @@ describe Feedzirra::Feed do
|
|
312
312
|
Feedzirra::Feed.add_url_to_multi(@multi, @paul_feed[:url], [], {}, {})
|
313
313
|
@easy_curl.on_success.call(@easy_curl)
|
314
314
|
end
|
315
|
-
|
315
|
+
|
316
316
|
it 'should determine the xml parser class' do
|
317
317
|
Feedzirra::Feed.should_receive(:determine_feed_parser_for_xml).with(@paul_feed[:xml]).and_return(Feedzirra::Parser::AtomFeedBurner)
|
318
318
|
Feedzirra::Feed.add_url_to_multi(@multi, @paul_feed[:url], [], {}, {})
|
@@ -324,7 +324,7 @@ describe Feedzirra::Feed do
|
|
324
324
|
Feedzirra::Feed.add_url_to_multi(@multi, @paul_feed[:url], [], {}, {})
|
325
325
|
@easy_curl.on_success.call(@easy_curl)
|
326
326
|
end
|
327
|
-
|
327
|
+
|
328
328
|
describe 'when a compatible xml parser class is found' do
|
329
329
|
it 'should set the last effective url to the feed url' do
|
330
330
|
@easy_curl.should_receive(:last_effective_url).and_return(@paul_feed[:url])
|
@@ -349,11 +349,11 @@ describe Feedzirra::Feed do
|
|
349
349
|
responses = {}
|
350
350
|
Feedzirra::Feed.add_url_to_multi(@multi, @paul_feed[:url], [], responses, {})
|
351
351
|
@easy_curl.on_success.call(@easy_curl)
|
352
|
-
|
352
|
+
|
353
353
|
responses.length.should == 1
|
354
354
|
responses['http://feeds.feedburner.com/PaulDixExplainsNothing'].should == @feed
|
355
355
|
end
|
356
|
-
|
356
|
+
|
357
357
|
it 'should call proc if :on_success option is passed' do
|
358
358
|
success = lambda { |url, feed| }
|
359
359
|
success.should_receive(:call).with(@paul_feed[:url], @feed)
|
@@ -372,9 +372,9 @@ describe Feedzirra::Feed do
|
|
372
372
|
@headers = "HTTP/1.0 500 Something Bad\r\nDate: Thu, 29 Jan 2009 03:55:24 GMT\r\nServer: Apache\r\nX-FB-Host: chi-write6\r\nLast-Modified: Wed, 28 Jan 2009 04:10:32 GMT\r\n"
|
373
373
|
@body = 'Sorry, something broke'
|
374
374
|
|
375
|
-
@easy_curl.stub
|
376
|
-
@easy_curl.stub
|
377
|
-
@easy_curl.stub
|
375
|
+
@easy_curl.stub(:response_code).and_return(500)
|
376
|
+
@easy_curl.stub(:header_str).and_return(@headers)
|
377
|
+
@easy_curl.stub(:body_str).and_return(@body)
|
378
378
|
end
|
379
379
|
|
380
380
|
it 'should call proc if :on_failure option is passed' do
|
@@ -383,7 +383,7 @@ describe Feedzirra::Feed do
|
|
383
383
|
Feedzirra::Feed.add_url_to_multi(@multi, @paul_feed[:url], [], {}, { :on_failure => failure })
|
384
384
|
@easy_curl.on_failure.call(@easy_curl)
|
385
385
|
end
|
386
|
-
|
386
|
+
|
387
387
|
it 'should return the http code in the responses' do
|
388
388
|
responses = {}
|
389
389
|
Feedzirra::Feed.add_url_to_multi(@multi, @paul_feed[:url], [], responses, {})
|
@@ -399,9 +399,9 @@ describe Feedzirra::Feed do
|
|
399
399
|
@headers = "HTTP/1.0 404 Not Found\r\nDate: Thu, 29 Jan 2009 03:55:24 GMT\r\nServer: Apache\r\nX-FB-Host: chi-write6\r\nLast-Modified: Wed, 28 Jan 2009 04:10:32 GMT\r\n"
|
400
400
|
@body = 'Page could not be found.'
|
401
401
|
|
402
|
-
@easy_curl.stub
|
403
|
-
@easy_curl.stub
|
404
|
-
@easy_curl.stub
|
402
|
+
@easy_curl.stub(:response_code).and_return(404)
|
403
|
+
@easy_curl.stub(:header_str).and_return(@headers)
|
404
|
+
@easy_curl.stub(:body_str).and_return(@body)
|
405
405
|
end
|
406
406
|
|
407
407
|
it 'should call proc if :on_failure option is passed' do
|
@@ -410,7 +410,7 @@ describe Feedzirra::Feed do
|
|
410
410
|
Feedzirra::Feed.add_url_to_multi(@multi, @paul_feed[:url], [], {}, { :on_failure => complete })
|
411
411
|
@easy_curl.on_complete.call(@easy_curl)
|
412
412
|
end
|
413
|
-
|
413
|
+
|
414
414
|
it 'should return the http code in the responses' do
|
415
415
|
responses = {}
|
416
416
|
Feedzirra::Feed.add_url_to_multi(@multi, @paul_feed[:url], [], responses, {})
|
@@ -426,7 +426,7 @@ describe Feedzirra::Feed do
|
|
426
426
|
before(:each) do
|
427
427
|
allow_message_expectations_on_nil
|
428
428
|
@multi = Curl::Multi.get([@paul_feed[:url]], {:follow_location => true}, {:pipeline => true})
|
429
|
-
@multi.stub
|
429
|
+
@multi.stub(:add)
|
430
430
|
@easy_curl = Curl::Easy.new(@paul_feed[:url])
|
431
431
|
@feed = Feedzirra::Feed.parse(sample_feedburner_atom_feed)
|
432
432
|
|
@@ -437,7 +437,7 @@ describe Feedzirra::Feed do
|
|
437
437
|
Feedzirra::Feed.add_feed_to_multi(@multi, @feed, [], {}, :user_agent => 'My cool application')
|
438
438
|
@easy_curl.headers["User-Agent"].should == 'My cool application'
|
439
439
|
end
|
440
|
-
|
440
|
+
|
441
441
|
it "should set user agent to default if it's not passed as an option" do
|
442
442
|
Feedzirra::Feed.add_feed_to_multi(@multi, @feed, [], {}, {})
|
443
443
|
@easy_curl.headers["User-Agent"].should == Feedzirra::Feed::USER_AGENT
|
@@ -447,10 +447,10 @@ describe Feedzirra::Feed do
|
|
447
447
|
modified_time = Time.parse_safely("Wed, 28 Jan 2009 04:10:32 GMT")
|
448
448
|
Feedzirra::Feed.add_feed_to_multi(@multi, @feed, [], {}, {:if_modified_since => modified_time})
|
449
449
|
modified_time.should be > @feed.last_modified
|
450
|
-
|
450
|
+
|
451
451
|
@easy_curl.headers["If-Modified-Since"].should == modified_time
|
452
452
|
end
|
453
|
-
|
453
|
+
|
454
454
|
it 'should set follow location to true' do
|
455
455
|
@easy_curl.should_receive(:follow_location=).with(true)
|
456
456
|
Feedzirra::Feed.add_feed_to_multi(@multi, @feed, [], {}, {})
|
@@ -470,16 +470,16 @@ describe Feedzirra::Feed do
|
|
470
470
|
describe 'on success' do
|
471
471
|
before(:each) do
|
472
472
|
@new_feed = @feed.clone
|
473
|
-
@feed.stub
|
474
|
-
Feedzirra::Feed.stub
|
475
|
-
Feedzirra::Feed.stub
|
476
|
-
Feedzirra::Parser::AtomFeedBurner.stub
|
477
|
-
Feedzirra::Feed.stub
|
478
|
-
Feedzirra::Feed.stub
|
473
|
+
@feed.stub(:update_from_feed)
|
474
|
+
Feedzirra::Feed.stub(:decode_content).and_return(@paul_feed[:xml])
|
475
|
+
Feedzirra::Feed.stub(:determine_feed_parser_for_xml).and_return(Feedzirra::Parser::AtomFeedBurner)
|
476
|
+
Feedzirra::Parser::AtomFeedBurner.stub(:parse).and_return(@new_feed)
|
477
|
+
Feedzirra::Feed.stub(:etag_from_header).and_return('ziEyTl4q9GH04BR4jgkImd0GvSE')
|
478
|
+
Feedzirra::Feed.stub(:last_modified_from_header).and_return('Wed, 28 Jan 2009 04:10:32 GMT')
|
479
479
|
end
|
480
480
|
|
481
481
|
it 'should process the next feed in the queue'
|
482
|
-
|
482
|
+
|
483
483
|
it 'should parse the updated feed' do
|
484
484
|
Feedzirra::Parser::AtomFeedBurner.should_receive(:parse).and_return(@new_feed)
|
485
485
|
Feedzirra::Feed.add_feed_to_multi(@multi, @feed, [], {}, {})
|
@@ -520,7 +520,7 @@ describe Feedzirra::Feed do
|
|
520
520
|
Feedzirra::Feed.add_feed_to_multi(@multi, @feed, [], {}, { :on_success => success })
|
521
521
|
@easy_curl.on_success.call(@easy_curl)
|
522
522
|
end
|
523
|
-
|
523
|
+
|
524
524
|
it 'should call update from feed on the old feed with the updated feed' do
|
525
525
|
@feed.should_receive(:update_from_feed).with(@new_feed)
|
526
526
|
Feedzirra::Feed.add_feed_to_multi(@multi, @feed, [], {}, {})
|
@@ -533,9 +533,9 @@ describe Feedzirra::Feed do
|
|
533
533
|
@headers = "HTTP/1.0 404 Not Found\r\nDate: Thu, 29 Jan 2009 03:55:24 GMT\r\nServer: Apache\r\nX-FB-Host: chi-write6\r\nLast-Modified: Wed, 28 Jan 2009 04:10:32 GMT\r\n"
|
534
534
|
@body = 'Page could not be found.'
|
535
535
|
|
536
|
-
@easy_curl.stub
|
537
|
-
@easy_curl.stub
|
538
|
-
@easy_curl.stub
|
536
|
+
@easy_curl.stub(:response_code).and_return(404)
|
537
|
+
@easy_curl.stub(:header_str).and_return(@headers)
|
538
|
+
@easy_curl.stub(:body_str).and_return(@body)
|
539
539
|
end
|
540
540
|
|
541
541
|
it 'should call on success callback if the response code is 304' do
|
@@ -545,7 +545,7 @@ describe Feedzirra::Feed do
|
|
545
545
|
Feedzirra::Feed.add_feed_to_multi(@multi, @feed, [], {}, { :on_success => success })
|
546
546
|
@easy_curl.on_failure.call(@easy_curl)
|
547
547
|
end
|
548
|
-
|
548
|
+
|
549
549
|
it 'should return the http code in the responses' do
|
550
550
|
responses = {}
|
551
551
|
Feedzirra::Feed.add_feed_to_multi(@multi, @feed, [], responses, {})
|
@@ -563,51 +563,51 @@ describe Feedzirra::Feed do
|
|
563
563
|
it 'should slice the feeds into groups of thirty for processing'
|
564
564
|
it "should return a feed object if a single feed is passed in"
|
565
565
|
it "should return an return an array of feed objects if multiple feeds are passed in"
|
566
|
-
|
566
|
+
|
567
567
|
it "should set if modified since as an option if passed" do
|
568
568
|
modified_time = Time.parse_safely("Wed, 28 Jan 2009 04:10:32 GMT")
|
569
|
-
Feedzirra::Feed.should_receive(:add_url_to_multi).with(anything, anything, anything, anything, {:if_modified_since => modified_time})
|
570
|
-
|
569
|
+
Feedzirra::Feed.should_receive(:add_url_to_multi).with(anything, anything, anything, anything, {:if_modified_since => modified_time})
|
570
|
+
|
571
571
|
@feed = Feedzirra::Feed.fetch_and_parse(sample_feedburner_atom_feed, {:if_modified_since => modified_time})
|
572
572
|
end
|
573
|
-
|
573
|
+
|
574
574
|
end
|
575
575
|
|
576
576
|
describe "#decode_content" do
|
577
577
|
before(:each) do
|
578
|
-
@curl_easy =
|
578
|
+
@curl_easy = double('curl_easy', :body_str => '<xml></xml>')
|
579
579
|
end
|
580
580
|
|
581
581
|
it 'should decode the response body using gzip if the Content-Encoding: is gzip' do
|
582
|
-
@curl_easy.stub
|
583
|
-
string_io =
|
582
|
+
@curl_easy.stub(:header_str).and_return('Content-Encoding: gzip')
|
583
|
+
string_io = double('stringio', :read => @curl_easy.body_str, :close => true)
|
584
584
|
StringIO.should_receive(:new).and_return(string_io)
|
585
585
|
Zlib::GzipReader.should_receive(:new).with(string_io).and_return(string_io)
|
586
586
|
Feedzirra::Feed.decode_content(@curl_easy)
|
587
587
|
end
|
588
|
-
|
588
|
+
|
589
589
|
it 'should decode the response body using gzip if the Content-Encoding: is gzip even when the case is wrong' do
|
590
|
-
@curl_easy.stub
|
591
|
-
string_io =
|
590
|
+
@curl_easy.stub(:header_str).and_return('content-encoding: gzip')
|
591
|
+
string_io = double('stringio', :read => @curl_easy.body_str, :close => true)
|
592
592
|
StringIO.should_receive(:new).and_return(string_io)
|
593
593
|
Zlib::GzipReader.should_receive(:new).with(string_io).and_return(string_io)
|
594
594
|
Feedzirra::Feed.decode_content(@curl_easy)
|
595
595
|
end
|
596
596
|
|
597
597
|
it 'should deflate the response body using inflate if the Content-Encoding: is deflate' do
|
598
|
-
@curl_easy.stub
|
598
|
+
@curl_easy.stub(:header_str).and_return('Content-Encoding: deflate')
|
599
599
|
Zlib::Inflate.should_receive(:inflate).with(@curl_easy.body_str)
|
600
600
|
Feedzirra::Feed.decode_content(@curl_easy)
|
601
601
|
end
|
602
602
|
|
603
603
|
it 'should deflate the response body using inflate if the Content-Encoding: is deflate event if the case is wrong' do
|
604
|
-
@curl_easy.stub
|
604
|
+
@curl_easy.stub(:header_str).and_return('content-encoding: deflate')
|
605
605
|
Zlib::Inflate.should_receive(:inflate).with(@curl_easy.body_str)
|
606
606
|
Feedzirra::Feed.decode_content(@curl_easy)
|
607
607
|
end
|
608
608
|
|
609
609
|
it 'should return the response body if it is not encoded' do
|
610
|
-
@curl_easy.stub
|
610
|
+
@curl_easy.stub(:header_str).and_return('')
|
611
611
|
Feedzirra::Feed.decode_content(@curl_easy).should == '<xml></xml>'
|
612
612
|
end
|
613
613
|
end
|
@@ -616,7 +616,7 @@ describe Feedzirra::Feed do
|
|
616
616
|
it 'should perform the updating using multicurl'
|
617
617
|
it "should pass any request options through to add_feed_to_multi"
|
618
618
|
it "should return a feed object if a single feed is passed in"
|
619
|
-
it "should return an return an array of feed objects if multiple feeds are passed in"
|
619
|
+
it "should return an return an array of feed objects if multiple feeds are passed in"
|
620
620
|
end
|
621
621
|
end
|
622
622
|
end
|
@@ -14,34 +14,34 @@ describe Feedzirra::FeedUtilities do
|
|
14
14
|
feed.updated = true
|
15
15
|
feed.should be_updated
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
it "should provide a new_entries accessor" do
|
19
19
|
feed = @klass.new
|
20
20
|
feed.new_entries.should == []
|
21
21
|
feed.new_entries = [:foo]
|
22
22
|
feed.new_entries.should == [:foo]
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
it "should provide an etag accessor" do
|
26
26
|
feed = @klass.new
|
27
27
|
feed.etag = "foo"
|
28
28
|
feed.etag.should == "foo"
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
it "should provide a last_modified accessor" do
|
32
32
|
feed = @klass.new
|
33
33
|
time = Time.now
|
34
|
-
feed.last_modified = time
|
34
|
+
feed.last_modified = time
|
35
35
|
feed.last_modified.should == time
|
36
36
|
feed.last_modified.class.should == Time
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
it "should return new_entries? as true when entries are put into new_entries" do
|
40
40
|
feed = @klass.new
|
41
41
|
feed.new_entries << :foo
|
42
42
|
feed.should have_new_entries
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
it "should return a last_modified value from the entry with the most recent published date if the last_modified date hasn't been set" do
|
46
46
|
feed = Feedzirra::Parser::Atom.new
|
47
47
|
entry =Feedzirra::Parser::AtomEntry.new
|
@@ -49,7 +49,7 @@ describe Feedzirra::FeedUtilities do
|
|
49
49
|
feed.entries << entry
|
50
50
|
feed.last_modified.should == entry.published
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
it "should not throw an error if one of the entries has published date of nil" do
|
54
54
|
feed = Feedzirra::Parser::Atom.new
|
55
55
|
entry = Feedzirra::Parser::AtomEntry.new
|
@@ -59,7 +59,7 @@ describe Feedzirra::FeedUtilities do
|
|
59
59
|
feed.last_modified.should == entry.published
|
60
60
|
end
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
describe "#update_from_feed" do
|
64
64
|
describe "updating feed attributes" do
|
65
65
|
before(:each) do
|
@@ -72,43 +72,43 @@ describe Feedzirra::FeedUtilities do
|
|
72
72
|
@feed.updated = false
|
73
73
|
@updated_feed = @feed.dup
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
it "should update the title if changed" do
|
77
77
|
@updated_feed.title = "new title"
|
78
78
|
@feed.update_from_feed(@updated_feed)
|
79
79
|
@feed.title.should == @updated_feed.title
|
80
80
|
@feed.should be_updated
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
83
|
it "should not update the title if the same" do
|
84
84
|
@feed.update_from_feed(@updated_feed)
|
85
|
-
@feed.should_not be_updated
|
85
|
+
@feed.should_not be_updated
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
it "should update the feed_url if changed" do
|
89
89
|
@updated_feed.feed_url = "a new feed url"
|
90
90
|
@feed.update_from_feed(@updated_feed)
|
91
91
|
@feed.feed_url.should == @updated_feed.feed_url
|
92
92
|
@feed.should be_updated
|
93
93
|
end
|
94
|
-
|
94
|
+
|
95
95
|
it "should not update the feed_url if the same" do
|
96
96
|
@feed.update_from_feed(@updated_feed)
|
97
97
|
@feed.should_not be_updated
|
98
98
|
end
|
99
|
-
|
99
|
+
|
100
100
|
it "should update the url if changed" do
|
101
101
|
@updated_feed.url = "a new url"
|
102
102
|
@feed.update_from_feed(@updated_feed)
|
103
103
|
@feed.url.should == @updated_feed.url
|
104
104
|
end
|
105
|
-
|
105
|
+
|
106
106
|
it "should not update the url if not changed" do
|
107
107
|
@feed.update_from_feed(@updated_feed)
|
108
108
|
@feed.should_not be_updated
|
109
109
|
end
|
110
110
|
end
|
111
|
-
|
111
|
+
|
112
112
|
describe "updating entries" do
|
113
113
|
before(:each) do
|
114
114
|
# I'm using the Atom class when I know I should be using a different one. However, this update_from_feed
|
@@ -122,24 +122,24 @@ describe Feedzirra::FeedUtilities do
|
|
122
122
|
@old_entry = Feedzirra::Parser::AtomEntry.new
|
123
123
|
@old_entry.url = "http://pauldix.net/old.html"
|
124
124
|
@old_entry.published = Time.now.to_s
|
125
|
-
@new_entry = Feedzirra::Parser::AtomEntry.new
|
125
|
+
@new_entry = Feedzirra::Parser::AtomEntry.new
|
126
126
|
@new_entry.url = "http://pauldix.net/new.html"
|
127
|
-
@new_entry.published = (Time.now + 10).to_s
|
127
|
+
@new_entry.published = (Time.now + 10).to_s
|
128
128
|
@feed.entries << @old_entry
|
129
129
|
@updated_feed.entries << @new_entry
|
130
130
|
@updated_feed.entries << @old_entry
|
131
131
|
end
|
132
|
-
|
132
|
+
|
133
133
|
it "should update last-modified from the latest entry date" do
|
134
134
|
@feed.update_from_feed(@updated_feed)
|
135
|
-
@feed.last_modified.should == @new_entry.published
|
135
|
+
@feed.last_modified.should == @new_entry.published
|
136
136
|
end
|
137
|
-
|
137
|
+
|
138
138
|
it "should put new entries into new_entries" do
|
139
139
|
@feed.update_from_feed(@updated_feed)
|
140
140
|
@feed.new_entries.should == [@new_entry]
|
141
141
|
end
|
142
|
-
|
142
|
+
|
143
143
|
it "should also put new entries into the entries collection" do
|
144
144
|
@feed.update_from_feed(@updated_feed)
|
145
145
|
@feed.entries.should include(@new_entry)
|
@@ -6,11 +6,11 @@ describe Feedzirra::Parser::AtomFeedBurnerEntry do
|
|
6
6
|
# but this is actually how it should work. You would never just pass entry xml straight to the AtomEnry
|
7
7
|
@entry = Feedzirra::Parser::AtomFeedBurner.parse(sample_feedburner_atom_feed).entries.first
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
it "should parse the title" do
|
11
11
|
@entry.title.should == "Making a Ruby C library even faster"
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
it "should be able to fetch a url via the 'alternate' rel if no origLink exists" do
|
15
15
|
entry = Feedzirra::Parser::AtomFeedBurner.parse(File.read("#{File.dirname(__FILE__)}/../../sample_feeds/PaulDixExplainsNothingAlternate.xml")).entries.first
|
16
16
|
entry.url.should == 'http://feeds.feedburner.com/~r/PaulDixExplainsNothing/~3/519925023/making-a-ruby-c-library-even-faster.html'
|
@@ -19,7 +19,7 @@ describe Feedzirra::Parser::AtomFeedBurnerEntry do
|
|
19
19
|
it "should parse the url" do
|
20
20
|
@entry.url.should == "http://www.pauldix.net/2009/01/making-a-ruby-c-library-even-faster.html"
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
it "should parse the url when there is no alternate" do
|
24
24
|
entry = Feedzirra::Parser::AtomFeedBurner.parse(File.read("#{File.dirname(__FILE__)}/../../sample_feeds/FeedBurnerUrlNoAlternate.xml")).entries.first
|
25
25
|
entry.url.should == 'http://example.com/QQQQ.html'
|
@@ -28,15 +28,15 @@ describe Feedzirra::Parser::AtomFeedBurnerEntry do
|
|
28
28
|
it "should parse the author" do
|
29
29
|
@entry.author.should == "Paul Dix"
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
it "should parse the content" do
|
33
33
|
@entry.content.should == sample_feedburner_atom_entry_content
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
it "should provide a summary" do
|
37
37
|
@entry.summary.should == "Last week I released the first version of a SAX based XML parsing library called SAX-Machine. It uses Nokogiri, which uses libxml, so it's pretty fast. However, I felt that it could be even faster. The only question was how..."
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
it "should parse the published date" do
|
41
41
|
@entry.published.should == Time.parse_safely("Thu Jan 22 15:50:22 UTC 2009")
|
42
42
|
end
|
@@ -44,4 +44,4 @@ describe Feedzirra::Parser::AtomFeedBurnerEntry do
|
|
44
44
|
it "should parse the categories" do
|
45
45
|
@entry.categories.should == ['Ruby', 'Another Category']
|
46
46
|
end
|
47
|
-
end
|
47
|
+
end
|
@@ -5,15 +5,15 @@ describe Feedzirra::Parser::AtomFeedBurner do
|
|
5
5
|
it "should return true for a feedburner atom feed" do
|
6
6
|
Feedzirra::Parser::AtomFeedBurner.should be_able_to_parse(sample_feedburner_atom_feed)
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
it "should return false for an rdf feed" do
|
10
10
|
Feedzirra::Parser::AtomFeedBurner.should_not be_able_to_parse(sample_rdf_feed)
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
it "should return false for a regular atom feed" do
|
14
14
|
Feedzirra::Parser::AtomFeedBurner.should_not be_able_to_parse(sample_atom_feed)
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
it "should return false for an rss feedburner feed" do
|
18
18
|
Feedzirra::Parser::AtomFeedBurner.should_not be_able_to_parse(sample_rss_feed_burner_feed)
|
19
19
|
end
|
@@ -23,7 +23,7 @@ describe Feedzirra::Parser::AtomFeedBurner do
|
|
23
23
|
before(:each) do
|
24
24
|
@feed = Feedzirra::Parser::AtomFeedBurner.parse(sample_feedburner_atom_feed)
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
it "should parse the title" do
|
28
28
|
@feed.title.should == "Paul Dix Explains Nothing"
|
29
29
|
end
|
@@ -35,13 +35,13 @@ describe Feedzirra::Parser::AtomFeedBurner do
|
|
35
35
|
it "should parse the url" do
|
36
36
|
@feed.url.should == "http://www.pauldix.net/"
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
it "should parse the feed_url" do
|
40
40
|
@feed.feed_url.should == "http://feeds.feedburner.com/PaulDixExplainsNothing"
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
it "should parse entries" do
|
44
44
|
@feed.entries.size.should == 5
|
45
45
|
end
|
46
46
|
end
|
47
|
-
end
|
47
|
+
end
|