ratom-instructure 0.6.9
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +135 -0
- data/LICENSE +20 -0
- data/README.rdoc +293 -0
- data/Rakefile +59 -0
- data/VERSION.yml +5 -0
- data/lib/atom.rb +796 -0
- data/lib/atom/configuration.rb +24 -0
- data/lib/atom/pub.rb +251 -0
- data/lib/atom/version.rb +7 -0
- data/lib/atom/xml/parser.rb +413 -0
- data/ratom.gemspec +95 -0
- data/spec/app/member_entry.atom +31 -0
- data/spec/app/service.xml +36 -0
- data/spec/app/service_xml_base.xml +37 -0
- data/spec/atom/pub_spec.rb +517 -0
- data/spec/atom_spec.rb +1385 -0
- data/spec/conformance/baseuri.atom +19 -0
- data/spec/conformance/divtest.atom +32 -0
- data/spec/conformance/linktests.xml +103 -0
- data/spec/conformance/nondefaultnamespace-baseline.atom +25 -0
- data/spec/conformance/nondefaultnamespace-xhtml.atom +25 -0
- data/spec/conformance/nondefaultnamespace.atom +25 -0
- data/spec/conformance/ordertest.xml +112 -0
- data/spec/conformance/title/html-cdata.atom +22 -0
- data/spec/conformance/title/html-entity.atom +22 -0
- data/spec/conformance/title/html-ncr.atom +22 -0
- data/spec/conformance/title/text-cdata.atom +22 -0
- data/spec/conformance/title/text-entity.atom +21 -0
- data/spec/conformance/title/text-ncr.atom +21 -0
- data/spec/conformance/title/xhtml-entity.atom +21 -0
- data/spec/conformance/title/xhtml-ncr.atom +21 -0
- data/spec/conformance/unknown-namespace.atom +25 -0
- data/spec/conformance/xmlbase.atom +133 -0
- data/spec/fixtures/complex_single_entry.atom +45 -0
- data/spec/fixtures/created_entry.atom +31 -0
- data/spec/fixtures/entry.atom +30 -0
- data/spec/fixtures/entry_with_custom_extensions.atom +8 -0
- data/spec/fixtures/entry_with_simple_extensions.atom +31 -0
- data/spec/fixtures/entry_with_single_custom_extension.atom +6 -0
- data/spec/fixtures/multiple_entry.atom +0 -0
- data/spec/fixtures/simple_single_entry.atom +21 -0
- data/spec/fixtures/with_stylesheet.atom +8 -0
- data/spec/paging/first_paged_feed.atom +21 -0
- data/spec/paging/last_paged_feed.atom +21 -0
- data/spec/paging/middle_paged_feed.atom +22 -0
- data/spec/property.rb +31 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +46 -0
- metadata +147 -0
data/spec/atom_spec.rb
ADDED
@@ -0,0 +1,1385 @@
|
|
1
|
+
# Copyright (c) 2008 The Kaphan Foundation
|
2
|
+
#
|
3
|
+
# For licensing information see LICENSE.
|
4
|
+
#
|
5
|
+
# Please visit http://www.peerworks.org/contact for further information.
|
6
|
+
#
|
7
|
+
|
8
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
9
|
+
require 'net/http'
|
10
|
+
require 'time'
|
11
|
+
require 'spec/property'
|
12
|
+
|
13
|
+
shared_examples_for 'simple_single_entry.atom attributes' do
|
14
|
+
it "should parse title" do
|
15
|
+
@feed.title.should == 'Example Feed'
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should parse updated" do
|
19
|
+
@feed.updated.should == Time.parse('2003-12-13T18:30:02Z')
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should parse id" do
|
23
|
+
@feed.id.should == 'urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6'
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should have an entries array" do
|
27
|
+
@feed.entries.should be_an_instance_of(Array)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should have one element in the entries array" do
|
31
|
+
@feed.entries.size.should == 1
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should have an alternate" do
|
35
|
+
@feed.alternate.should_not be_nil
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should have an Atom::Link as the alternate" do
|
39
|
+
@feed.alternate.should be_an_instance_of(Atom::Link)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should have the correct href in the alternate" do
|
43
|
+
@feed.alternate.href.should == 'http://example.org/'
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should have 1 author" do
|
47
|
+
@feed.should have(1).authors
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should have 'John Doe' as the author's name" do
|
51
|
+
@feed.authors.first.name.should == "John Doe"
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should parse title" do
|
55
|
+
@entry.title.should == 'Atom-Powered Robots Run Amok'
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should have an alternate" do
|
59
|
+
@entry.alternate.should_not be_nil
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should have an Atom::Link as the alternate" do
|
63
|
+
@entry.alternate.should be_an_instance_of(Atom::Link)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should have the correct href on the alternate" do
|
67
|
+
@entry.alternate.href.should == 'http://example.org/2003/12/13/atom03'
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should parse id" do
|
71
|
+
@entry.id.should == 'urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a'
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should parse updated" do
|
75
|
+
@entry.updated.should == Time.parse('2003-12-13T18:30:02Z')
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should parse summary" do
|
79
|
+
@entry.summary.should == 'Some text.'
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should parse content" do
|
83
|
+
@entry.content.should == 'This <em>is</em> html.'
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should parse content type" do
|
87
|
+
@entry.content.type.should == 'html'
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe Atom do
|
92
|
+
describe "Atom::Feed.load_feed" do
|
93
|
+
it "should accept an IO" do
|
94
|
+
lambda { Atom::Feed.load_feed(File.open('spec/fixtures/simple_single_entry.atom')) }.should_not raise_error
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should raise ArgumentError with something other than IO or URI" do
|
98
|
+
lambda { Atom::Feed.load_feed(nil) }.should raise_error(ArgumentError)
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should accept a String" do
|
102
|
+
Atom::Feed.load_feed(File.read('spec/fixtures/simple_single_entry.atom')).should be_an_instance_of(Atom::Feed)
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should accept a URI" do
|
106
|
+
uri = URI.parse('http://example.com/feed.atom')
|
107
|
+
response = Net::HTTPSuccess.new(nil, nil, nil)
|
108
|
+
response.stub!(:body).and_return(File.read('spec/fixtures/simple_single_entry.atom'))
|
109
|
+
mock_http_get(uri, response)
|
110
|
+
|
111
|
+
Atom::Feed.load_feed(uri).should be_an_instance_of(Atom::Feed)
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should accept a URI with query parameters" do
|
115
|
+
uri = URI.parse('http://example.com/feed.atom?page=2')
|
116
|
+
response = Net::HTTPSuccess.new(nil, nil, nil)
|
117
|
+
response.stub!(:body).and_return(File.read('spec/fixtures/simple_single_entry.atom'))
|
118
|
+
mock_http_get(uri, response)
|
119
|
+
|
120
|
+
Atom::Feed.load_feed(uri).should be_an_instance_of(Atom::Feed)
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should raise ArgumentError with non-http uri" do
|
124
|
+
uri = URI.parse('file:/tmp')
|
125
|
+
lambda { Atom::Feed.load_feed(uri) }.should raise_error(ArgumentError)
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should return an Atom::Feed" do
|
129
|
+
feed = Atom::Feed.load_feed(File.open('spec/fixtures/simple_single_entry.atom'))
|
130
|
+
feed.should be_an_instance_of(Atom::Feed)
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should not raise an error with a String and basic-auth credentials" do
|
134
|
+
lambda { Atom::Feed.load_feed(File.read('spec/fixtures/simple_single_entry.atom'), :user => 'user', :pass => 'pass') }.should_not raise_error
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should not raise an error with a URI with basic-auth credentials" do
|
138
|
+
uri = URI.parse('http://example.com/feed.atom')
|
139
|
+
|
140
|
+
response = Net::HTTPSuccess.new(nil, nil, nil)
|
141
|
+
response.stub!(:body).and_return(File.read('spec/fixtures/simple_single_entry.atom'))
|
142
|
+
mock_http_get(uri, response, 'user', 'pass')
|
143
|
+
|
144
|
+
lambda { Atom::Feed.load_feed(uri, :user => 'user', :pass => 'pass') }.should_not raise_error
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
describe 'Atom::Entry.load_entry' do
|
149
|
+
it "should accept an IO" do
|
150
|
+
Atom::Entry.load_entry(File.open('spec/fixtures/entry.atom')).should be_an_instance_of(Atom::Entry)
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should accept a URI" do
|
154
|
+
uri = URI.parse('http://example.org/entry.atom')
|
155
|
+
response = Net::HTTPSuccess.new(nil, nil, nil)
|
156
|
+
response.stub!(:body).and_return(File.read('spec/fixtures/entry.atom'))
|
157
|
+
mock_http_get(uri, response)
|
158
|
+
|
159
|
+
Atom::Entry.load_entry(uri).should be_an_instance_of(Atom::Entry)
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should accept a String" do
|
163
|
+
Atom::Entry.load_entry(File.read('spec/fixtures/entry.atom')).should be_an_instance_of(Atom::Entry)
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should raise ArgumentError with something other than IO, String or URI" do
|
167
|
+
lambda { Atom::Entry.load_entry(nil) }.should raise_error(ArgumentError)
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should raise ArgumentError with non-http uri" do
|
171
|
+
lambda { Atom::Entry.load_entry(URI.parse('file:/tmp')) }.should raise_error(ArgumentError)
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
describe 'SimpleSingleFeed' do
|
176
|
+
before(:all) do
|
177
|
+
@feed = Atom::Feed.load_feed(File.open('spec/fixtures/simple_single_entry.atom'))
|
178
|
+
@entry = @feed.entries.first
|
179
|
+
end
|
180
|
+
|
181
|
+
it_should_behave_like "simple_single_entry.atom attributes"
|
182
|
+
end
|
183
|
+
|
184
|
+
describe 'FeedWithStyleSheet' do
|
185
|
+
it "should load without failure" do
|
186
|
+
lambda { feed = Atom::Feed.load_feed(File.open('spec/fixtures/with_stylesheet.atom')) }.should_not raise_error
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
describe 'ComplexFeed' do
|
191
|
+
before(:all) do
|
192
|
+
@feed = Atom::Feed.load_feed(File.open('spec/fixtures/complex_single_entry.atom'))
|
193
|
+
end
|
194
|
+
|
195
|
+
describe Atom::Feed do
|
196
|
+
it "should have a title" do
|
197
|
+
@feed.title.should == 'dive into mark'
|
198
|
+
end
|
199
|
+
|
200
|
+
it "should have type on the title" do
|
201
|
+
@feed.title.type.should == 'text'
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should have a subtitle" do
|
205
|
+
@feed.subtitle.should == 'A <em>lot</em> of effort went into making this effortless'
|
206
|
+
end
|
207
|
+
|
208
|
+
it "should have a type for the subtitle" do
|
209
|
+
@feed.subtitle.type.should == 'html'
|
210
|
+
end
|
211
|
+
|
212
|
+
it "should have an updated date" do
|
213
|
+
@feed.updated.should == Time.parse('2005-07-31T12:29:29Z')
|
214
|
+
end
|
215
|
+
|
216
|
+
it "should have an id" do
|
217
|
+
@feed.id.should == 'tag:example.org,2003:3'
|
218
|
+
end
|
219
|
+
|
220
|
+
it "should have 2 links" do
|
221
|
+
@feed.should have(2).links
|
222
|
+
end
|
223
|
+
|
224
|
+
it "should have an alternate link" do
|
225
|
+
@feed.alternate.should_not be_nil
|
226
|
+
end
|
227
|
+
|
228
|
+
it "should have the right url for the alternate" do
|
229
|
+
@feed.alternate.to_s.should == 'http://example.org/'
|
230
|
+
end
|
231
|
+
|
232
|
+
it "should have a self link" do
|
233
|
+
@feed.self.should_not be_nil
|
234
|
+
end
|
235
|
+
|
236
|
+
it "should have the right url for self" do
|
237
|
+
@feed.self.to_s.should == 'http://example.org/feed.atom'
|
238
|
+
end
|
239
|
+
|
240
|
+
it "should have rights" do
|
241
|
+
@feed.rights.should == 'Copyright (c) 2003, Mark Pilgrim'
|
242
|
+
end
|
243
|
+
|
244
|
+
it "should have a generator" do
|
245
|
+
@feed.generator.should_not be_nil
|
246
|
+
end
|
247
|
+
|
248
|
+
it "should have a generator uri" do
|
249
|
+
@feed.generator.uri.should == 'http://www.example.com/'
|
250
|
+
end
|
251
|
+
|
252
|
+
it "should have a generator version" do
|
253
|
+
@feed.generator.version.should == '1.0'
|
254
|
+
end
|
255
|
+
|
256
|
+
it "should have a generator name" do
|
257
|
+
@feed.generator.name.should == 'Example Toolkit'
|
258
|
+
end
|
259
|
+
|
260
|
+
it "should have an entry" do
|
261
|
+
@feed.should have(1).entries
|
262
|
+
end
|
263
|
+
|
264
|
+
it "should have a category" do
|
265
|
+
@feed.should have(1).categories
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
describe "FeedWithXmlBase" do
|
270
|
+
before(:all) do
|
271
|
+
@feed = Atom::Feed.load_feed(File.open('spec/conformance/xmlbase.atom'))
|
272
|
+
end
|
273
|
+
|
274
|
+
subject { @feed }
|
275
|
+
|
276
|
+
its(:title) { should == "xml:base support tests" }
|
277
|
+
it { should have(16).entries }
|
278
|
+
|
279
|
+
it "should resolve all alternate links to the same location" do
|
280
|
+
@feed.entries.each do |entry|
|
281
|
+
entry.links.first.href.should == "http://example.org/tests/base/result.html"
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
it "should resolve all links in content to what their label says" do
|
286
|
+
pending "support xml:base in content XHTML"
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
describe Atom::Entry do
|
291
|
+
before(:each) do
|
292
|
+
@entry = @feed.entries.first
|
293
|
+
end
|
294
|
+
|
295
|
+
it "should have a title" do
|
296
|
+
@entry.title.should == 'Atom draft-07 snapshot'
|
297
|
+
end
|
298
|
+
|
299
|
+
it "should have an id" do
|
300
|
+
@entry.id.should == 'tag:example.org,2003:3.2397'
|
301
|
+
end
|
302
|
+
|
303
|
+
it "should have an updated date" do
|
304
|
+
@entry.updated.should == Time.parse('2005-07-31T12:29:29Z')
|
305
|
+
end
|
306
|
+
|
307
|
+
it "should have a published date" do
|
308
|
+
@entry.published.should == Time.parse('2003-12-13T08:29:29-04:00')
|
309
|
+
end
|
310
|
+
|
311
|
+
it "should have an author" do
|
312
|
+
@entry.should have(1).authors
|
313
|
+
end
|
314
|
+
|
315
|
+
it "should have two links" do
|
316
|
+
@entry.should have(2).links
|
317
|
+
end
|
318
|
+
|
319
|
+
it "should have one alternate link" do
|
320
|
+
@entry.should have(1).alternates
|
321
|
+
end
|
322
|
+
|
323
|
+
it "should have one enclosure link" do
|
324
|
+
@entry.should have(1).enclosures
|
325
|
+
end
|
326
|
+
|
327
|
+
it "should have 2 contributors" do
|
328
|
+
@entry.should have(2).contributors
|
329
|
+
end
|
330
|
+
|
331
|
+
it "should have names for the contributors" do
|
332
|
+
@entry.contributors[0].name.should == 'Sam Ruby'
|
333
|
+
@entry.contributors[1].name.should == 'Joe Gregorio'
|
334
|
+
end
|
335
|
+
|
336
|
+
it "should have content" do
|
337
|
+
@entry.content.should_not be_nil
|
338
|
+
end
|
339
|
+
|
340
|
+
it "should have 2 categories" do
|
341
|
+
@entry.should have(2).categories
|
342
|
+
end
|
343
|
+
end
|
344
|
+
|
345
|
+
describe Atom::Category do
|
346
|
+
describe 'atom category' do
|
347
|
+
before(:each) do
|
348
|
+
@category = @feed.entries.first.categories.first
|
349
|
+
end
|
350
|
+
|
351
|
+
it "should have a term" do
|
352
|
+
@category.term.should == "atom"
|
353
|
+
end
|
354
|
+
|
355
|
+
it "should have a scheme" do
|
356
|
+
@category.scheme.should == "http://example.org"
|
357
|
+
end
|
358
|
+
|
359
|
+
it "should have a label" do
|
360
|
+
@category.label.should == "Atom"
|
361
|
+
end
|
362
|
+
end
|
363
|
+
|
364
|
+
describe 'draft category' do
|
365
|
+
before(:each) do
|
366
|
+
@category = @feed.entries.first.categories.last
|
367
|
+
end
|
368
|
+
|
369
|
+
it "should have a term" do
|
370
|
+
@category.term.should == "drafts"
|
371
|
+
end
|
372
|
+
|
373
|
+
it "should have a scheme" do
|
374
|
+
@category.scheme.should == "http://example2.org"
|
375
|
+
end
|
376
|
+
|
377
|
+
it "should have a label" do
|
378
|
+
@category.label.should == "Drafts"
|
379
|
+
end
|
380
|
+
end
|
381
|
+
end
|
382
|
+
|
383
|
+
describe Atom::Link do
|
384
|
+
describe 'alternate link' do
|
385
|
+
before(:each) do
|
386
|
+
@entry = @feed.entries.first
|
387
|
+
@link = @entry.alternate
|
388
|
+
end
|
389
|
+
|
390
|
+
it "should have text/html type" do
|
391
|
+
@link.type.should == 'text/html'
|
392
|
+
end
|
393
|
+
|
394
|
+
it "should have alternate rel" do
|
395
|
+
@link.rel.should == 'alternate'
|
396
|
+
end
|
397
|
+
|
398
|
+
it "should have href 'http://example.org/2005/04/02/atom'" do
|
399
|
+
@link.href.should == 'http://example.org/2005/04/02/atom'
|
400
|
+
end
|
401
|
+
|
402
|
+
it "should have 'http://example.org/2005/04/02/atom' string representation" do
|
403
|
+
@link.to_s.should == 'http://example.org/2005/04/02/atom'
|
404
|
+
end
|
405
|
+
|
406
|
+
it "should have title 'Alternate link'" do
|
407
|
+
@link.title.should == "Alternate link"
|
408
|
+
end
|
409
|
+
end
|
410
|
+
|
411
|
+
describe 'enclosure link' do
|
412
|
+
before(:each) do
|
413
|
+
@entry = @feed.entries.first
|
414
|
+
@link = @entry.enclosures.first
|
415
|
+
end
|
416
|
+
|
417
|
+
it "should have audio/mpeg type" do
|
418
|
+
@link.type.should == 'audio/mpeg'
|
419
|
+
end
|
420
|
+
|
421
|
+
it "should have enclosure rel" do
|
422
|
+
@link.rel.should == 'enclosure'
|
423
|
+
end
|
424
|
+
|
425
|
+
it "should have length 1337" do
|
426
|
+
@link.length.should == 1337
|
427
|
+
end
|
428
|
+
|
429
|
+
it "should have href 'http://example.org/audio/ph34r_my_podcast.mp3'" do
|
430
|
+
@link.href.should == 'http://example.org/audio/ph34r_my_podcast.mp3'
|
431
|
+
end
|
432
|
+
|
433
|
+
it "should have 'http://example.org/audio/ph34r_my_podcast.mp3' string representation" do
|
434
|
+
@link.to_s.should == 'http://example.org/audio/ph34r_my_podcast.mp3'
|
435
|
+
end
|
436
|
+
end
|
437
|
+
end
|
438
|
+
|
439
|
+
describe Atom::Person do
|
440
|
+
before(:each) do
|
441
|
+
@entry = @feed.entries.first
|
442
|
+
@person = @entry.authors.first
|
443
|
+
end
|
444
|
+
|
445
|
+
it "should have a name" do
|
446
|
+
@person.name.should == 'Mark Pilgrim'
|
447
|
+
end
|
448
|
+
|
449
|
+
it "should have a uri" do
|
450
|
+
@person.uri.should == 'http://example.org/'
|
451
|
+
end
|
452
|
+
|
453
|
+
it "should have an email address" do
|
454
|
+
@person.email.should == 'f8dy@example.com'
|
455
|
+
end
|
456
|
+
end
|
457
|
+
|
458
|
+
describe Atom::Content do
|
459
|
+
before(:each) do
|
460
|
+
@entry = @feed.entries.first
|
461
|
+
@content = @entry.content
|
462
|
+
end
|
463
|
+
|
464
|
+
it "should have 'xhtml' type" do
|
465
|
+
@content.type.should == 'xhtml'
|
466
|
+
end
|
467
|
+
|
468
|
+
it "should have 'en' language" do
|
469
|
+
@content.xml_lang.should == 'en'
|
470
|
+
end
|
471
|
+
|
472
|
+
it "should have the content as the string representation" do
|
473
|
+
@content.should == '<p xmlns="http://www.w3.org/1999/xhtml"><i>[Update: The Atom draft is finished.]</i></p>'
|
474
|
+
end
|
475
|
+
end
|
476
|
+
end
|
477
|
+
|
478
|
+
describe 'ConformanceTests' do
|
479
|
+
describe 'nondefaultnamespace.atom' do
|
480
|
+
before(:all) do
|
481
|
+
@feed = Atom::Feed.load_feed(File.open('spec/conformance/nondefaultnamespace.atom'))
|
482
|
+
end
|
483
|
+
|
484
|
+
it "should have a title" do
|
485
|
+
@feed.title.should == 'Non-default namespace test'
|
486
|
+
end
|
487
|
+
|
488
|
+
it "should have 1 entry" do
|
489
|
+
@feed.should have(1).entries
|
490
|
+
end
|
491
|
+
|
492
|
+
describe Atom::Entry do
|
493
|
+
before(:all) do
|
494
|
+
@entry = @feed.entries.first
|
495
|
+
end
|
496
|
+
|
497
|
+
it "should have a title" do
|
498
|
+
@entry.title.should == 'If you can read the content of this entry, your aggregator works fine.'
|
499
|
+
end
|
500
|
+
|
501
|
+
it "should have content" do
|
502
|
+
@entry.content.should_not be_nil
|
503
|
+
end
|
504
|
+
|
505
|
+
it "should have 'xhtml' for the type of the content" do
|
506
|
+
@entry.content.type.should == 'xhtml'
|
507
|
+
end
|
508
|
+
|
509
|
+
it "should strip the outer div of the content" do
|
510
|
+
@entry.content.should_not match(/div/)
|
511
|
+
end
|
512
|
+
|
513
|
+
it "should keep inner xhtml of content" do
|
514
|
+
@entry.content.should == '<p xmlns="http://www.w3.org/1999/xhtml">For information, see:</p> ' +
|
515
|
+
'<ul xmlns="http://www.w3.org/1999/xhtml"> ' +
|
516
|
+
'<li><a href="http://plasmasturm.org/log/376/">Who knows an <abbr title="Extensible Markup Language">XML</abbr> document from a hole in the ground?</a></li> ' +
|
517
|
+
'<li><a href="http://plasmasturm.org/log/377/">More on Atom aggregator <abbr title="Extensible Markup Language">XML</abbr> namespace conformance tests</a></li> ' +
|
518
|
+
'<li><a href="http://www.intertwingly.net/wiki/pie/XmlNamespaceConformanceTests"><abbr title="Extensible Markup Language">XML</abbr> Namespace Conformance Tests</a></li> ' +
|
519
|
+
'</ul>'
|
520
|
+
end
|
521
|
+
end
|
522
|
+
end
|
523
|
+
|
524
|
+
describe 'unknown-namespace.atom' do
|
525
|
+
before(:all) do
|
526
|
+
@feed = Atom::Feed.load_feed(File.open('spec/conformance/unknown-namespace.atom'))
|
527
|
+
@entry = @feed.entries.first
|
528
|
+
@content = @entry.content
|
529
|
+
end
|
530
|
+
|
531
|
+
it "should have content" do
|
532
|
+
@content.should_not be_nil
|
533
|
+
end
|
534
|
+
|
535
|
+
it "should strip surrounding div" do
|
536
|
+
@content.should_not match(/div/)
|
537
|
+
end
|
538
|
+
|
539
|
+
it "should keep inner lists" do
|
540
|
+
@content.should match(/<h:ul/)
|
541
|
+
@content.should match(/<ul/)
|
542
|
+
end
|
543
|
+
|
544
|
+
it "should have xhtml type" do
|
545
|
+
@content.type.should == 'xhtml'
|
546
|
+
end
|
547
|
+
end
|
548
|
+
|
549
|
+
describe 'linktests.atom' do
|
550
|
+
before(:all) do
|
551
|
+
@feed = Atom::Feed.load_feed(File.open('spec/conformance/linktests.xml'))
|
552
|
+
@entries = @feed.entries
|
553
|
+
end
|
554
|
+
|
555
|
+
describe 'linktest1' do
|
556
|
+
before(:all) do
|
557
|
+
@entry = @entries[0]
|
558
|
+
end
|
559
|
+
|
560
|
+
it "should pick single alternate link without rel" do
|
561
|
+
@entry.alternate.href.should == 'http://www.snellspace.com/public/linktests/alternate'
|
562
|
+
end
|
563
|
+
end
|
564
|
+
|
565
|
+
describe 'linktest2' do
|
566
|
+
before(:all) do
|
567
|
+
@entry = @entries[1]
|
568
|
+
end
|
569
|
+
|
570
|
+
it "should be picky about case of alternate rel" do
|
571
|
+
@entry.alternate.href.should == 'http://www.snellspace.com/public/linktests/alternate'
|
572
|
+
end
|
573
|
+
|
574
|
+
it "should be picky when picking the alternate by type" do
|
575
|
+
@entry.alternate('text/plain').href.should == 'http://www.snellspace.com/public/linktests/alternate2'
|
576
|
+
end
|
577
|
+
end
|
578
|
+
|
579
|
+
describe 'linktest3' do
|
580
|
+
before(:all) do
|
581
|
+
@entry = @entries[2]
|
582
|
+
end
|
583
|
+
|
584
|
+
it "should parse all links" do
|
585
|
+
@entry.should have(5).links
|
586
|
+
end
|
587
|
+
|
588
|
+
it "should pick the alternate from a full list of core types" do
|
589
|
+
@entry.alternate.href.should == 'http://www.snellspace.com/public/linktests/alternate'
|
590
|
+
end
|
591
|
+
end
|
592
|
+
|
593
|
+
describe 'linktest4' do
|
594
|
+
before(:all) do
|
595
|
+
@entry = @entries[3]
|
596
|
+
end
|
597
|
+
|
598
|
+
it "should parse all links" do
|
599
|
+
@entry.should have(6).links
|
600
|
+
end
|
601
|
+
|
602
|
+
it "should pick the first alternate from a full list of core types with an extra alternate" do
|
603
|
+
@entry.alternate.href.should == 'http://www.snellspace.com/public/linktests/alternate'
|
604
|
+
end
|
605
|
+
|
606
|
+
it "should pick the alternate by type from a full list of core types with an extra alternate" do
|
607
|
+
@entry.alternate('text/plain').href.should == 'http://www.snellspace.com/public/linktests/alternate2'
|
608
|
+
end
|
609
|
+
end
|
610
|
+
|
611
|
+
describe 'linktest5' do
|
612
|
+
before(:all) do
|
613
|
+
@entry = @entries[4]
|
614
|
+
end
|
615
|
+
|
616
|
+
it "should parse all links" do
|
617
|
+
@entry.should have(2).links
|
618
|
+
end
|
619
|
+
|
620
|
+
it "should pick the alternate without choking on a non-core type" do
|
621
|
+
@entry.alternate.href.should == 'http://www.snellspace.com/public/linktests/alternate'
|
622
|
+
end
|
623
|
+
|
624
|
+
it "should include the non-core type in the list of links" do
|
625
|
+
@entry.links.map{|l| l.href }.should include('http://www.snellspace.com/public/linktests/license')
|
626
|
+
end
|
627
|
+
end
|
628
|
+
|
629
|
+
describe 'linktest6' do
|
630
|
+
before(:all) do
|
631
|
+
@entry = @entries[5]
|
632
|
+
end
|
633
|
+
|
634
|
+
it "should parse all links" do
|
635
|
+
@entry.should have(2).links
|
636
|
+
end
|
637
|
+
|
638
|
+
it "should pick the alternate without choking on a non-core type identified by a uri" do
|
639
|
+
@entry.alternate.href.should == 'http://www.snellspace.com/public/linktests/alternate'
|
640
|
+
end
|
641
|
+
|
642
|
+
it "should include the non-core type in the list of links identified by a uri" do
|
643
|
+
@entry.links.map{|l| l.href }.should include('http://www.snellspace.com/public/linktests/example')
|
644
|
+
end
|
645
|
+
end
|
646
|
+
|
647
|
+
describe 'linktest7' do
|
648
|
+
before(:all) do
|
649
|
+
@entry = @entries[6]
|
650
|
+
end
|
651
|
+
|
652
|
+
it "should parse all links" do
|
653
|
+
@entry.should have(2).links
|
654
|
+
end
|
655
|
+
|
656
|
+
it "should pick the alternate without choking on a non-core type" do
|
657
|
+
@entry.alternate.href.should == 'http://www.snellspace.com/public/linktests/alternate'
|
658
|
+
end
|
659
|
+
|
660
|
+
it "should include the non-core type in the list of links" do
|
661
|
+
@entry.links.map{|l| l.href }.should include('http://www.snellspace.com/public/linktests/license')
|
662
|
+
end
|
663
|
+
end
|
664
|
+
|
665
|
+
describe 'linktest8' do
|
666
|
+
before(:all) do
|
667
|
+
@entry = @entries[7]
|
668
|
+
end
|
669
|
+
|
670
|
+
it "should parse all links" do
|
671
|
+
@entry.should have(2).links
|
672
|
+
end
|
673
|
+
|
674
|
+
it "should pick the alternate without choking on a non-core type identified by a uri" do
|
675
|
+
@entry.alternate.href.should == 'http://www.snellspace.com/public/linktests/alternate'
|
676
|
+
end
|
677
|
+
|
678
|
+
it "should include the non-core type in the list of links identified by a uri" do
|
679
|
+
@entry.links.map{|l| l.href }.should include('http://www.snellspace.com/public/linktests/example')
|
680
|
+
end
|
681
|
+
end
|
682
|
+
|
683
|
+
describe 'linktest9' do
|
684
|
+
before(:all) do
|
685
|
+
@entry = @entries[8]
|
686
|
+
end
|
687
|
+
|
688
|
+
it "should parse all links" do
|
689
|
+
@entry.should have(3).links
|
690
|
+
end
|
691
|
+
|
692
|
+
it "should pick the alternate without hreflang" do
|
693
|
+
@entry.alternate.href.should == 'http://www.snellspace.com/public/linktests/alternate'
|
694
|
+
end
|
695
|
+
end
|
696
|
+
end
|
697
|
+
|
698
|
+
describe 'ordertest.atom' do
|
699
|
+
before(:all) do
|
700
|
+
@feed = Atom::Feed.load_feed(File.open('spec/conformance/ordertest.xml'))
|
701
|
+
end
|
702
|
+
|
703
|
+
it 'should have 9 entries' do
|
704
|
+
@feed.should have(9).entries
|
705
|
+
end
|
706
|
+
|
707
|
+
describe 'ordertest1' do
|
708
|
+
before(:each) do
|
709
|
+
@entry = @feed.entries[0]
|
710
|
+
end
|
711
|
+
|
712
|
+
it "should have the correct title" do
|
713
|
+
@entry.title.should == 'Simple order, nothing fancy'
|
714
|
+
end
|
715
|
+
end
|
716
|
+
|
717
|
+
describe 'ordertest2' do
|
718
|
+
before(:each) do
|
719
|
+
@entry = @feed.entries[1]
|
720
|
+
end
|
721
|
+
|
722
|
+
it "should have the correct title" do
|
723
|
+
@entry.title.should == 'Same as the first, only mixed up a bit'
|
724
|
+
end
|
725
|
+
end
|
726
|
+
|
727
|
+
describe "ordertest3" do
|
728
|
+
before(:each) do
|
729
|
+
@entry = @feed.entries[2]
|
730
|
+
end
|
731
|
+
|
732
|
+
it "should have the correct title" do
|
733
|
+
@entry.title.should == 'Multiple alt link elements, which one does your reader show?'
|
734
|
+
end
|
735
|
+
|
736
|
+
it "should pick the first alternate" do
|
737
|
+
@entry.alternate.href.should == 'http://www.snellspace.com/public/alternate'
|
738
|
+
end
|
739
|
+
end
|
740
|
+
|
741
|
+
describe 'ordertest4' do
|
742
|
+
before(:each) do
|
743
|
+
@entry = @feed.entries[3]
|
744
|
+
end
|
745
|
+
|
746
|
+
it "should have the correct title" do
|
747
|
+
@entry.title.should == 'Multiple link elements, does your feed reader show the "alternate" correctly?'
|
748
|
+
end
|
749
|
+
|
750
|
+
it "should pick the right link" do
|
751
|
+
@entry.alternate.href.should == 'http://www.snellspace.com/public/alternate'
|
752
|
+
end
|
753
|
+
end
|
754
|
+
|
755
|
+
describe 'ordertest5' do
|
756
|
+
before(:each) do
|
757
|
+
@entry = @feed.entries[4]
|
758
|
+
end
|
759
|
+
|
760
|
+
it "should have a source" do
|
761
|
+
@entry.source.should_not be_nil
|
762
|
+
end
|
763
|
+
|
764
|
+
it "should have the correct title" do
|
765
|
+
@entry.title.should == 'Entry with a source first'
|
766
|
+
end
|
767
|
+
|
768
|
+
it "should have the correct updated" do
|
769
|
+
@entry.updated.should == Time.parse('2006-01-26T09:20:05Z')
|
770
|
+
end
|
771
|
+
|
772
|
+
it "should have the correct alt link" do
|
773
|
+
@entry.alternate.href.should == 'http://www.snellspace.com/public/alternate'
|
774
|
+
end
|
775
|
+
|
776
|
+
describe Atom::Source do
|
777
|
+
before(:each) do
|
778
|
+
@source = @entry.source
|
779
|
+
end
|
780
|
+
|
781
|
+
it "should have an id" do
|
782
|
+
@source.id.should == 'tag:example.org,2006:atom/conformance/element_order'
|
783
|
+
end
|
784
|
+
|
785
|
+
it "should have a title" do
|
786
|
+
@source.title.should == 'Order Matters'
|
787
|
+
end
|
788
|
+
|
789
|
+
it "should have a subtitle" do
|
790
|
+
@source.subtitle.should == 'Testing how feed readers handle the order of entry elements'
|
791
|
+
end
|
792
|
+
|
793
|
+
it "should have a updated" do
|
794
|
+
@source.updated.should == Time.parse('2006-01-26T09:16:00Z')
|
795
|
+
end
|
796
|
+
|
797
|
+
it "should have an author" do
|
798
|
+
@source.should have(1).authors
|
799
|
+
end
|
800
|
+
|
801
|
+
it "should have the right name for the author" do
|
802
|
+
@source.authors.first.name.should == 'James Snell'
|
803
|
+
end
|
804
|
+
|
805
|
+
it "should have 2 links" do
|
806
|
+
@source.should have(2).links
|
807
|
+
end
|
808
|
+
|
809
|
+
it "should have an alternate" do
|
810
|
+
@source.alternate.href.should == 'http://www.snellspace.com/wp/?p=255'
|
811
|
+
end
|
812
|
+
|
813
|
+
it "should have a self" do
|
814
|
+
@source.self.href.should == 'http://www.snellspace.com/public/ordertest.xml'
|
815
|
+
end
|
816
|
+
end
|
817
|
+
end
|
818
|
+
|
819
|
+
describe 'ordertest6' do
|
820
|
+
before(:each) do
|
821
|
+
@entry = @feed.entries[5]
|
822
|
+
end
|
823
|
+
|
824
|
+
it "should have a source" do
|
825
|
+
@entry.source.should_not be_nil
|
826
|
+
end
|
827
|
+
|
828
|
+
it "should have the correct title" do
|
829
|
+
@entry.title.should == 'Entry with a source last'
|
830
|
+
end
|
831
|
+
|
832
|
+
it "should have the correct updated" do
|
833
|
+
@entry.updated.should == Time.parse('2006-01-26T09:20:06Z')
|
834
|
+
end
|
835
|
+
|
836
|
+
it "should have the correct alt link" do
|
837
|
+
@entry.alternate.href.should == 'http://www.snellspace.com/public/alternate'
|
838
|
+
end
|
839
|
+
end
|
840
|
+
|
841
|
+
describe 'ordetest7' do
|
842
|
+
before(:each) do
|
843
|
+
@entry = @feed.entries[6]
|
844
|
+
end
|
845
|
+
|
846
|
+
it "should have a source" do
|
847
|
+
@entry.source.should_not be_nil
|
848
|
+
end
|
849
|
+
|
850
|
+
it "should have the correct title" do
|
851
|
+
@entry.title.should == 'Entry with a source in the middle'
|
852
|
+
end
|
853
|
+
|
854
|
+
it "should have the correct updated" do
|
855
|
+
@entry.updated.should == Time.parse('2006-01-26T09:20:07Z')
|
856
|
+
end
|
857
|
+
|
858
|
+
it "should have the correct alt link" do
|
859
|
+
@entry.alternate.href.should == 'http://www.snellspace.com/public/alternate'
|
860
|
+
end
|
861
|
+
end
|
862
|
+
|
863
|
+
describe 'ordertest8' do
|
864
|
+
before(:each) do
|
865
|
+
@entry = @feed.entries[7]
|
866
|
+
end
|
867
|
+
|
868
|
+
it "should have the right title" do
|
869
|
+
@entry.title.should == 'Atom elements in an extension element'
|
870
|
+
end
|
871
|
+
|
872
|
+
it "should have right id" do
|
873
|
+
@entry.id.should == 'tag:example.org,2006:atom/conformance/element_order/8'
|
874
|
+
end
|
875
|
+
end
|
876
|
+
|
877
|
+
describe 'ordertest9' do
|
878
|
+
before(:each) do
|
879
|
+
@entry = @feed.entries[8]
|
880
|
+
end
|
881
|
+
|
882
|
+
it "should have the right title" do
|
883
|
+
@entry.title.should == 'Atom elements in an extension element'
|
884
|
+
end
|
885
|
+
|
886
|
+
it 'should have the right id' do
|
887
|
+
@entry.id.should == 'tag:example.org,2006:atom/conformance/element_order/9'
|
888
|
+
end
|
889
|
+
end
|
890
|
+
end
|
891
|
+
end
|
892
|
+
|
893
|
+
describe 'pagination' do
|
894
|
+
describe 'first_paged_feed.atom' do
|
895
|
+
before(:all) do
|
896
|
+
@feed = Atom::Feed.load_feed(File.open('spec/paging/first_paged_feed.atom'))
|
897
|
+
end
|
898
|
+
|
899
|
+
it "should be first?" do
|
900
|
+
@feed.should be_first
|
901
|
+
end
|
902
|
+
|
903
|
+
it "should not be last?" do
|
904
|
+
@feed.should_not be_last
|
905
|
+
end
|
906
|
+
|
907
|
+
it "should have next" do
|
908
|
+
@feed.next_page.href.should == 'http://example.org/index.atom?page=2'
|
909
|
+
end
|
910
|
+
|
911
|
+
it "should not have prev" do
|
912
|
+
@feed.prev_page.should be_nil
|
913
|
+
end
|
914
|
+
|
915
|
+
it "should have last" do
|
916
|
+
@feed.last_page.href.should == 'http://example.org/index.atom?page=10'
|
917
|
+
end
|
918
|
+
|
919
|
+
it "should have first" do
|
920
|
+
@feed.first_page.href.should == 'http://example.org/index.atom'
|
921
|
+
end
|
922
|
+
end
|
923
|
+
|
924
|
+
describe 'middle_paged_feed.atom' do
|
925
|
+
before(:all) do
|
926
|
+
@feed = Atom::Feed.load_feed(File.open('spec/paging/middle_paged_feed.atom'))
|
927
|
+
end
|
928
|
+
|
929
|
+
it "should not be last?" do
|
930
|
+
@feed.should_not be_last
|
931
|
+
end
|
932
|
+
|
933
|
+
it "should not be first?" do
|
934
|
+
@feed.should_not be_first
|
935
|
+
end
|
936
|
+
|
937
|
+
it "should have next_page" do
|
938
|
+
@feed.next_page.href.should == 'http://example.org/index.atom?page=4'
|
939
|
+
end
|
940
|
+
|
941
|
+
it "should have prev_page" do
|
942
|
+
@feed.prev_page.href.should == 'http://example.org/index.atom?page=2'
|
943
|
+
end
|
944
|
+
|
945
|
+
it "should have last_page" do
|
946
|
+
@feed.last_page.href.should == 'http://example.org/index.atom?page=10'
|
947
|
+
end
|
948
|
+
|
949
|
+
it "should have first_page" do
|
950
|
+
@feed.first_page.href.should == 'http://example.org/index.atom'
|
951
|
+
end
|
952
|
+
end
|
953
|
+
|
954
|
+
describe 'last_paged_feed.atom' do
|
955
|
+
before(:all) do
|
956
|
+
@feed = Atom::Feed.load_feed(File.open('spec/paging/last_paged_feed.atom'))
|
957
|
+
end
|
958
|
+
|
959
|
+
it "should not be first?" do
|
960
|
+
@feed.should_not be_first
|
961
|
+
end
|
962
|
+
|
963
|
+
it "should be last?" do
|
964
|
+
@feed.should be_last
|
965
|
+
end
|
966
|
+
|
967
|
+
it "should have prev_page" do
|
968
|
+
@feed.prev_page.href.should == 'http://example.org/index.atom?page=9'
|
969
|
+
end
|
970
|
+
|
971
|
+
it "should not have next_page" do
|
972
|
+
@feed.next_page.should be_nil
|
973
|
+
end
|
974
|
+
|
975
|
+
it "should have first_page" do
|
976
|
+
@feed.first_page.href.should == 'http://example.org/index.atom'
|
977
|
+
end
|
978
|
+
|
979
|
+
it "should have last_page" do
|
980
|
+
@feed.last_page.href.should == 'http://example.org/index.atom?page=10'
|
981
|
+
end
|
982
|
+
end
|
983
|
+
|
984
|
+
describe 'pagination using each_entry' do
|
985
|
+
before(:each) do
|
986
|
+
@feed = Atom::Feed.load_feed(File.open('spec/paging/first_paged_feed.atom'))
|
987
|
+
end
|
988
|
+
|
989
|
+
it "should paginate through each entry" do
|
990
|
+
feed1 = Atom::Feed.load_feed(File.read('spec/paging/middle_paged_feed.atom'))
|
991
|
+
feed2 = Atom::Feed.load_feed(File.read('spec/paging/last_paged_feed.atom'))
|
992
|
+
|
993
|
+
Atom::Feed.should_receive(:load_feed).
|
994
|
+
with(URI.parse('http://example.org/index.atom?page=2'), an_instance_of(Hash)).
|
995
|
+
and_return(feed1)
|
996
|
+
Atom::Feed.should_receive(:load_feed).
|
997
|
+
with(URI.parse('http://example.org/index.atom?page=4'), an_instance_of(Hash)).
|
998
|
+
and_return(feed2)
|
999
|
+
|
1000
|
+
entry_count = 0
|
1001
|
+
@feed.each_entry(:paginate => true) do |entry|
|
1002
|
+
entry_count += 1
|
1003
|
+
end
|
1004
|
+
|
1005
|
+
entry_count.should == 3
|
1006
|
+
end
|
1007
|
+
|
1008
|
+
it "should not paginate through each entry when paginate not true" do
|
1009
|
+
entry_count = 0
|
1010
|
+
@feed.each_entry do |entry|
|
1011
|
+
entry_count += 1
|
1012
|
+
end
|
1013
|
+
|
1014
|
+
entry_count.should == 1
|
1015
|
+
end
|
1016
|
+
|
1017
|
+
it "should only paginate up to since" do
|
1018
|
+
response1 = Net::HTTPSuccess.new(nil, nil, nil)
|
1019
|
+
response1.stub!(:body).and_return(File.read('spec/paging/middle_paged_feed.atom'))
|
1020
|
+
mock_http_get(URI.parse('http://example.org/index.atom?page=2'), response1)
|
1021
|
+
|
1022
|
+
entry_count = 0
|
1023
|
+
@feed.each_entry(:paginate => true, :since => Time.parse('2003-11-19T18:30:02Z')) do |entry|
|
1024
|
+
entry_count += 1
|
1025
|
+
end
|
1026
|
+
|
1027
|
+
entry_count.should == 1
|
1028
|
+
end
|
1029
|
+
end
|
1030
|
+
|
1031
|
+
describe "entry_with_simple_extensions.atom" do
|
1032
|
+
before(:each) do
|
1033
|
+
@feed = Atom::Feed.load_feed(File.open('spec/fixtures/entry_with_simple_extensions.atom'))
|
1034
|
+
@entry = @feed.entries.first
|
1035
|
+
end
|
1036
|
+
|
1037
|
+
it "should load simple extension for feed" do
|
1038
|
+
@feed["http://example.org/example", 'simple1'].should == ['Simple1 Value']
|
1039
|
+
end
|
1040
|
+
|
1041
|
+
it "should load empty simple extension for feed" do
|
1042
|
+
@feed["http://example.org/example", 'simple-empty'].should == ['']
|
1043
|
+
end
|
1044
|
+
|
1045
|
+
it "should load simple extension 1 for entry" do
|
1046
|
+
@entry["http://example.org/example", 'simple1'].should == ['Simple1 Entry Value']
|
1047
|
+
end
|
1048
|
+
|
1049
|
+
it "should load simple extension 2 for entry" do
|
1050
|
+
@entry["http://example.org/example", 'simple2'].should == ['Simple2', 'Simple2a']
|
1051
|
+
end
|
1052
|
+
|
1053
|
+
it "should find a simple extension in another namespace" do
|
1054
|
+
@entry["http://example2.org/example2", 'simple1'].should == ['Simple Entry Value (NS2)']
|
1055
|
+
end
|
1056
|
+
|
1057
|
+
it "should load simple extension attribute on a category" do
|
1058
|
+
@entry.categories.first["http://example.org/example", "attribute"].first.should == "extension"
|
1059
|
+
end
|
1060
|
+
|
1061
|
+
it "should write a simple extension attribute as an attribute" do
|
1062
|
+
@entry.categories.first.to_xml(true)['ns1:attribute'].should == 'extension'
|
1063
|
+
end
|
1064
|
+
|
1065
|
+
it "should read an extension with the same local name as an Atom element" do
|
1066
|
+
@feed['http://example.org/example', 'title'].should == ['Extension Title']
|
1067
|
+
end
|
1068
|
+
|
1069
|
+
it "should find simple extension with dashes in the name" do
|
1070
|
+
@entry["http://example.org/example", 'simple-with-dash'].should == ['Simple with dash Value']
|
1071
|
+
end
|
1072
|
+
|
1073
|
+
it_should_behave_like 'simple_single_entry.atom attributes'
|
1074
|
+
|
1075
|
+
it "should load simple extension 3 xml for entry" do
|
1076
|
+
@entry["http://example.org/example3", 'simple3'].should == ['<ContinuityOfCareRecord xmlns="urn:astm-org:CCR">Simple Entry Value (NS2)</ContinuityOfCareRecord>']
|
1077
|
+
end
|
1078
|
+
|
1079
|
+
describe "when only namespace is provided" do
|
1080
|
+
before :each do
|
1081
|
+
@example_elements = @entry["http://example.org/example"]
|
1082
|
+
@example2_elements = @entry['http://example2.org/example2']
|
1083
|
+
@example3_elements = @entry['http://example.org/example3']
|
1084
|
+
end
|
1085
|
+
|
1086
|
+
it "should return namespace elements as a hash" do
|
1087
|
+
@example_elements.should == {
|
1088
|
+
'simple1' => ['Simple1 Entry Value'],
|
1089
|
+
'simple2' => ['Simple2', 'Simple2a'],
|
1090
|
+
'simple-with-dash' => ["Simple with dash Value"]
|
1091
|
+
}
|
1092
|
+
|
1093
|
+
@example2_elements.should == {
|
1094
|
+
'simple1' => ['Simple Entry Value (NS2)']
|
1095
|
+
}
|
1096
|
+
|
1097
|
+
@example3_elements.should == {
|
1098
|
+
'simple3' => ['<ContinuityOfCareRecord xmlns="urn:astm-org:CCR">Simple Entry Value (NS2)</ContinuityOfCareRecord>']
|
1099
|
+
}
|
1100
|
+
end
|
1101
|
+
end
|
1102
|
+
end
|
1103
|
+
|
1104
|
+
describe 'writing simple extensions' do
|
1105
|
+
it "should recode and re-read a simple extension element" do
|
1106
|
+
entry = Atom::Entry.new do |entry|
|
1107
|
+
entry.id = 'urn:test'
|
1108
|
+
entry.title = 'Simple Ext. Test'
|
1109
|
+
entry.updated = Time.now
|
1110
|
+
entry['http://example.org', 'title'] << 'Example title'
|
1111
|
+
end
|
1112
|
+
|
1113
|
+
entry2 = Atom::Entry.load_entry(entry.to_xml)
|
1114
|
+
entry2['http://example.org', 'title'].should == ['Example title']
|
1115
|
+
end
|
1116
|
+
end
|
1117
|
+
end
|
1118
|
+
|
1119
|
+
describe 'custom_extensions' do
|
1120
|
+
before(:all) do
|
1121
|
+
Atom::Entry.add_extension_namespace :ns_alias, "http://custom.namespace"
|
1122
|
+
Atom::Entry.elements "ns_alias:property", :class => Atom::Extensions::Property
|
1123
|
+
Atom::Entry.elements "ns_alias:property-with-dash", :class => Atom::Extensions::Property
|
1124
|
+
@entry = Atom::Entry.load_entry(File.open('spec/fixtures/entry_with_custom_extensions.atom'))
|
1125
|
+
end
|
1126
|
+
|
1127
|
+
it "should_load_custom_extensions_for_entry" do
|
1128
|
+
@entry.ns_alias_property.should_not == []
|
1129
|
+
end
|
1130
|
+
|
1131
|
+
it "should_load_2_custom_extensions_for_entry" do
|
1132
|
+
@entry.ns_alias_property.size.should == 2
|
1133
|
+
end
|
1134
|
+
|
1135
|
+
it "should load correct_data_for_custom_extensions_for_entry" do
|
1136
|
+
@entry.ns_alias_property.map { |x| [x.name, x.value] }.should == [['foo', 'bar'], ['baz', 'bat']]
|
1137
|
+
end
|
1138
|
+
end
|
1139
|
+
|
1140
|
+
describe 'single custom_extensions' do
|
1141
|
+
before(:all) do
|
1142
|
+
Atom::Entry.add_extension_namespace :custom, "http://single.custom.namespace"
|
1143
|
+
Atom::Entry.element "custom:singleproperty", :class => Atom::Extensions::Property
|
1144
|
+
@entry = Atom::Entry.load_entry(File.open('spec/fixtures/entry_with_single_custom_extension.atom'))
|
1145
|
+
end
|
1146
|
+
|
1147
|
+
it "should load single custom extensions for entry" do
|
1148
|
+
@entry.custom_singleproperty.should_not be_nil
|
1149
|
+
end
|
1150
|
+
|
1151
|
+
it "should load correct data for custom extensions for entry" do
|
1152
|
+
@entry.custom_singleproperty.name.should == 'foo'
|
1153
|
+
@entry.custom_singleproperty.value.should == 'bar'
|
1154
|
+
end
|
1155
|
+
end
|
1156
|
+
|
1157
|
+
describe 'write_support' do
|
1158
|
+
# FIXME this example depends on "custom_extensions" for configuring Atom::Entry
|
1159
|
+
before(:all) do
|
1160
|
+
@entry = Atom::Entry.new
|
1161
|
+
@entry.ns_alias_property << Atom::Extensions::Property.new('ratom', 'rocks')
|
1162
|
+
@entry.ns_alias_property << Atom::Extensions::Property.new('custom extensions', 'also rock')
|
1163
|
+
@node = @entry.to_xml(true)
|
1164
|
+
end
|
1165
|
+
|
1166
|
+
it "should_write_custom_extensions_on_to_xml" do
|
1167
|
+
@node.children.size.should == 2
|
1168
|
+
ratom, custom_extensions = @node.children
|
1169
|
+
ratom.attributes["name"].should == "ratom"
|
1170
|
+
ratom.attributes["value"].should == "rocks"
|
1171
|
+
custom_extensions.attributes["name"].should == "custom extensions"
|
1172
|
+
custom_extensions.attributes["value"].should == "also rock"
|
1173
|
+
end
|
1174
|
+
end
|
1175
|
+
|
1176
|
+
describe Atom::Link do
|
1177
|
+
before(:each) do
|
1178
|
+
@href = 'http://example.org/next'
|
1179
|
+
@link = Atom::Link.new(:rel => 'next', :href => @href)
|
1180
|
+
end
|
1181
|
+
|
1182
|
+
it "should fetch feed for fetch_next" do
|
1183
|
+
Atom::Feed.should_receive(:load_feed).with(URI.parse(@href), an_instance_of(Hash))
|
1184
|
+
@link.fetch
|
1185
|
+
end
|
1186
|
+
|
1187
|
+
it "should fetch content when response is not xml" do
|
1188
|
+
Atom::Feed.should_receive(:load_feed).and_raise(Atom::LoadError)
|
1189
|
+
response = Net::HTTPSuccess.new(nil, nil, nil)
|
1190
|
+
response.stub!(:body).and_return('some text.')
|
1191
|
+
Net::HTTP.should_receive(:get_response).with(URI.parse(@href)).and_return(response)
|
1192
|
+
@link.fetch.should == 'some text.'
|
1193
|
+
end
|
1194
|
+
end
|
1195
|
+
|
1196
|
+
describe Atom::Entry do
|
1197
|
+
before(:all) do
|
1198
|
+
@entry = Atom::Entry.load_entry(File.read('spec/fixtures/entry.atom'))
|
1199
|
+
end
|
1200
|
+
|
1201
|
+
it "should be == to itself" do
|
1202
|
+
@entry.should == Atom::Entry.load_entry(File.read('spec/fixtures/entry.atom'))
|
1203
|
+
end
|
1204
|
+
|
1205
|
+
it "should be != if something changes" do
|
1206
|
+
@other = Atom::Entry.load_entry(File.read('spec/fixtures/entry.atom'))
|
1207
|
+
@other.title = 'foo'
|
1208
|
+
@entry.should_not == @other
|
1209
|
+
end
|
1210
|
+
|
1211
|
+
it "should be != if content changes" do
|
1212
|
+
@other = Atom::Entry.load_entry(File.read('spec/fixtures/entry.atom'))
|
1213
|
+
@other.content.type = 'html'
|
1214
|
+
@entry.should_not == @other
|
1215
|
+
end
|
1216
|
+
|
1217
|
+
it "should output itself" do
|
1218
|
+
other = Atom::Entry.load_entry(@entry.to_xml)
|
1219
|
+
@entry.should == other
|
1220
|
+
end
|
1221
|
+
|
1222
|
+
it "should properly escape titles" do
|
1223
|
+
@entry.title = "Breaking Space"
|
1224
|
+
other = Atom::Entry.load_entry(@entry.to_xml)
|
1225
|
+
@entry.should == other
|
1226
|
+
end
|
1227
|
+
|
1228
|
+
it "should raise error when to_xml'ing non-utf8 content" do
|
1229
|
+
lambda {
|
1230
|
+
puts(Atom::Entry.new do |entry|
|
1231
|
+
entry.title = "My entry"
|
1232
|
+
entry.id = "urn:entry:1"
|
1233
|
+
entry.content = Atom::Content::Html.new("this is not \227 utf8")
|
1234
|
+
end.to_xml)
|
1235
|
+
}.should raise_error(Atom::SerializationError)
|
1236
|
+
end
|
1237
|
+
end
|
1238
|
+
|
1239
|
+
describe 'Atom::Feed initializer' do
|
1240
|
+
it "should create an empty Feed" do
|
1241
|
+
lambda { Atom::Feed.new }.should_not raise_error
|
1242
|
+
end
|
1243
|
+
|
1244
|
+
it "should yield to a block" do
|
1245
|
+
lambda do
|
1246
|
+
Atom::Feed.new do |f|
|
1247
|
+
f.should be_an_instance_of(Atom::Feed)
|
1248
|
+
throw :yielded
|
1249
|
+
end
|
1250
|
+
end.should throw_symbol(:yielded)
|
1251
|
+
end
|
1252
|
+
end
|
1253
|
+
|
1254
|
+
describe 'Atom::Entry initializer' do
|
1255
|
+
it "should create an empty feed" do
|
1256
|
+
lambda { Atom::Entry.new }.should_not raise_error
|
1257
|
+
end
|
1258
|
+
|
1259
|
+
it "should yield to a block" do
|
1260
|
+
lambda do
|
1261
|
+
Atom::Entry.new do |f|
|
1262
|
+
f.should be_an_instance_of(Atom::Entry)
|
1263
|
+
throw :yielded
|
1264
|
+
end
|
1265
|
+
end.should throw_symbol(:yielded)
|
1266
|
+
end
|
1267
|
+
end
|
1268
|
+
|
1269
|
+
describe Atom::Content::Html do
|
1270
|
+
it "should escape ampersands in entities" do
|
1271
|
+
Atom::Content::Html.new(" ").to_xml.to_s.should == "<content type=\"html\">&nbsp;</content>"
|
1272
|
+
end
|
1273
|
+
end
|
1274
|
+
|
1275
|
+
describe Atom::Content::Text do
|
1276
|
+
it "should be createable from a string" do
|
1277
|
+
txt = Atom::Content::Text.new("This is some text")
|
1278
|
+
txt.should == "This is some text"
|
1279
|
+
txt.type.should == "text"
|
1280
|
+
end
|
1281
|
+
end
|
1282
|
+
|
1283
|
+
describe Atom::Content::Xhtml do
|
1284
|
+
it "should be createable from a string" do
|
1285
|
+
txt = Atom::Content::Xhtml.new("<p>This is some text</p>")
|
1286
|
+
txt.should == "<p>This is some text</p>"
|
1287
|
+
txt.type.should == "xhtml"
|
1288
|
+
end
|
1289
|
+
|
1290
|
+
it "should be renderable to xml" do
|
1291
|
+
txt = Atom::Content::Xhtml.new("<p>This is some text</p>")
|
1292
|
+
txt.to_xml.should_not raise_error("TypeError")
|
1293
|
+
end
|
1294
|
+
end
|
1295
|
+
|
1296
|
+
describe Atom::Content::External do
|
1297
|
+
before(:each) do
|
1298
|
+
feed = nil
|
1299
|
+
lambda { feed = Atom::Feed.load_feed(File.open('spec/fixtures/external_content_single_entry.atom')) }.should_not raise_error
|
1300
|
+
entry = feed.entries.first
|
1301
|
+
entry.content.should_not be_nil
|
1302
|
+
@content = entry.content
|
1303
|
+
@content.class.should == Atom::Content::External
|
1304
|
+
end
|
1305
|
+
|
1306
|
+
it "should capture the src" do
|
1307
|
+
@content.type.should == 'application/pdf'
|
1308
|
+
@content.src.should == 'http://example.org/pdfs/robots-run-amok.pdf'
|
1309
|
+
end
|
1310
|
+
|
1311
|
+
it "should include type and src in the serialized xml" do
|
1312
|
+
xml = @content.to_xml
|
1313
|
+
xml['type'].should == 'application/pdf'
|
1314
|
+
xml['src'].should == 'http://example.org/pdfs/robots-run-amok.pdf'
|
1315
|
+
end
|
1316
|
+
end
|
1317
|
+
|
1318
|
+
describe 'Atom::Category initializer' do
|
1319
|
+
it "should create a empty category" do
|
1320
|
+
lambda { Atom::Category.new }.should_not raise_error
|
1321
|
+
end
|
1322
|
+
|
1323
|
+
it "should create from a hash" do
|
1324
|
+
category = Atom::Category.new(:term => 'term', :scheme => 'scheme', :label => 'label')
|
1325
|
+
category.term.should == 'term'
|
1326
|
+
category.scheme.should == 'scheme'
|
1327
|
+
category.label.should == 'label'
|
1328
|
+
end
|
1329
|
+
|
1330
|
+
it "should create from a block" do
|
1331
|
+
category = Atom::Category.new do |cat|
|
1332
|
+
cat.term = 'term'
|
1333
|
+
end
|
1334
|
+
|
1335
|
+
category.term.should == 'term'
|
1336
|
+
end
|
1337
|
+
end
|
1338
|
+
|
1339
|
+
describe Atom::Source do
|
1340
|
+
it "should create an empty source" do
|
1341
|
+
lambda { Atom::Source.new }.should_not raise_error
|
1342
|
+
end
|
1343
|
+
|
1344
|
+
it "should create from a hash" do
|
1345
|
+
source = Atom::Source.new(:title => 'title', :id => 'sourceid')
|
1346
|
+
source.title.should == 'title'
|
1347
|
+
source.id.should == 'sourceid'
|
1348
|
+
end
|
1349
|
+
|
1350
|
+
it "should create from a block" do
|
1351
|
+
source = Atom::Source.new do |source|
|
1352
|
+
source.title = 'title'
|
1353
|
+
source.id = 'sourceid'
|
1354
|
+
end
|
1355
|
+
source.title.should == 'title'
|
1356
|
+
source.id.should == 'sourceid'
|
1357
|
+
end
|
1358
|
+
end
|
1359
|
+
|
1360
|
+
describe Atom::Generator do
|
1361
|
+
it "should create an empty generator" do
|
1362
|
+
lambda { Atom::Generator.new }.should_not raise_error
|
1363
|
+
end
|
1364
|
+
|
1365
|
+
it "should create from a hash" do
|
1366
|
+
generator = Atom::Generator.new(:name => 'generator', :uri => 'http://generator')
|
1367
|
+
generator.name.should == 'generator'
|
1368
|
+
generator.uri.should == 'http://generator'
|
1369
|
+
end
|
1370
|
+
|
1371
|
+
it "should create from a block" do
|
1372
|
+
generator = Atom::Generator.new do |generator|
|
1373
|
+
generator.name = 'generator'
|
1374
|
+
generator.uri = 'http://generator'
|
1375
|
+
end
|
1376
|
+
generator.name.should == 'generator'
|
1377
|
+
generator.uri.should == 'http://generator'
|
1378
|
+
end
|
1379
|
+
|
1380
|
+
it "should output the name as the text of the generator element" do
|
1381
|
+
generator = Atom::Generator.new({:name => "My Generator"})
|
1382
|
+
generator.to_xml(true).to_s.should == "<generator>My Generator</generator>"
|
1383
|
+
end
|
1384
|
+
end
|
1385
|
+
end
|