rss 0.2.9 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/NEWS.md +38 -0
- data/README.md +11 -11
- data/lib/rss/itunes.rb +10 -1
- data/lib/rss/maker/itunes.rb +2 -0
- data/lib/rss/rss.rb +43 -15
- data/lib/rss/utils.rb +0 -18
- data/lib/rss/version.rb +1 -1
- data/lib/rss/xml-stylesheet.rb +3 -4
- data/lib/rss/xml.rb +3 -2
- data/lib/rss.rb +11 -11
- metadata +7 -101
- data/Gemfile +0 -6
- data/Rakefile +0 -15
- data/rss.gemspec +0 -30
- data/test/dot.png +0 -0
- data/test/rss-assertions.rb +0 -2116
- data/test/rss-testcase.rb +0 -479
- data/test/run-test.rb +0 -15
- data/test/test_1.0.rb +0 -308
- data/test/test_2.0.rb +0 -412
- data/test/test_accessor.rb +0 -104
- data/test/test_atom.rb +0 -684
- data/test/test_content.rb +0 -105
- data/test/test_dublincore.rb +0 -270
- data/test/test_image.rb +0 -215
- data/test/test_inherit.rb +0 -41
- data/test/test_itunes.rb +0 -360
- data/test/test_maker_0.9.rb +0 -477
- data/test/test_maker_1.0.rb +0 -519
- data/test/test_maker_2.0.rb +0 -758
- data/test/test_maker_atom_entry.rb +0 -394
- data/test/test_maker_atom_feed.rb +0 -455
- data/test/test_maker_content.rb +0 -48
- data/test/test_maker_dc.rb +0 -150
- data/test/test_maker_image.rb +0 -63
- data/test/test_maker_itunes.rb +0 -488
- data/test/test_maker_slash.rb +0 -38
- data/test/test_maker_sy.rb +0 -45
- data/test/test_maker_taxo.rb +0 -82
- data/test/test_maker_trackback.rb +0 -42
- data/test/test_maker_xml-stylesheet.rb +0 -84
- data/test/test_parser.rb +0 -122
- data/test/test_parser_1.0.rb +0 -529
- data/test/test_parser_2.0.rb +0 -123
- data/test/test_parser_atom_entry.rb +0 -164
- data/test/test_parser_atom_feed.rb +0 -277
- data/test/test_setup_maker_0.9.rb +0 -247
- data/test/test_setup_maker_1.0.rb +0 -551
- data/test/test_setup_maker_2.0.rb +0 -309
- data/test/test_setup_maker_atom_entry.rb +0 -410
- data/test/test_setup_maker_atom_feed.rb +0 -446
- data/test/test_setup_maker_itunes.rb +0 -146
- data/test/test_setup_maker_slash.rb +0 -39
- data/test/test_slash.rb +0 -65
- data/test/test_syndication.rb +0 -126
- data/test/test_taxonomy.rb +0 -173
- data/test/test_to_s.rb +0 -701
- data/test/test_trackback.rb +0 -136
- data/test/test_xml-stylesheet.rb +0 -109
data/test/test_1.0.rb
DELETED
@@ -1,308 +0,0 @@
|
|
1
|
-
# frozen_string_literal: false
|
2
|
-
require "rexml/document"
|
3
|
-
|
4
|
-
require_relative "rss-testcase"
|
5
|
-
|
6
|
-
require "rss/1.0"
|
7
|
-
|
8
|
-
module RSS
|
9
|
-
class TestRSS10Core < TestCase
|
10
|
-
|
11
|
-
def setup
|
12
|
-
@rdf_prefix = "rdf"
|
13
|
-
@rdf_uri = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
14
|
-
@uri = "http://purl.org/rss/1.0/"
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_RDF
|
18
|
-
version = "1.0"
|
19
|
-
encoding = "UTF-8"
|
20
|
-
standalone = false
|
21
|
-
|
22
|
-
rdf = RDF.new(version, encoding, standalone)
|
23
|
-
setup_rss10(rdf)
|
24
|
-
doc = REXML::Document.new(rdf.to_s)
|
25
|
-
|
26
|
-
xmldecl = doc.xml_decl
|
27
|
-
|
28
|
-
assert_equal(version, xmldecl.version)
|
29
|
-
assert_equal(encoding, xmldecl.encoding.to_s)
|
30
|
-
assert_equal(standalone, !xmldecl.standalone.nil?)
|
31
|
-
|
32
|
-
assert_equal(@rdf_uri, doc.root.namespace)
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_not_displayed_xml_stylesheets
|
36
|
-
rdf = RDF.new()
|
37
|
-
plain_rdf = rdf.to_s
|
38
|
-
3.times do
|
39
|
-
rdf.xml_stylesheets.push(XMLStyleSheet.new)
|
40
|
-
assert_equal(plain_rdf, rdf.to_s)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_xml_stylesheets
|
45
|
-
[
|
46
|
-
[{:href => "a.xsl", :type => "text/xsl"}],
|
47
|
-
[
|
48
|
-
{:href => "a.xsl", :type => "text/xsl"},
|
49
|
-
{:href => "a.css", :type => "text/css"},
|
50
|
-
],
|
51
|
-
].each do |attrs_ary|
|
52
|
-
assert_xml_stylesheet_pis(attrs_ary)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_channel
|
57
|
-
about = "http://hoge.com"
|
58
|
-
resource = "http://hoge.com/hoge.png"
|
59
|
-
|
60
|
-
item_title = "item title"
|
61
|
-
item_link = "http://hoge.com/item"
|
62
|
-
|
63
|
-
image = RDF::Channel::Image.new(resource)
|
64
|
-
items = RDF::Channel::Items.new
|
65
|
-
items.Seq.lis << items.class::Seq::Li.new(item_link)
|
66
|
-
textinput = RDF::Channel::Textinput.new(resource)
|
67
|
-
|
68
|
-
rss_item = RDF::Item.new
|
69
|
-
rss_item.title = item_title
|
70
|
-
rss_item.link = item_link
|
71
|
-
rss_item.about = item_link
|
72
|
-
|
73
|
-
h = {
|
74
|
-
'title' => "fugafuga",
|
75
|
-
'link' => "http://hoge.com",
|
76
|
-
'description' => "fugafugafugafuga",
|
77
|
-
'image' => image,
|
78
|
-
'items' => items,
|
79
|
-
'textinput' => textinput,
|
80
|
-
}
|
81
|
-
|
82
|
-
channel = RDF::Channel.new(about)
|
83
|
-
%w(title link description image items textinput).each do |x|
|
84
|
-
channel.__send__("#{x}=", h[x])
|
85
|
-
end
|
86
|
-
|
87
|
-
doc = REXML::Document.new(make_RDF(<<-EOR))
|
88
|
-
#{channel}
|
89
|
-
<items>
|
90
|
-
#{rss_item}
|
91
|
-
</items>
|
92
|
-
EOR
|
93
|
-
c = doc.root.elements[1]
|
94
|
-
|
95
|
-
assert_equal(about, c.attributes["about"])
|
96
|
-
%w(title link description image textinput).each do |x|
|
97
|
-
elem = c.elements[x]
|
98
|
-
assert_equal(x, elem.name)
|
99
|
-
assert_equal(@uri, elem.namespace)
|
100
|
-
if x == "image" or x == "textinput"
|
101
|
-
excepted = resource
|
102
|
-
res = elem.attributes.get_attribute("resource")
|
103
|
-
assert_equal(@rdf_uri, res.namespace)
|
104
|
-
value = res.value
|
105
|
-
else
|
106
|
-
excepted = h[x]
|
107
|
-
value = elem.text
|
108
|
-
end
|
109
|
-
assert_equal(excepted, value)
|
110
|
-
end
|
111
|
-
assert_equal(@uri, c.elements["items"].namespace)
|
112
|
-
assert_equal("items", c.elements["items"].name)
|
113
|
-
end
|
114
|
-
|
115
|
-
def test_channel_image
|
116
|
-
resource = "http://hoge.com/hoge.png"
|
117
|
-
image = RDF::Channel::Image.new(resource)
|
118
|
-
|
119
|
-
doc = REXML::Document.new(make_RDF(image.to_s))
|
120
|
-
i = doc.root.elements[1]
|
121
|
-
|
122
|
-
assert_equal("image", i.name)
|
123
|
-
assert_equal(@uri, i.namespace)
|
124
|
-
|
125
|
-
res = i.attributes.get_attribute("resource")
|
126
|
-
|
127
|
-
assert_equal(@rdf_uri, res.namespace)
|
128
|
-
assert_equal(resource, res.value)
|
129
|
-
end
|
130
|
-
|
131
|
-
def test_channel_textinput
|
132
|
-
resource = "http://hoge.com/hoge.png"
|
133
|
-
textinput = RDF::Channel::Textinput.new(resource)
|
134
|
-
|
135
|
-
doc = REXML::Document.new(make_RDF(textinput.to_s))
|
136
|
-
t = doc.root.elements[1]
|
137
|
-
|
138
|
-
assert_equal("textinput", t.name)
|
139
|
-
assert_equal(@uri, t.namespace)
|
140
|
-
|
141
|
-
res = t.attributes.get_attribute("resource")
|
142
|
-
|
143
|
-
assert_equal(@rdf_uri, res.namespace)
|
144
|
-
assert_equal(resource, res.value)
|
145
|
-
end
|
146
|
-
|
147
|
-
def test_channel_items
|
148
|
-
item_link = "http://example.com/item"
|
149
|
-
|
150
|
-
items = RDF::Channel::Items.new
|
151
|
-
li = items.Seq.class::Li.new(item_link)
|
152
|
-
items.Seq.lis << li
|
153
|
-
|
154
|
-
doc = REXML::Document.new(make_RDF(items.to_s))
|
155
|
-
i = doc.root.elements[1]
|
156
|
-
|
157
|
-
assert_equal("items", i.name)
|
158
|
-
assert_equal(@uri, i.namespace)
|
159
|
-
|
160
|
-
assert_equal(1, i.elements.size)
|
161
|
-
seq = i.elements[1]
|
162
|
-
assert_equal("Seq", seq.name)
|
163
|
-
assert_equal(@rdf_uri, seq.namespace)
|
164
|
-
|
165
|
-
assert_equal(1, seq.elements.size)
|
166
|
-
l = seq.elements[1]
|
167
|
-
assert_equal("li", l.name)
|
168
|
-
assert_equal(@rdf_uri, l.namespace)
|
169
|
-
assert_equal(item_link, l.attributes["resource"])
|
170
|
-
end
|
171
|
-
|
172
|
-
def test_seq
|
173
|
-
item_link = "http://example.com/item"
|
174
|
-
seq = RDF::Seq.new
|
175
|
-
li = seq.class::Li.new(item_link)
|
176
|
-
seq.lis << li
|
177
|
-
|
178
|
-
doc = REXML::Document.new(make_RDF(seq.to_s))
|
179
|
-
s = doc.root.elements[1]
|
180
|
-
|
181
|
-
assert_equal("Seq", s.name)
|
182
|
-
assert_equal(@rdf_uri, s.namespace)
|
183
|
-
|
184
|
-
assert_equal(1, s.elements.size)
|
185
|
-
l = s.elements[1]
|
186
|
-
assert_equal("li", l.name)
|
187
|
-
assert_equal(@rdf_uri, l.namespace)
|
188
|
-
assert_equal(item_link, l.attributes["resource"])
|
189
|
-
end
|
190
|
-
|
191
|
-
def test_li
|
192
|
-
resource = "http://hoge.com/"
|
193
|
-
li = RDF::Li.new(resource)
|
194
|
-
|
195
|
-
doc = REXML::Document.new(make_RDF(li.to_s))
|
196
|
-
l = doc.root.elements[1]
|
197
|
-
|
198
|
-
assert_equal("li", l.name)
|
199
|
-
assert_equal(@rdf_uri, l.namespace(l.prefix))
|
200
|
-
|
201
|
-
res = l.attributes.get_attribute("resource")
|
202
|
-
|
203
|
-
assert_equal('', res.instance_eval("@prefix"))
|
204
|
-
assert_equal(resource, res.value)
|
205
|
-
end
|
206
|
-
|
207
|
-
def test_image
|
208
|
-
about = "http://hoge.com"
|
209
|
-
h = {
|
210
|
-
'title' => "fugafuga",
|
211
|
-
'url' => "http://hoge.com/hoge",
|
212
|
-
'link' => "http://hoge.com/fuga",
|
213
|
-
}
|
214
|
-
|
215
|
-
image = RDF::Image.new(about)
|
216
|
-
%w(title url link).each do |x|
|
217
|
-
image.__send__("#{x}=", h[x])
|
218
|
-
end
|
219
|
-
|
220
|
-
doc = REXML::Document.new(make_RDF(image.to_s))
|
221
|
-
i = doc.root.elements[1]
|
222
|
-
|
223
|
-
assert_equal(about, i.attributes["about"])
|
224
|
-
%w(title url link).each do |x|
|
225
|
-
elem = i.elements[x]
|
226
|
-
assert_equal(x, elem.name)
|
227
|
-
assert_equal(@uri, elem.namespace)
|
228
|
-
assert_equal(h[x], elem.text)
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
def test_item
|
233
|
-
about = "http://hoge.com"
|
234
|
-
h = {
|
235
|
-
'title' => "fugafuga",
|
236
|
-
'link' => "http://hoge.com/fuga",
|
237
|
-
'description' => "hogehogehoge",
|
238
|
-
}
|
239
|
-
|
240
|
-
item = RDF::Item.new(about)
|
241
|
-
%w(title link description).each do |x|
|
242
|
-
item.__send__("#{x}=", h[x])
|
243
|
-
end
|
244
|
-
|
245
|
-
doc = REXML::Document.new(make_RDF(item.to_s))
|
246
|
-
i = doc.root.elements[1]
|
247
|
-
|
248
|
-
assert_equal(about, i.attributes["about"])
|
249
|
-
%w(title link description).each do |x|
|
250
|
-
elem = i.elements[x]
|
251
|
-
assert_equal(x, elem.name)
|
252
|
-
assert_equal(@uri, elem.namespace)
|
253
|
-
assert_equal(h[x], elem.text)
|
254
|
-
end
|
255
|
-
end
|
256
|
-
|
257
|
-
def test_textinput
|
258
|
-
about = "http://hoge.com"
|
259
|
-
h = {
|
260
|
-
'title' => "fugafuga",
|
261
|
-
'link' => "http://hoge.com/fuga",
|
262
|
-
'name' => "foo",
|
263
|
-
'description' => "hogehogehoge",
|
264
|
-
}
|
265
|
-
|
266
|
-
textinput = RDF::Textinput.new(about)
|
267
|
-
%w(title link name description).each do |x|
|
268
|
-
textinput.__send__("#{x}=", h[x])
|
269
|
-
end
|
270
|
-
|
271
|
-
doc = REXML::Document.new(make_RDF(textinput.to_s))
|
272
|
-
t = doc.root.elements[1]
|
273
|
-
|
274
|
-
assert_equal(about, t.attributes["about"])
|
275
|
-
%w(title link name description).each do |x|
|
276
|
-
elem = t.elements[x]
|
277
|
-
assert_equal(x, elem.name)
|
278
|
-
assert_equal(@uri, elem.namespace)
|
279
|
-
assert_equal(h[x], elem.text)
|
280
|
-
end
|
281
|
-
end
|
282
|
-
|
283
|
-
def test_to_xml
|
284
|
-
rss = RSS::Parser.parse(make_sample_RDF)
|
285
|
-
assert_equal(rss.to_s, rss.to_xml)
|
286
|
-
assert_equal(rss.to_s, rss.to_xml("1.0"))
|
287
|
-
rss09 = rss.to_xml("0.91") do |maker|
|
288
|
-
maker.channel.language = "en-us"
|
289
|
-
end
|
290
|
-
rss09 = RSS::Parser.parse(rss09)
|
291
|
-
assert_equal("0.91", rss09.rss_version)
|
292
|
-
assert_equal(["rss", "0.91", nil], rss09.feed_info)
|
293
|
-
rss20 = RSS::Parser.parse(rss.to_xml("2.0"))
|
294
|
-
assert_equal("2.0", rss20.rss_version)
|
295
|
-
assert_equal(["rss", "2.0", nil], rss20.feed_info)
|
296
|
-
|
297
|
-
atom_xml = rss.to_xml("atom") do |maker|
|
298
|
-
maker.channel.author = "Alice"
|
299
|
-
maker.channel.updated ||= Time.now
|
300
|
-
maker.items.each do |item|
|
301
|
-
item.updated ||= Time.now
|
302
|
-
end
|
303
|
-
end
|
304
|
-
atom = RSS::Parser.parse(atom_xml)
|
305
|
-
assert_equal(["atom", "1.0", "feed"], atom.feed_info)
|
306
|
-
end
|
307
|
-
end
|
308
|
-
end
|
data/test/test_2.0.rb
DELETED
@@ -1,412 +0,0 @@
|
|
1
|
-
# frozen_string_literal: false
|
2
|
-
require "rexml/document"
|
3
|
-
|
4
|
-
require_relative "rss-testcase"
|
5
|
-
|
6
|
-
module RSS
|
7
|
-
class TestRSS20Core < TestCase
|
8
|
-
|
9
|
-
def setup
|
10
|
-
@rss_version = "2.0"
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_Rss
|
14
|
-
version = "1.0"
|
15
|
-
encoding = "UTF-8"
|
16
|
-
standalone = false
|
17
|
-
|
18
|
-
rss = Rss.new(@rss_version, version, encoding, standalone)
|
19
|
-
setup_rss20(rss)
|
20
|
-
|
21
|
-
doc = REXML::Document.new(rss.to_s(false))
|
22
|
-
|
23
|
-
xmldecl = doc.xml_decl
|
24
|
-
|
25
|
-
assert_equal(version, xmldecl.version)
|
26
|
-
assert_equal(encoding, xmldecl.encoding.to_s)
|
27
|
-
assert_equal(standalone, !xmldecl.standalone.nil?)
|
28
|
-
|
29
|
-
assert_equal("", doc.root.namespace)
|
30
|
-
assert_equal(@rss_version, doc.root.attributes["version"])
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_not_displayed_xml_stylesheets
|
34
|
-
rss = Rss.new(@rss_version)
|
35
|
-
plain_rss = rss.to_s
|
36
|
-
3.times do
|
37
|
-
rss.xml_stylesheets.push(XMLStyleSheet.new)
|
38
|
-
assert_equal(plain_rss, rss.to_s)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_xml_stylesheets
|
43
|
-
[
|
44
|
-
[{:href => "a.xsl", :type => "text/xsl"}],
|
45
|
-
[
|
46
|
-
{:href => "a.xsl", :type => "text/xsl"},
|
47
|
-
{:href => "a.css", :type => "text/css"},
|
48
|
-
],
|
49
|
-
].each do |attrs_ary|
|
50
|
-
rss = Rss.new(@rss_version)
|
51
|
-
setup_rss20(rss)
|
52
|
-
assert_xml_stylesheet_pis(attrs_ary, rss)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_channel
|
57
|
-
h = {
|
58
|
-
'title' => "fugafuga",
|
59
|
-
'link' => "http://hoge.com",
|
60
|
-
'description' => "fugafugafugafuga",
|
61
|
-
|
62
|
-
'language' => "en-us",
|
63
|
-
'copyright' => "Copyright 2002, Spartanburg Herald-Journal",
|
64
|
-
'managingEditor' => "geo@herald.com (George Matesky)",
|
65
|
-
'webMaster' => "betty@herald.com (Betty Guernsey)",
|
66
|
-
'pubDate' => Time.parse("Sat, 07 Sep 2002 00:00:01 GMT"),
|
67
|
-
'lastBuildDate' => Time.parse("Sat, 07 Sep 2002 09:42:31 GMT"),
|
68
|
-
'generator' => "MightyInHouse Content System v2.3",
|
69
|
-
'docs' => "http://blogs.law.harvard.edu/tech/rss",
|
70
|
-
'ttl' => "60",
|
71
|
-
'rating' => '(PICS-1.1 "http://www.rsac.org/ratingsv01.html" l gen true comment "RSACi North America Server" for "http://www.rsac.org" on "1996.04.16T08:15-0500" r (n 0 s 0 v 0 l 0))',
|
72
|
-
}
|
73
|
-
categories = [
|
74
|
-
{
|
75
|
-
:content => "Newspapers",
|
76
|
-
},
|
77
|
-
{
|
78
|
-
:domain => "Syndic8",
|
79
|
-
:content => "1765",
|
80
|
-
}
|
81
|
-
]
|
82
|
-
|
83
|
-
channel = Rss::Channel.new
|
84
|
-
|
85
|
-
elems = %w(title link description language copyright
|
86
|
-
managingEditor webMaster pubDate lastBuildDate
|
87
|
-
generator docs ttl rating)
|
88
|
-
elems.each do |x|
|
89
|
-
value = h[x]
|
90
|
-
value = value.rfc822 if %w(pubDate lastBuildDate).include?(x)
|
91
|
-
channel.__send__("#{x}=", value)
|
92
|
-
end
|
93
|
-
categories.each do |cat|
|
94
|
-
channel.categories << Rss::Channel::Category.new(cat[:domain],
|
95
|
-
cat[:content])
|
96
|
-
end
|
97
|
-
|
98
|
-
doc = REXML::Document.new(make_rss20(channel.to_s))
|
99
|
-
c = doc.root.elements[1]
|
100
|
-
|
101
|
-
elems.each do |x|
|
102
|
-
elem = c.elements[x]
|
103
|
-
assert_equal(x, elem.name)
|
104
|
-
assert_equal("", elem.namespace)
|
105
|
-
expected = h[x]
|
106
|
-
case x
|
107
|
-
when "pubDate", "lastBuildDate"
|
108
|
-
assert_equal(expected, Time.parse(elem.text))
|
109
|
-
when "ttl"
|
110
|
-
expected = channel.__send__(x)
|
111
|
-
assert_equal(expected, elem.text.to_i)
|
112
|
-
else
|
113
|
-
assert_equal(expected, elem.text)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
categories.each_with_index do |cat, i|
|
117
|
-
cat = cat.dup
|
118
|
-
cat[:domain] ||= nil
|
119
|
-
category = c.elements["category[#{i+1}]"]
|
120
|
-
actual = {
|
121
|
-
:domain => category.attributes["domain"],
|
122
|
-
:content => category.text,
|
123
|
-
}
|
124
|
-
assert_equal(cat, actual)
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
def test_channel_cloud
|
129
|
-
cloud_params = {
|
130
|
-
:domain => "rpc.sys.com",
|
131
|
-
:port => "80",
|
132
|
-
:path => "/RPC2",
|
133
|
-
:registerProcedure => "myCloud.rssPleaseNotify",
|
134
|
-
:protocol => "xml-rpc",
|
135
|
-
}
|
136
|
-
cloud = Rss::Channel::Cloud.new(cloud_params[:domain],
|
137
|
-
cloud_params[:port],
|
138
|
-
cloud_params[:path],
|
139
|
-
cloud_params[:registerProcedure],
|
140
|
-
cloud_params[:protocol])
|
141
|
-
cloud_params[:port] = cloud.port
|
142
|
-
|
143
|
-
doc = REXML::Document.new(cloud.to_s)
|
144
|
-
cloud_elem = doc.root
|
145
|
-
|
146
|
-
actual = {}
|
147
|
-
cloud_elem.attributes.each do |name, value|
|
148
|
-
value = value.to_i if name == "port"
|
149
|
-
actual[name.intern] = value
|
150
|
-
end
|
151
|
-
assert_equal(cloud_params, actual)
|
152
|
-
end
|
153
|
-
|
154
|
-
def test_channel_image
|
155
|
-
image_params = {
|
156
|
-
:url => "http://hoge.com/hoge.png",
|
157
|
-
:title => "fugafuga",
|
158
|
-
:link => "http://hoge.com",
|
159
|
-
:width => "144",
|
160
|
-
:height => "400",
|
161
|
-
:description => "an image",
|
162
|
-
}
|
163
|
-
image = Rss::Channel::Image.new(image_params[:url],
|
164
|
-
image_params[:title],
|
165
|
-
image_params[:link],
|
166
|
-
image_params[:width],
|
167
|
-
image_params[:height],
|
168
|
-
image_params[:description])
|
169
|
-
|
170
|
-
doc = REXML::Document.new(image.to_s)
|
171
|
-
image_elem = doc.root
|
172
|
-
|
173
|
-
image_params.each do |name, value|
|
174
|
-
value = image.__send__(name)
|
175
|
-
actual = image_elem.elements[name.to_s].text
|
176
|
-
actual = actual.to_i if [:width, :height].include?(name)
|
177
|
-
assert_equal(value, actual)
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
def test_channel_textInput
|
182
|
-
textInput_params = {
|
183
|
-
:title => "fugafuga",
|
184
|
-
:description => "text hoge fuga",
|
185
|
-
:name => "hoge",
|
186
|
-
:link => "http://hoge.com",
|
187
|
-
}
|
188
|
-
textInput = Rss::Channel::TextInput.new(textInput_params[:title],
|
189
|
-
textInput_params[:description],
|
190
|
-
textInput_params[:name],
|
191
|
-
textInput_params[:link])
|
192
|
-
|
193
|
-
doc = REXML::Document.new(textInput.to_s)
|
194
|
-
input_elem = doc.root
|
195
|
-
|
196
|
-
textInput_params.each do |name, value|
|
197
|
-
actual = input_elem.elements[name.to_s].text
|
198
|
-
assert_equal(value, actual)
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
def test_channel_skip_days
|
203
|
-
skipDays_values = [
|
204
|
-
"Sunday",
|
205
|
-
"Monday",
|
206
|
-
]
|
207
|
-
skipDays = Rss::Channel::SkipDays.new
|
208
|
-
skipDays_values.each do |value|
|
209
|
-
skipDays.days << Rss::Channel::SkipDays::Day.new(value)
|
210
|
-
end
|
211
|
-
|
212
|
-
doc = REXML::Document.new(skipDays.to_s)
|
213
|
-
days_elem = doc.root
|
214
|
-
|
215
|
-
skipDays_values.each_with_index do |value, i|
|
216
|
-
assert_equal(value, days_elem.elements[i + 1].text)
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
def test_channel_skip_hours
|
221
|
-
skipHours_values = [
|
222
|
-
"0",
|
223
|
-
"13",
|
224
|
-
]
|
225
|
-
skipHours = Rss::Channel::SkipHours.new
|
226
|
-
skipHours_values.each do |value|
|
227
|
-
skipHours.hours << Rss::Channel::SkipHours::Hour.new(value)
|
228
|
-
end
|
229
|
-
|
230
|
-
doc = REXML::Document.new(skipHours.to_s)
|
231
|
-
hours_elem = doc.root
|
232
|
-
|
233
|
-
skipHours_values.each_with_index do |value, i|
|
234
|
-
expected = skipHours.hours[i].content
|
235
|
-
assert_equal(expected, hours_elem.elements[i + 1].text.to_i)
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
|
-
def test_item
|
240
|
-
h = {
|
241
|
-
'title' => "fugafuga",
|
242
|
-
'link' => "http://hoge.com/",
|
243
|
-
'description' => "text hoge fuga",
|
244
|
-
'author' => "oprah@oxygen.net",
|
245
|
-
'comments' => "http://www.myblog.org/cgi-local/mt/mt-comments.cgi?entry_id=290",
|
246
|
-
'pubDate' => Time.parse("Sat, 07 Sep 2002 00:00:01 GMT"),
|
247
|
-
}
|
248
|
-
categories = [
|
249
|
-
{
|
250
|
-
:content => "Newspapers",
|
251
|
-
},
|
252
|
-
{
|
253
|
-
:domain => "Syndic8",
|
254
|
-
:content => "1765",
|
255
|
-
}
|
256
|
-
]
|
257
|
-
|
258
|
-
channel = Rss::Channel.new
|
259
|
-
channel.title = "title"
|
260
|
-
channel.link = "http://example.com/"
|
261
|
-
channel.description = "description"
|
262
|
-
|
263
|
-
item = Rss::Channel::Item.new
|
264
|
-
channel.items << item
|
265
|
-
|
266
|
-
elems = %w(title link description author comments pubDate)
|
267
|
-
elems.each do |x|
|
268
|
-
value = h[x]
|
269
|
-
value = value.rfc822 if x == "pubDate"
|
270
|
-
item.__send__("#{x}=", value)
|
271
|
-
end
|
272
|
-
categories.each do |cat|
|
273
|
-
item.categories << Rss::Channel::Category.new(cat[:domain],
|
274
|
-
cat[:content])
|
275
|
-
end
|
276
|
-
|
277
|
-
doc = REXML::Document.new(channel.to_s)
|
278
|
-
channel_elem = doc.root
|
279
|
-
|
280
|
-
item_elem = channel_elem.elements["item[1]"]
|
281
|
-
elems.each do |x|
|
282
|
-
elem = item_elem.elements[x]
|
283
|
-
assert_equal(x, elem.name)
|
284
|
-
assert_equal("", elem.namespace)
|
285
|
-
expected = h[x]
|
286
|
-
case x
|
287
|
-
when "pubDate"
|
288
|
-
assert_equal(expected, Time.parse(elem.text))
|
289
|
-
else
|
290
|
-
assert_equal(expected, elem.text)
|
291
|
-
end
|
292
|
-
end
|
293
|
-
categories.each_with_index do |cat, i|
|
294
|
-
cat = cat.dup
|
295
|
-
cat[:domain] ||= nil
|
296
|
-
category = item_elem.elements["category[#{i+1}]"]
|
297
|
-
actual = {
|
298
|
-
:domain => category.attributes["domain"],
|
299
|
-
:content => category.text,
|
300
|
-
}
|
301
|
-
assert_equal(cat, actual)
|
302
|
-
end
|
303
|
-
end
|
304
|
-
|
305
|
-
def test_item_enclosure
|
306
|
-
enclosure_params = {
|
307
|
-
:url => "http://www.scripting.com/mp3s/weatherReportSuite.mp3",
|
308
|
-
:length => "12216320",
|
309
|
-
:type => "audio/mpeg",
|
310
|
-
}
|
311
|
-
|
312
|
-
enclosure = Rss::Channel::Item::Enclosure.new(enclosure_params[:url],
|
313
|
-
enclosure_params[:length],
|
314
|
-
enclosure_params[:type])
|
315
|
-
enclosure_params[:length] = enclosure.length
|
316
|
-
|
317
|
-
doc = REXML::Document.new(enclosure.to_s)
|
318
|
-
enclosure_elem = doc.root
|
319
|
-
|
320
|
-
actual = {}
|
321
|
-
enclosure_elem.attributes.each do |name, value|
|
322
|
-
value = value.to_i if name == "length"
|
323
|
-
actual[name.intern] = value
|
324
|
-
end
|
325
|
-
assert_equal(enclosure_params, actual)
|
326
|
-
end
|
327
|
-
|
328
|
-
def test_item_guid
|
329
|
-
test_params = [
|
330
|
-
{
|
331
|
-
:content => "http://some.server.com/weblogItem3207",
|
332
|
-
},
|
333
|
-
{
|
334
|
-
:isPermaLink => "true",
|
335
|
-
:content => "http://inessential.com/2002/09/01.php#a2",
|
336
|
-
},
|
337
|
-
]
|
338
|
-
|
339
|
-
test_params.each do |guid_params|
|
340
|
-
guid = Rss::Channel::Item::Guid.new(guid_params[:isPermaLink],
|
341
|
-
guid_params[:content])
|
342
|
-
if guid_params.has_key?(:isPermaLink)
|
343
|
-
guid_params[:isPermaLink] = guid.isPermaLink
|
344
|
-
end
|
345
|
-
if guid.isPermaLink.nil?
|
346
|
-
assert_equal(true, guid.PermaLink?)
|
347
|
-
else
|
348
|
-
assert_equal(guid.isPermaLink, guid.PermaLink?)
|
349
|
-
end
|
350
|
-
|
351
|
-
doc = REXML::Document.new(guid.to_s)
|
352
|
-
guid_elem = doc.root
|
353
|
-
|
354
|
-
actual = {}
|
355
|
-
actual[:content] = guid_elem.text if guid_elem.text
|
356
|
-
guid_elem.attributes.each do |name, value|
|
357
|
-
value = value == "true" if name == "isPermaLink"
|
358
|
-
actual[name.intern] = value
|
359
|
-
end
|
360
|
-
assert_equal(guid_params, actual)
|
361
|
-
end
|
362
|
-
end
|
363
|
-
|
364
|
-
def test_item_source
|
365
|
-
source_params = {
|
366
|
-
:url => "http://www.tomalak.org/links2.xml",
|
367
|
-
:content => "Tomalak's Realm",
|
368
|
-
}
|
369
|
-
|
370
|
-
source = Rss::Channel::Item::Source.new(source_params[:url],
|
371
|
-
source_params[:content])
|
372
|
-
|
373
|
-
doc = REXML::Document.new(source.to_s)
|
374
|
-
source_elem = doc.root
|
375
|
-
|
376
|
-
actual = {}
|
377
|
-
actual[:content] = source_elem.text
|
378
|
-
source_elem.attributes.each do |name, value|
|
379
|
-
actual[name.intern] = value
|
380
|
-
end
|
381
|
-
assert_equal(source_params, actual)
|
382
|
-
end
|
383
|
-
|
384
|
-
def test_to_xml
|
385
|
-
rss = RSS::Parser.parse(make_sample_rss20)
|
386
|
-
assert_equal(rss.to_s, rss.to_xml)
|
387
|
-
assert_equal(rss.to_s, rss.to_xml("2.0"))
|
388
|
-
rss09_xml = rss.to_xml("0.91") do |maker|
|
389
|
-
setup_dummy_image(maker)
|
390
|
-
end
|
391
|
-
rss09 = RSS::Parser.parse(rss09_xml)
|
392
|
-
assert_equal("0.91", rss09.rss_version)
|
393
|
-
rss10 = rss.to_xml("1.0") do |maker|
|
394
|
-
maker.channel.about = "http://www.example.com/index.rdf"
|
395
|
-
end
|
396
|
-
rss10 = RSS::Parser.parse(rss10)
|
397
|
-
assert_equal("1.0", rss10.rss_version)
|
398
|
-
|
399
|
-
atom_xml = rss.to_xml("atom1.0") do |maker|
|
400
|
-
maker.channel.id = "http://www.example.com/atom.xml"
|
401
|
-
maker.channel.author = "Alice"
|
402
|
-
maker.channel.updated = Time.now
|
403
|
-
maker.items.each do |item|
|
404
|
-
item.author = "Bob"
|
405
|
-
item.updated = Time.now
|
406
|
-
end
|
407
|
-
end
|
408
|
-
atom = RSS::Parser.parse(atom_xml)
|
409
|
-
assert_equal(["atom", "1.0", "feed"], atom.feed_info)
|
410
|
-
end
|
411
|
-
end
|
412
|
-
end
|