atomutil 0.0.1

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.
@@ -0,0 +1,44 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe Atom::Categories, "categories handler" do
4
+
5
+ it "should handle attributes and elements collectly with each accessor" do
6
+ cats = Atom::Categories.new
7
+ cats.fixed = 'yes'
8
+ cats.fixed.should == 'yes'
9
+ cats.scheme = 'http://example.org/extra-cats/'
10
+ cats.scheme.should == 'http://example.org/extra-cats/'
11
+ end
12
+
13
+ it "should handle attributes and elements collectly with hash-type parameter" do
14
+ cats = Atom::Categories.new :fixed => 'yes', :scheme => 'http://example.org/extra-cats/'
15
+ cats.fixed.should == 'yes'
16
+ cats.scheme.should == 'http://example.org/extra-cats/'
17
+ end
18
+
19
+
20
+ it "should handle Atom::Category objects collectly" do
21
+ cats = Atom::Categories.new
22
+ cats.fixed = 'yes'
23
+ cats.scheme = 'http://example.org/extra-cats/'
24
+ cat = Atom::Category.new
25
+ cat.scheme = "http://example.org/extra-cats/"
26
+ cat.term = "joke"
27
+ cats.add_category cat
28
+ first = cats.categories.first
29
+ first.scheme.should == "http://example.org/extra-cats/"
30
+ first.term.should == "joke"
31
+ cat2 = Atom::Category.new
32
+ cat2.scheme = "http://example.org/extra-cats/"
33
+ cat2.term = "serious"
34
+ cats.add_category cat2
35
+ cats2 = cats.categories
36
+ cats2[0].scheme.should == "http://example.org/extra-cats/"
37
+ cats2[0].term.should == "joke"
38
+ cats2[1].scheme.should == "http://example.org/extra-cats/"
39
+ cats2[1].term.should == "serious"
40
+ cats_xml = cats.to_s
41
+ cats_xml.should =~ %r{<categories(?: xmlns='http://www.w3.org/2007/app')?}
42
+ end
43
+
44
+ end
@@ -0,0 +1,27 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe Atom::Category, "category object" do
4
+
5
+ before(:all) do
6
+ @cat = Atom::Category.new
7
+ @cat.term = "foo"
8
+ @cat.label = "bar"
9
+ @cat.scheme = "http://example.com/"
10
+ end
11
+
12
+ it "should handle parameters collectly" do
13
+ @cat.term.should == "foo"
14
+ @cat.label.should == "bar"
15
+ @cat.scheme.should == "http://example.com/"
16
+ end
17
+
18
+ it "should build xml collectly" do
19
+ cat_xml = @cat.to_s
20
+ cat_xml.should =~ /<category\s.*\/>/
21
+ cat_xml.should =~ /term='foo'/
22
+ cat_xml.should =~ /label='bar'/
23
+ cat_xml.should =~ /scheme='http:\/\/example\.com\/'/
24
+ end
25
+
26
+ end
27
+
@@ -0,0 +1,56 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe Atom::Content, "setter/getter and building xml" do
4
+
5
+ it "should set and get type" do
6
+ content = Atom::Content.new
7
+ content.type = "image/jpeg"
8
+ content.type.should == "image/jpeg"
9
+ content.type = "application/gzip"
10
+ content.type.should == "application/gzip"
11
+ end
12
+
13
+ it "should construct with body collectly" do
14
+ content = Atom::Content.new :body => 'This is a test'
15
+ content.body.should == 'This is a test'
16
+ content.type.should == 'text'
17
+ end
18
+
19
+ it "should set body and type collectly" do
20
+ content = Atom::Content.new :body => 'This is a test', :type => 'text/bar'
21
+ content.body.should == 'This is a test'
22
+ content.type.should == 'text/bar'
23
+ end
24
+
25
+ it "should handle text body collectly" do
26
+ content = Atom::Content.new
27
+ content.body = 'This is a test'
28
+ content.body.should == 'This is a test'
29
+ content.type = 'foo/bar'
30
+ content.type.should == 'foo/bar'
31
+ end
32
+
33
+ it "should handle xhtml body collectly" do
34
+ content = Atom::Content.new
35
+ content.body = '<p>This is a test with XHTML</p>'
36
+ content.body.should == '<p>This is a test with XHTML</p>'
37
+ content.type.should == 'xhtml'
38
+ end
39
+
40
+ it "should handle invalid xhtml body collectly" do
41
+ content = Atom::Content.new
42
+ content.body = '<p>This is a test with invalid XHTML'
43
+ content.body.should == '<p>This is a test with invalid XHTML'
44
+ content.type.should == 'html'
45
+ end
46
+
47
+ it "should handle image data collectly" do
48
+ content = Atom::Content.new
49
+ content.type = 'image/jpeg'
50
+ content.body = "\xff\xde\xde\xde"
51
+ content.type.should == 'image/jpeg'
52
+ content.body.should == "\xff\xde\xde\xde"
53
+ end
54
+
55
+ end
56
+
@@ -0,0 +1,68 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe Atom::Feed, "customized with other namespace" do
4
+
5
+ it "should parse and handle openSearch elements collectly" do
6
+ xmlstring = <<-EOS
7
+ <feed xmlns="http://www.w3.org/2005/Atom"
8
+ xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.1/">
9
+ <title>Example</title>
10
+ <icon>http://example.org/feed/icon.jpeg</icon>
11
+ <openSearch:totalResult>153</openSearch:totalResult>
12
+ <openSearch:startIndex>40</openSearch:startIndex>
13
+ <openSearch:itemsPerPage>20</openSearch:itemsPerPage>
14
+ </feed>
15
+ EOS
16
+ feed = Atom::Feed.new :stream => xmlstring
17
+ feed.get(Atom::Namespace::OPEN_SEARCH, 'totalResult').text.to_i.should == 153
18
+ feed.get(Atom::Namespace::OPEN_SEARCH, 'startIndex').text.to_i.should == 40
19
+ feed.get(Atom::Namespace::OPEN_SEARCH, 'itemsPerPage').text.to_i.should == 20
20
+ end
21
+
22
+ it "should build and handle openSearch elements collectly" do
23
+ feed = Atom::Feed.new
24
+ feed.title = 'Example'
25
+ feed.set(Atom::Namespace::OPEN_SEARCH, 'totalResult', 153)
26
+ feed.set(Atom::Namespace::OPEN_SEARCH, 'startIndex', 40)
27
+ feed.set(Atom::Namespace::OPEN_SEARCH, 'itemsPerPage', 20)
28
+ feed.get(Atom::Namespace::OPEN_SEARCH, 'totalResult').text.to_i.should == 153
29
+ feed.get(Atom::Namespace::OPEN_SEARCH, 'startIndex').text.to_i.should == 40
30
+ feed.get(Atom::Namespace::OPEN_SEARCH, 'itemsPerPage').text.to_i.should == 20
31
+ end
32
+
33
+ it "shoudl parse and handle more complex elements" do
34
+ xmlstring = <<-EOS
35
+ <feed xmlns="http://www.w3.org/2005/Atom"
36
+ xmlns:myns="http://example.org/2007/example">
37
+ <title>Example</title>
38
+ <icon>http://example.org/feed/icon.jpg</icon>
39
+ <myns:foo><myns:bar buz="Buz">Bar</myns:bar></myns:foo>
40
+ </feed>
41
+ EOS
42
+ myns = Atom::Namespace.new :prefix => 'myns', :uri => 'http://example.org/2007/example'
43
+ feed = Atom::Feed.new :stream => xmlstring
44
+ foo = feed.get(myns, 'foo')
45
+ foo.class.should == REXML::Element
46
+ bar = foo.elements[1]
47
+ bar.class.should == REXML::Element
48
+ bar.attributes['buz'].should == 'Buz'
49
+ bar.text.should == 'Bar'
50
+ end
51
+
52
+ it "should build and handle more complex elements" do
53
+ myns = Atom::Namespace.new :prefix => 'myns', :uri => 'http://example.org/2007/example'
54
+ feed = Atom::Feed.new :title => 'Example'
55
+ bar = REXML::Element.new("#{myns.prefix}:bar")
56
+ bar.text = 'Bar'
57
+ bar.add_attribute(REXML::Attribute.new("buz", 'Buz'))
58
+ feed.set(myns, 'foo', bar)
59
+ foo = feed.get(myns, 'foo')
60
+ foo.class.should == REXML::Element
61
+ bar2 = foo.elements[1]
62
+ bar2.class.should == REXML::Element
63
+ bar2.attributes['buz'].should == 'Buz'
64
+ bar.text.should == 'Bar'
65
+ end
66
+
67
+ end
68
+
data/spec/feed_spec.rb ADDED
@@ -0,0 +1,227 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe Atom::Feed, "feed object" do
4
+
5
+ it "should handle feed from file with filepath" do
6
+ path = File.join(File.dirname(__FILE__), 'samples', 'feed.atom')
7
+ feed = Atom::Feed.new :file => path
8
+ feed.title.should == 'dive into mark'
9
+ feed.id.should == 'tag:example.org,2003:3'
10
+ feed.updated.iso8601.should == '2005-07-31T12:29:29Z'
11
+ feed.alternate_link.should == 'http://example.org/'
12
+ feed.self_link.should == 'http://example.org/feed.atom'
13
+ feed.rights.should == 'Copyright (c) 2003, Mark Pilgrim'
14
+ feed.generator.name.gsub(/^[\s\n]*(.+)[\s\n]*$/, '\1').should == 'Example Toolkit'
15
+ entry = feed.entries[0]
16
+ entry.title.should == 'Atom draft-07 snapshot'
17
+ entry.id.should == 'tag:example.org,2003:3.2397'
18
+ entry.updated.iso8601.should == '2005-07-31T12:29:29Z'
19
+ entry.published.iso8601.should == Time.iso8601('2003-12-13T08:29:29-04:00').iso8601
20
+ entry.alternate_link.should == 'http://example.org/2005/04/02/atom'
21
+ entry.enclosure_link.should == 'http://example.org/audio/ph34r_my_podcast.mp3'
22
+ author = entry.author
23
+ author.name.should == 'Mark Pilgrim'
24
+ author.uri.should == 'http://example.org/'
25
+ author.email.should == 'f8dy@example.com'
26
+ homepage = author.get(Atom::Namespace::FOAF, 'homepage')
27
+ homepage.class.should == REXML::Element
28
+ homepage.attributes['rdf:resource'].should == 'http://www.example.org/blog'
29
+ img = author.get(Atom::Namespace::FOAF, 'img')
30
+ img.class.should == REXML::Element
31
+ img.attributes['rdf:resource'].should == 'http://www.example.org/mypic.png'
32
+
33
+ contributors = entry.contributors
34
+ contributors.size.should == 2
35
+ contributors[0].name.should == 'Sam Ruby'
36
+ contributors[1].name.should == 'Joe Gregorio'
37
+
38
+ content = entry.content
39
+ content.type.should == 'xhtml'
40
+ body = content.body
41
+ body.gsub(/^[\n\s]*(.+)[\n\s]*$/, '\1').should == '<p><i>[Update: The Atom draft is finished.]</i></p>'
42
+ end
43
+
44
+ it "should handle feed from file with Pathname object" do
45
+ path = Pathname.new(File.join(File.dirname(__FILE__), 'samples', 'feed.atom'))
46
+ feed = Atom::Feed.new :file => path
47
+ feed.title.should == 'dive into mark'
48
+ feed.id.should == 'tag:example.org,2003:3'
49
+ feed.updated.iso8601.should == '2005-07-31T12:29:29Z'
50
+ feed.alternate_link.should == 'http://example.org/'
51
+ feed.self_link.should == 'http://example.org/feed.atom'
52
+ feed.rights.should == 'Copyright (c) 2003, Mark Pilgrim'
53
+ feed.generator.name.gsub(/^[\s\n]*(.+)[\s\n]*$/, '\1').should == 'Example Toolkit'
54
+ entry = feed.entries[0]
55
+ entry.title.should == 'Atom draft-07 snapshot'
56
+ entry.id.should == 'tag:example.org,2003:3.2397'
57
+ entry.updated.iso8601.should == '2005-07-31T12:29:29Z'
58
+ entry.published.iso8601.should == Time.iso8601('2003-12-13T08:29:29-04:00').iso8601
59
+ entry.alternate_link.should == 'http://example.org/2005/04/02/atom'
60
+ entry.enclosure_link.should == 'http://example.org/audio/ph34r_my_podcast.mp3'
61
+ author = entry.author
62
+ author.name.should == 'Mark Pilgrim'
63
+ author.uri.should == 'http://example.org/'
64
+ author.email.should == 'f8dy@example.com'
65
+ homepage = author.get(Atom::Namespace::FOAF, 'homepage')
66
+ homepage.class.should == REXML::Element
67
+ homepage.attributes['rdf:resource'].should == 'http://www.example.org/blog'
68
+ img = author.get(Atom::Namespace::FOAF, 'img')
69
+ img.class.should == REXML::Element
70
+ img.attributes['rdf:resource'].should == 'http://www.example.org/mypic.png'
71
+
72
+ contributors = entry.contributors
73
+ contributors.size.should == 2
74
+ contributors[0].name.should == 'Sam Ruby'
75
+ contributors[1].name.should == 'Joe Gregorio'
76
+
77
+ content = entry.content
78
+ content.type.should == 'xhtml'
79
+ body = content.body
80
+ body.gsub(/^[\n\s]*(.+)[\n\s]*$/, '\1').should == '<p><i>[Update: The Atom draft is finished.]</i></p>'
81
+ end
82
+ #it "should handle feed from uri" do
83
+ # feed = Atom::Feed.new :uri => ''
84
+ #end
85
+
86
+ it "should handle feed from stream" do
87
+ xmlstring = <<-EOS
88
+ <?xml version="1.0" encoding="utf-8"?>
89
+
90
+ <feed xmlns="http://www.w3.org/2005/Atom"
91
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
92
+ xmlns:foaf="http://xmlns.com/foaf/0.1">
93
+
94
+ <title type="text">dive into mark</title>
95
+ <id>tag:example.org,2003:3</id>
96
+
97
+ <updated>2005-07-31T12:29:29Z</updated>
98
+
99
+ <link rel="alternate" type="text/html"
100
+ hreflang="en" href="http://example.org/"/>
101
+ <link rel="self" type="application/atom+xml"
102
+ href="http://example.org/feed.atom"/>
103
+
104
+ <rights>Copyright (c) 2003, Mark Pilgrim</rights>
105
+ <generator uri="http://www.example.com/" version="1.0">
106
+ Example Toolkit
107
+ </generator>
108
+
109
+ <entry>
110
+ <title>Atom draft-07 snapshot</title>
111
+ <id>tag:example.org,2003:3.2397</id>
112
+
113
+ <updated>2005-07-31T12:29:29Z</updated>
114
+ <published>2003-12-13T08:29:29-04:00</published>
115
+
116
+ <link rel="alternate" type="text/html"
117
+ href="http://example.org/2005/04/02/atom"/>
118
+
119
+ <link rel="enclosure" type="audio/mpeg" length="1337"
120
+ href="http://example.org/audio/ph34r_my_podcast.mp3"/>
121
+
122
+ <author>
123
+ <name>Mark Pilgrim</name>
124
+ <uri>http://example.org/</uri>
125
+ <email>f8dy@example.com</email>
126
+
127
+ <foaf:homepage rdf:resource="http://www.example.org/blog" />
128
+ <foaf:img rdf:resource="http://www.example.org/mypic.png" />
129
+ </author>
130
+
131
+ <contributor>
132
+ <name>Sam Ruby</name>
133
+ </contributor>
134
+ <contributor>
135
+ <name>Joe Gregorio</name>
136
+ </contributor>
137
+
138
+ <content type="xhtml" xml:lang="en" xml:base="http://diveintomark.org/">
139
+ <div xmlns="http://www.w3.org/1999/xhtml">
140
+ <p><i>[Update: The Atom draft is finished.]</i></p>
141
+ </div>
142
+ </content>
143
+
144
+ </entry>
145
+
146
+ </feed>
147
+
148
+ EOS
149
+ feed = Atom::Feed.new :stream => xmlstring
150
+ feed.title.should == 'dive into mark'
151
+ feed.id.should == 'tag:example.org,2003:3'
152
+ feed.updated.iso8601.should == '2005-07-31T12:29:29Z'
153
+ feed.alternate_link.should == 'http://example.org/'
154
+ feed.self_link.should == 'http://example.org/feed.atom'
155
+ feed.rights.should == 'Copyright (c) 2003, Mark Pilgrim'
156
+ feed.generator.name.gsub(/^[\s\n]*(.+)[\s\n]*$/, '\1').should == 'Example Toolkit'
157
+ entry = feed.entries[0]
158
+ entry.title.should == 'Atom draft-07 snapshot'
159
+ entry.id.should == 'tag:example.org,2003:3.2397'
160
+ entry.updated.iso8601.should == '2005-07-31T12:29:29Z'
161
+ entry.published.iso8601.should == Time.iso8601('2003-12-13T08:29:29-04:00').iso8601
162
+ entry.alternate_link.should == 'http://example.org/2005/04/02/atom'
163
+ entry.enclosure_link.should == 'http://example.org/audio/ph34r_my_podcast.mp3'
164
+ author = entry.author
165
+ author.name.should == 'Mark Pilgrim'
166
+ author.uri.should == 'http://example.org/'
167
+ author.email.should == 'f8dy@example.com'
168
+ homepage = author.get(Atom::Namespace::FOAF, 'homepage')
169
+ homepage.class.should == REXML::Element
170
+ homepage.attributes['rdf:resource'].should == 'http://www.example.org/blog'
171
+ img = author.get(Atom::Namespace::FOAF, 'img')
172
+ img.class.should == REXML::Element
173
+ img.attributes['rdf:resource'].should == 'http://www.example.org/mypic.png'
174
+
175
+ contributors = entry.contributors
176
+ contributors.size.should == 2
177
+ contributors[0].name.should == 'Sam Ruby'
178
+ contributors[1].name.should == 'Joe Gregorio'
179
+
180
+ content = entry.content
181
+ content.type.should == 'xhtml'
182
+ body = content.body
183
+ body.gsub(/^[\n\s]*(.+)[\n\s]*$/, '\1').should == '<p><i>[Update: The Atom draft is finished.]</i></p>'
184
+ end
185
+
186
+ it "should build feed collectly" do
187
+
188
+ feed = Atom::Feed.new
189
+ feed.id = 'tag:example.org,2007:myexample'
190
+ feed.id.should == 'tag:example.org,2007:myexample'
191
+ feed.version = '1.00'
192
+ feed.version.should == '1.00'
193
+ feed.language = 'en'
194
+ feed.language.should == 'en'
195
+ feed.generator = 'MyFeedGenerator'
196
+ feed.generator.name.should == 'MyFeedGenerator'
197
+ feed.generator = Atom::Generator.new(
198
+ :name => 'MySecondGenerator',
199
+ :uri => 'http://example.org/generator',
200
+ :version => '1.00'
201
+ )
202
+ feed.generator.name.should == 'MySecondGenerator'
203
+ feed.generator.uri.should == 'http://example.org/generator'
204
+ feed.generator.version.should == '1.00'
205
+ feed.rights = 'Copyright(c) 2007, Example.'
206
+ feed.rights.should == 'Copyright(c) 2007, Example.'
207
+
208
+ author = Atom::Author.new
209
+ author.name = 'Atom User'
210
+ author.email = 'atom@example.org'
211
+ author.uri = 'http://example.org/atom'
212
+ feed.author = author
213
+
214
+ feed.language = 'fr'
215
+ feed.language.should == 'fr'
216
+
217
+ xmlstring = feed.to_s
218
+ xmlstring.should =~ %r{<feed}
219
+ xmlstring.should =~ %r{<author}
220
+ xmlstring.should =~ %r{<id}
221
+ xmlstring.should =~ %r{version='1.00'}
222
+ xmlstring.should =~ %r{xml:lang='fr'}
223
+ xmlstring.should =~ %r{<generator}
224
+ end
225
+
226
+ end
227
+
data/spec/link_spec.rb ADDED
@@ -0,0 +1,58 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe Atom::Link, "link object" do
4
+
5
+ it "should handle each accessors collectly" do
6
+ link = Atom::Link.new
7
+ link.title = 'This is a test'
8
+ link.title.should == 'This is a test'
9
+ link.title = 'Different title'
10
+ link.title.should == 'Different title'
11
+ link.rel = 'alternate'
12
+ link.rel.should == 'alternate'
13
+ link.href = 'http://example.org/'
14
+ link.href.should == 'http://example.org/'
15
+ link.type = 'text/html'
16
+ link.type.should == 'text/html'
17
+ link.length = 100
18
+ link.length.should == "100"
19
+ link.hreflang = 'ja'
20
+ link.hreflang.should == 'ja'
21
+ end
22
+
23
+ it "should handle hash-style parameter" do
24
+ link = Atom::Link.new(
25
+ :title => 'This is a test',
26
+ :rel => 'alternate',
27
+ :href => 'http://example.org/',
28
+ :type => 'text/html',
29
+ :length => 100,
30
+ :hreflang => 'ja'
31
+ )
32
+ link.title.should == 'This is a test'
33
+ link.rel.should == 'alternate'
34
+ link.href.should == 'http://example.org/'
35
+ link.type.should == 'text/html'
36
+ link.length.should == "100"
37
+ link.hreflang.should == 'ja'
38
+ end
39
+
40
+ it "should handle xml collectly" do
41
+ xmlstring = Atom::Link.new(
42
+ :title => 'This is a test',
43
+ :rel => 'alternate',
44
+ :href => 'http://example.org/',
45
+ :type => 'text/html',
46
+ :length => 100,
47
+ :hreflang => 'ja'
48
+ ).to_s
49
+ xmlstring.should =~ %r{<link}
50
+ xmlstring.should =~ %r{rel='alternate'}
51
+ xmlstring.should =~ %r{href='http://example\.org/'}
52
+ xmlstring.should =~ %r{type='text/html'}
53
+ xmlstring.should =~ %r{length='100'}
54
+ xmlstring.should =~ %r{hreflang='ja'}
55
+ end
56
+
57
+ end
58
+
@@ -0,0 +1,40 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe Atom::Namespace, "namespace object" do
4
+
5
+ it "should handle accessor collectly" do
6
+ my_ns = Atom::Namespace.new :uri => 'http://example.org/ns', :prefix => 'ex'
7
+ my_ns.prefix.should == 'ex'
8
+ my_ns.uri.should == 'http://example.org/ns'
9
+ my_ns.to_s.should == 'http://example.org/ns'
10
+ end
11
+
12
+ it "should handle major namespaces as constans" do
13
+ Atom::Namespace::ATOM.prefix.should be_nil
14
+ Atom::Namespace::ATOM.uri.should == 'http://www.w3.org/2005/Atom'
15
+ Atom::Namespace::ATOM_WITH_PREFIX.prefix.should == 'atom'
16
+ Atom::Namespace::ATOM_WITH_PREFIX.uri.should == 'http://www.w3.org/2005/Atom'
17
+ Atom::Namespace::OBSOLETE_ATOM.prefix.should be_nil
18
+ Atom::Namespace::OBSOLETE_ATOM.uri.should == 'http://purl.org/atom/ns#'
19
+ Atom::Namespace::OBSOLETE_ATOM_WITH_PREFIX.prefix.should == 'atom'
20
+ Atom::Namespace::OBSOLETE_ATOM_WITH_PREFIX.uri.should == 'http://purl.org/atom/ns#'
21
+ Atom::Namespace::APP.prefix.should be_nil
22
+ Atom::Namespace::APP.uri.should == 'http://www.w3.org/2007/app'
23
+ Atom::Namespace::APP_WITH_PREFIX.prefix.should == 'app'
24
+ Atom::Namespace::APP_WITH_PREFIX.uri.should == 'http://www.w3.org/2007/app'
25
+ Atom::Namespace::OBSOLETE_APP.prefix.should be_nil
26
+ Atom::Namespace::OBSOLETE_APP.uri.should == 'http://purl.org/atom/app#'
27
+ Atom::Namespace::OBSOLETE_APP_WITH_PREFIX.prefix.should == 'app'
28
+ Atom::Namespace::OBSOLETE_APP_WITH_PREFIX.uri.should == 'http://purl.org/atom/app#'
29
+ Atom::Namespace::OPEN_SEARCH.prefix.should == 'openSearch'
30
+ Atom::Namespace::OPEN_SEARCH.uri.should == 'http://a9.com/-/spec/opensearchrss/1.1/'
31
+ Atom::Namespace::FOAF.prefix.should == 'foaf'
32
+ Atom::Namespace::FOAF.uri.should == 'http://xmlns.com/foaf/0.1'
33
+ Atom::Namespace::DC.prefix.should == 'dc'
34
+ Atom::Namespace::DC.uri.should == 'http://purl.org/dc/elements/1.1/'
35
+ Atom::Namespace::RDF.prefix.should == 'rdf'
36
+ Atom::Namespace::RDF.uri.should == 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
37
+ end
38
+
39
+ end
40
+
@@ -0,0 +1,22 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe Atom::Feed, "extended with openSearch namespace" do
4
+
5
+ it "should handle openSearch namespace collectly" do
6
+ feed = Atom::Feed.new
7
+ feed.total_results = 30
8
+ feed.items_per_page = 10
9
+ feed.start_index = 1
10
+
11
+ feed.total_results.should == 30
12
+ feed.items_per_page.should == 10
13
+ feed.start_index.should == 1
14
+
15
+ xmlstring = feed.to_s
16
+ xmlstring.should =~ %r{<openSearch:totalResults}
17
+ xmlstring.should =~ %r{<openSearch:itemsPerPage}
18
+ xmlstring.should =~ %r{<openSearch:startIndex}
19
+ end
20
+
21
+ end
22
+
@@ -0,0 +1,61 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe Atom::Person, "builds" do
4
+
5
+ before do
6
+ @person = Atom::Person.new
7
+ end
8
+
9
+ it "should set and get name" do
10
+ @person.name = "Lyo Kato"
11
+ @person.name.should == "Lyo Kato"
12
+ end
13
+
14
+ it "should set and get email" do
15
+ @person.email = "lyo.kato@gmail.com"
16
+ @person.email.should == "lyo.kato@gmail.com"
17
+ end
18
+
19
+ it "should set and get uri" do
20
+ @person.uri = "http://www.lyokato.net/"
21
+ @person.uri.should == "http://www.lyokato.net/"
22
+ end
23
+
24
+ it "should build xml" do
25
+ @person.name = "Lyo Kato"
26
+ @person.email = "lyo.kato@gmail.com"
27
+ @person.uri = "http://www.lyokato.net/"
28
+ person_xml = @person.to_s
29
+ person_xml.should =~ /<author(?: xmlns='http:\/\/www\.w3\.org\/2005\/Atom')?>/
30
+ person_xml.should =~ /<name(?: xmlns='http:\/\/www\.w3\.org\/2005\/Atom')?>Lyo Kato<\/name>/
31
+ person_xml.should =~ /<email(?: xmlns='http:\/\/www\.w3\.org\/2005\/Atom')?>lyo\.kato\@gmail\.com<\/email>/
32
+ end
33
+
34
+ it "should be converted to Author" do
35
+ @person.name = "Lyo Kato"
36
+ @person.email = "lyo.kato@gmail.com"
37
+ @person.uri = "http://www.lyokato.net/"
38
+ author = @person.to_author
39
+ author.should be_instance_of(Atom::Author)
40
+ author.name.should == "Lyo Kato"
41
+ author_xml = author.to_s
42
+ author_xml.should =~ /<author(?: xmlns='http:\/\/www\.w3\.org\/2005\/Atom')?>/
43
+ author_xml.should =~ /<name(?: xmlns='http:\/\/www\.w3\.org\/2005\/Atom')?>Lyo Kato<\/name>/
44
+ author_xml.should =~ /<email(?: xmlns='http:\/\/www\.w3\.org\/2005\/Atom')?>lyo\.kato\@gmail\.com<\/email>/
45
+ end
46
+
47
+ it "should be converted to Contributor" do
48
+ @person.name = "Lyo Kato"
49
+ @person.email = "lyo.kato@gmail.com"
50
+ @person.uri = "http://www.lyokato.net/"
51
+ contributor = @person.to_contributor
52
+ contributor.should be_instance_of(Atom::Contributor)
53
+ contributor.name.should == "Lyo Kato"
54
+ contributor_xml = contributor.to_s
55
+ contributor_xml.should =~ /<contributor(?: xmlns='http:\/\/www\.w3\.org\/2005\/Atom')>/
56
+ contributor_xml.should =~ /<name(?: xmlns='http:\/\/www\.w3\.org\/2005\/Atom')?>Lyo Kato<\/name>/
57
+ contributor_xml.should =~ /<email(?: xmlns='http:\/\/www\.w3\.org\/2005\/Atom')?>lyo\.kato\@gmail\.com<\/email>/
58
+ end
59
+
60
+ end
61
+
@@ -0,0 +1,60 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+
3
+ <feed xmlns="http://www.w3.org/2005/Atom"
4
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
5
+ xmlns:foaf="http://xmlns.com/foaf/0.1">
6
+
7
+ <title type="text">dive into mark</title>
8
+ <id>tag:example.org,2003:3</id>
9
+
10
+ <updated>2005-07-31T12:29:29Z</updated>
11
+
12
+ <link rel="alternate" type="text/html"
13
+ hreflang="en" href="http://example.org/"/>
14
+ <link rel="self" type="application/atom+xml"
15
+ href="http://example.org/feed.atom"/>
16
+
17
+ <rights>Copyright (c) 2003, Mark Pilgrim</rights>
18
+ <generator uri="http://www.example.com/" version="1.0">
19
+ Example Toolkit
20
+ </generator>
21
+
22
+ <entry>
23
+ <title>Atom draft-07 snapshot</title>
24
+ <id>tag:example.org,2003:3.2397</id>
25
+
26
+ <updated>2005-07-31T12:29:29Z</updated>
27
+ <published>2003-12-13T08:29:29-04:00</published>
28
+
29
+ <link rel="alternate" type="text/html"
30
+ href="http://example.org/2005/04/02/atom"/>
31
+
32
+ <link rel="enclosure" type="audio/mpeg" length="1337"
33
+ href="http://example.org/audio/ph34r_my_podcast.mp3"/>
34
+
35
+ <author>
36
+ <name>Mark Pilgrim</name>
37
+ <uri>http://example.org/</uri>
38
+ <email>f8dy@example.com</email>
39
+
40
+ <foaf:homepage rdf:resource="http://www.example.org/blog" />
41
+ <foaf:img rdf:resource="http://www.example.org/mypic.png" />
42
+ </author>
43
+
44
+ <contributor>
45
+ <name>Sam Ruby</name>
46
+ </contributor>
47
+ <contributor>
48
+ <name>Joe Gregorio</name>
49
+ </contributor>
50
+
51
+ <content type="xhtml" xml:lang="en" xml:base="http://diveintomark.org/">
52
+ <div xmlns="http://www.w3.org/1999/xhtml">
53
+ <p><i>[Update: The Atom draft is finished.]</i></p>
54
+ </div>
55
+ </content>
56
+
57
+ </entry>
58
+
59
+ </feed>
60
+
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --colour