rss-nokogiri 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/.gemtest +0 -0
  2. data/.gitignore +19 -0
  3. data/.gitmodules +3 -0
  4. data/BSDL +22 -0
  5. data/COPYING +56 -0
  6. data/COPYING.ja +51 -0
  7. data/Gemfile +4 -0
  8. data/LEGAL +8 -0
  9. data/README.markdown +51 -0
  10. data/Rakefile +12 -0
  11. data/lib/rss/nokogiri.rb +92 -0
  12. data/rss-nokogiri.gemspec +24 -0
  13. data/test/regression/dot.png +0 -0
  14. data/test/regression/rss-assertions.rb +2090 -0
  15. data/test/regression/rss-testcase.rb +478 -0
  16. data/test/regression/test_1.0.rb +295 -0
  17. data/test/regression/test_2.0.rb +409 -0
  18. data/test/regression/test_accessor.rb +103 -0
  19. data/test/regression/test_atom.rb +681 -0
  20. data/test/regression/test_content.rb +104 -0
  21. data/test/regression/test_dublincore.rb +279 -0
  22. data/test/regression/test_image.rb +214 -0
  23. data/test/regression/test_inherit.rb +40 -0
  24. data/test/regression/test_itunes.rb +347 -0
  25. data/test/regression/test_maker_0.9.rb +474 -0
  26. data/test/regression/test_maker_1.0.rb +516 -0
  27. data/test/regression/test_maker_2.0.rb +757 -0
  28. data/test/regression/test_maker_atom_entry.rb +393 -0
  29. data/test/regression/test_maker_atom_feed.rb +454 -0
  30. data/test/regression/test_maker_content.rb +47 -0
  31. data/test/regression/test_maker_dc.rb +149 -0
  32. data/test/regression/test_maker_image.rb +62 -0
  33. data/test/regression/test_maker_itunes.rb +471 -0
  34. data/test/regression/test_maker_slash.rb +37 -0
  35. data/test/regression/test_maker_sy.rb +44 -0
  36. data/test/regression/test_maker_taxo.rb +81 -0
  37. data/test/regression/test_maker_trackback.rb +41 -0
  38. data/test/regression/test_maker_xml-stylesheet.rb +83 -0
  39. data/test/regression/test_parser.rb +62 -0
  40. data/test/regression/test_parser_1.0.rb +528 -0
  41. data/test/regression/test_parser_2.0.rb +122 -0
  42. data/test/regression/test_parser_atom_entry.rb +163 -0
  43. data/test/regression/test_parser_atom_feed.rb +276 -0
  44. data/test/regression/test_setup_maker_0.9.rb +246 -0
  45. data/test/regression/test_setup_maker_1.0.rb +550 -0
  46. data/test/regression/test_setup_maker_2.0.rb +308 -0
  47. data/test/regression/test_setup_maker_atom_entry.rb +409 -0
  48. data/test/regression/test_setup_maker_atom_feed.rb +445 -0
  49. data/test/regression/test_setup_maker_itunes.rb +144 -0
  50. data/test/regression/test_setup_maker_slash.rb +38 -0
  51. data/test/regression/test_slash.rb +64 -0
  52. data/test/regression/test_syndication.rb +125 -0
  53. data/test/regression/test_taxonomy.rb +172 -0
  54. data/test/regression/test_to_s.rb +670 -0
  55. data/test/regression/test_trackback.rb +135 -0
  56. data/test/regression/test_version.rb +9 -0
  57. data/test/regression/test_xml-stylesheet.rb +108 -0
  58. metadata +220 -0
@@ -0,0 +1,40 @@
1
+ require "rss-testcase"
2
+
3
+ require "rss/1.0"
4
+
5
+ module RSS
6
+ class TestInherit < TestCase
7
+
8
+ class InheritedImage < RSS::RDF::Image
9
+ def self.indent_size; 1; end
10
+ def self.tag_name; 'image'; end
11
+ end
12
+
13
+ def setup
14
+ @rss = make_RDF(<<-EOR)
15
+ #{make_channel}
16
+ #{make_image}
17
+ #{make_item}
18
+ #{make_textinput}
19
+ EOR
20
+ end
21
+
22
+ def test_inherit
23
+ rss = RSS::Parser.parse(@rss)
24
+ orig_image = rss.image
25
+ prefix = "[INHERIT]"
26
+ image = InheritedImage.new("#{prefix} #{orig_image.about}")
27
+ image.title = "#{prefix} #{orig_image.title}"
28
+ image.url = "#{prefix} #{orig_image.url}"
29
+ image.link = "#{prefix} #{orig_image.link}"
30
+ rss.image = image
31
+
32
+ new_rss = RSS::Parser.parse(rss.to_s)
33
+ new_image = new_rss.image
34
+ assert_equal("#{prefix} #{orig_image.about}", new_image.about)
35
+ assert_equal("#{prefix} #{orig_image.title}", new_image.title)
36
+ assert_equal("#{prefix} #{orig_image.url}", new_image.url)
37
+ assert_equal("#{prefix} #{orig_image.link}", new_image.link)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,347 @@
1
+ require "cgi"
2
+ require "rexml/document"
3
+
4
+ require "rss-testcase"
5
+
6
+ require "rss/2.0"
7
+ require "rss/itunes"
8
+
9
+ module RSS
10
+ class TestITunes < TestCase
11
+ def test_author
12
+ assert_itunes_author(%w(channel)) do |content, xmlns|
13
+ make_rss20(make_channel20(content), xmlns)
14
+ end
15
+
16
+ assert_itunes_author(%w(items last)) do |content, xmlns|
17
+ make_rss20(make_channel20(make_item20(content)), xmlns)
18
+ end
19
+ end
20
+
21
+ def test_block
22
+ assert_itunes_block(%w(items last)) do |content, xmlns|
23
+ make_rss20(make_channel20(make_item20(content)), xmlns)
24
+ end
25
+ end
26
+
27
+ def test_category
28
+ assert_itunes_category(%w(channel)) do |content, xmlns|
29
+ make_rss20(make_channel20(content), xmlns)
30
+ end
31
+ end
32
+
33
+ def test_image
34
+ assert_itunes_image(%w(channel)) do |content, xmlns|
35
+ make_rss20(make_channel20(content), xmlns)
36
+ end
37
+ end
38
+
39
+ def test_duration
40
+ assert_itunes_duration(%w(items last)) do |content, xmlns|
41
+ make_rss20(make_channel20(make_item20(content)), xmlns)
42
+ end
43
+ end
44
+
45
+ def test_explicit
46
+ assert_itunes_explicit(%w(channel)) do |content, xmlns|
47
+ make_rss20(make_channel20(content), xmlns)
48
+ end
49
+
50
+ assert_itunes_explicit(%w(items last)) do |content, xmlns|
51
+ make_rss20(make_channel20(make_item20(content)), xmlns)
52
+ end
53
+ end
54
+
55
+ def test_keywords
56
+ assert_itunes_keywords(%w(channel)) do |content, xmlns|
57
+ make_rss20(make_channel20(content), xmlns)
58
+ end
59
+
60
+ assert_itunes_keywords(%w(items last)) do |content, xmlns|
61
+ make_rss20(make_channel20(make_item20(content)), xmlns)
62
+ end
63
+ end
64
+
65
+ def test_new_feed_url
66
+ assert_itunes_new_feed_url(%w(channel)) do |content, xmlns|
67
+ make_rss20(make_channel20(content), xmlns)
68
+ end
69
+ end
70
+
71
+ def test_owner
72
+ assert_itunes_owner(%w(channel)) do |content, xmlns|
73
+ make_rss20(make_channel20(content), xmlns)
74
+ end
75
+ end
76
+
77
+ def test_subtitle
78
+ assert_itunes_subtitle(%w(channel)) do |content, xmlns|
79
+ make_rss20(make_channel20(content), xmlns)
80
+ end
81
+
82
+ assert_itunes_subtitle(%w(items last)) do |content, xmlns|
83
+ make_rss20(make_channel20(make_item20(content)), xmlns)
84
+ end
85
+ end
86
+
87
+ def test_summary
88
+ assert_itunes_summary(%w(channel)) do |content, xmlns|
89
+ make_rss20(make_channel20(content), xmlns)
90
+ end
91
+
92
+ assert_itunes_summary(%w(items last)) do |content, xmlns|
93
+ make_rss20(make_channel20(make_item20(content)), xmlns)
94
+ end
95
+ end
96
+
97
+ private
98
+ def itunes_rss20_parse(content, &maker)
99
+ xmlns = {"itunes" => "http://www.itunes.com/dtds/podcast-1.0.dtd"}
100
+ rss20_xml = maker.call(content, xmlns)
101
+ ::RSS::Parser.parse(rss20_xml)
102
+ end
103
+
104
+ def assert_itunes_author(readers, &rss20_maker)
105
+ _wrap_assertion do
106
+ author = "John Lennon"
107
+ rss20 = itunes_rss20_parse(tag("itunes:author", author), &rss20_maker)
108
+ target = chain_reader(rss20, readers)
109
+ assert_equal(author, target.itunes_author)
110
+ end
111
+ end
112
+
113
+ def _assert_itunes_block(value, boolean_value, readers, &rss20_maker)
114
+ rss20 = itunes_rss20_parse(tag("itunes:block", value), &rss20_maker)
115
+ target = chain_reader(rss20, readers)
116
+ assert_equal(value, target.itunes_block)
117
+ assert_equal(boolean_value, target.itunes_block?)
118
+ end
119
+
120
+ def assert_itunes_block(readers, &rss20_maker)
121
+ _wrap_assertion do
122
+ _assert_itunes_block("yes", true, readers, &rss20_maker)
123
+ _assert_itunes_block("Yes", true, readers, &rss20_maker)
124
+ _assert_itunes_block("no", false, readers, &rss20_maker)
125
+ _assert_itunes_block("", false, readers, &rss20_maker)
126
+ end
127
+ end
128
+
129
+ def _assert_itunes_category(categories, readers, &rss20_maker)
130
+ cats = categories.collect do |category|
131
+ if category.is_a?(Array)
132
+ category, sub_category = category
133
+ tag("itunes:category",
134
+ tag("itunes:category", nil, {"text" => sub_category}),
135
+ {"text" => category})
136
+ else
137
+ tag("itunes:category", nil, {"text" => category})
138
+ end
139
+ end.join
140
+ rss20 = itunes_rss20_parse(cats, &rss20_maker)
141
+ target = chain_reader(rss20, readers)
142
+ actual_categories = target.itunes_categories.collect do |category|
143
+ cat = category.text
144
+ if category.itunes_categories.empty?
145
+ cat
146
+ else
147
+ [cat, *category.itunes_categories.collect {|c| c.text}]
148
+ end
149
+ end
150
+ assert_equal(categories, actual_categories)
151
+ end
152
+
153
+ def assert_itunes_category(readers, &rss20_maker)
154
+ _wrap_assertion do
155
+ _assert_itunes_category(["Audio Blogs"], readers, &rss20_maker)
156
+ _assert_itunes_category([["Arts & Entertainment", "Games"]],
157
+ readers, &rss20_maker)
158
+ _assert_itunes_category([["Arts & Entertainment", "Games"],
159
+ ["Technology", "Computers"],
160
+ "Audio Blogs"],
161
+ readers, &rss20_maker)
162
+ end
163
+ end
164
+
165
+ def assert_itunes_image(readers, &rss20_maker)
166
+ _wrap_assertion do
167
+ url = "http://example.com/podcasts/everything/AllAboutEverything.jpg"
168
+ content = tag("itunes:image", nil, {"href" => url})
169
+ rss20 = itunes_rss20_parse(content, &rss20_maker)
170
+ target = chain_reader(rss20, readers)
171
+ assert_not_nil(target.itunes_image)
172
+ assert_equal(url, target.itunes_image.href)
173
+
174
+ assert_missing_attribute("image", "href") do
175
+ content = tag("itunes:image")
176
+ itunes_rss20_parse(content, &rss20_maker)
177
+ end
178
+ end
179
+ end
180
+
181
+ def _assert_itunes_duration(hour, minute, second, value,
182
+ readers, &rss20_maker)
183
+ content = tag("itunes:duration", value)
184
+ rss20 = itunes_rss20_parse(content, &rss20_maker)
185
+ duration = chain_reader(rss20, readers).itunes_duration
186
+ assert_equal(value, duration.content)
187
+ assert_equal(hour, duration.hour)
188
+ assert_equal(minute, duration.minute)
189
+ assert_equal(second, duration.second)
190
+ end
191
+
192
+ def _assert_itunes_duration_not_available_value(value, &rss20_maker)
193
+ assert_not_available_value("duration", value) do
194
+ content = tag("itunes:duration", value)
195
+ itunes_rss20_parse(content, &rss20_maker)
196
+ end
197
+ end
198
+
199
+ def assert_itunes_duration(readers, &rss20_maker)
200
+ _wrap_assertion do
201
+ _assert_itunes_duration(7, 14, 5, "07:14:05", readers, &rss20_maker)
202
+ _assert_itunes_duration(7, 14, 5, "7:14:05", readers, &rss20_maker)
203
+ _assert_itunes_duration(0, 4, 55, "04:55", readers, &rss20_maker)
204
+ _assert_itunes_duration(0, 4, 5, "4:05", readers, &rss20_maker)
205
+
206
+ _assert_itunes_duration_not_available_value("5", &rss20_maker)
207
+ _assert_itunes_duration_not_available_value("09:07:14:05", &rss20_maker)
208
+ _assert_itunes_duration_not_available_value("10:5", &rss20_maker)
209
+ _assert_itunes_duration_not_available_value("10:03:5", &rss20_maker)
210
+ _assert_itunes_duration_not_available_value("10:3:05", &rss20_maker)
211
+
212
+ _assert_itunes_duration_not_available_value("xx:xx:xx", &rss20_maker)
213
+ end
214
+ end
215
+
216
+ def _assert_itunes_explicit(explicit, value, readers, &rss20_maker)
217
+ content = tag("itunes:explicit", value)
218
+ rss20 = itunes_rss20_parse(content, &rss20_maker)
219
+ target = chain_reader(rss20, readers)
220
+ assert_equal(value, target.itunes_explicit)
221
+ assert_equal(explicit, target.itunes_explicit?)
222
+ end
223
+
224
+ def assert_itunes_explicit(readers, &rss20_maker)
225
+ _wrap_assertion do
226
+ _assert_itunes_explicit(true, "yes", readers, &rss20_maker)
227
+ _assert_itunes_explicit(false, "clean", readers, &rss20_maker)
228
+ _assert_itunes_explicit(nil, "no", readers, &rss20_maker)
229
+ end
230
+ end
231
+
232
+ def _assert_itunes_keywords(keywords, value, readers, &rss20_maker)
233
+ content = tag("itunes:keywords", value)
234
+ rss20 = itunes_rss20_parse(content, &rss20_maker)
235
+ target = chain_reader(rss20, readers)
236
+ assert_equal(keywords, target.itunes_keywords)
237
+ end
238
+
239
+ def assert_itunes_keywords(readers, &rss20_maker)
240
+ _wrap_assertion do
241
+ _assert_itunes_keywords(["salt"], "salt", readers, &rss20_maker)
242
+ _assert_itunes_keywords(["salt"], " salt ", readers, &rss20_maker)
243
+ _assert_itunes_keywords(["salt", "pepper", "shaker", "exciting"],
244
+ "salt, pepper, shaker, exciting",
245
+ readers, &rss20_maker)
246
+ _assert_itunes_keywords(["metric", "socket", "wrenches", "toolsalt"],
247
+ "metric, socket, wrenches, toolsalt",
248
+ readers, &rss20_maker)
249
+ _assert_itunes_keywords(["olitics", "red", "blue", "state"],
250
+ "olitics, red, blue, state",
251
+ readers, &rss20_maker)
252
+ end
253
+ end
254
+
255
+ def assert_itunes_new_feed_url(readers, &rss20_maker)
256
+ _wrap_assertion do
257
+ url = "http://newlocation.com/example.rss"
258
+ content = tag("itunes:new-feed-url", url)
259
+ rss20 = itunes_rss20_parse(content, &rss20_maker)
260
+ target = chain_reader(rss20, readers)
261
+ assert_equal(url, target.itunes_new_feed_url)
262
+ end
263
+ end
264
+
265
+ def _assert_itunes_owner(name, email, readers, &rss20_maker)
266
+ content = tag("itunes:owner",
267
+ tag("itunes:name", name) + tag("itunes:email", email))
268
+ rss20 = itunes_rss20_parse(content, &rss20_maker)
269
+ owner = chain_reader(rss20, readers).itunes_owner
270
+ assert_equal(name, owner.itunes_name)
271
+ assert_equal(email, owner.itunes_email)
272
+ end
273
+
274
+ def assert_itunes_owner(readers, &rss20_maker)
275
+ _wrap_assertion do
276
+ _assert_itunes_owner("John Doe", "john.doe@example.com",
277
+ readers, &rss20_maker)
278
+
279
+ assert_missing_tag("name", "owner") do
280
+ content = tag("itunes:owner")
281
+ itunes_rss20_parse(content, &rss20_maker)
282
+ end
283
+
284
+ assert_missing_tag("name", "owner") do
285
+ content = tag("itunes:owner",
286
+ tag("itunes:email", "john.doe@example.com"))
287
+ itunes_rss20_parse(content, &rss20_maker)
288
+ end
289
+
290
+ assert_missing_tag("email", "owner") do
291
+ content = tag("itunes:owner", tag("itunes:name", "John Doe"))
292
+ itunes_rss20_parse(content, &rss20_maker)
293
+ end
294
+ end
295
+ end
296
+
297
+ def _assert_itunes_subtitle(value, readers, &rss20_maker)
298
+ content = tag("itunes:subtitle", value)
299
+ rss20 = itunes_rss20_parse(content, &rss20_maker)
300
+ target = chain_reader(rss20, readers)
301
+ assert_equal(value, target.itunes_subtitle)
302
+ end
303
+
304
+ def assert_itunes_subtitle(readers, &rss20_maker)
305
+ _wrap_assertion do
306
+ _assert_itunes_subtitle("A show about everything", readers, &rss20_maker)
307
+ _assert_itunes_subtitle("A short primer on table spices",
308
+ readers, &rss20_maker)
309
+ _assert_itunes_subtitle("Comparing socket wrenches is fun!",
310
+ readers, &rss20_maker)
311
+ _assert_itunes_subtitle("Red + Blue != Purple", readers, &rss20_maker)
312
+ end
313
+ end
314
+
315
+ def _assert_itunes_summary(value, readers, &rss20_maker)
316
+ content = tag("itunes:summary", value)
317
+ rss20 = itunes_rss20_parse(content, &rss20_maker)
318
+ target = chain_reader(rss20, readers)
319
+ assert_equal(value, target.itunes_summary)
320
+ end
321
+
322
+ def assert_itunes_summary(readers, &rss20_maker)
323
+ _wrap_assertion do
324
+ _assert_itunes_summary("All About Everything is a show about " +
325
+ "everything. Each week we dive into any " +
326
+ "subject known to man and talk about it as " +
327
+ "much as we can. Look for our Podcast in " +
328
+ "the iTunes Music Store",
329
+ readers, &rss20_maker)
330
+ _assert_itunes_summary("This week we talk about salt and pepper " +
331
+ "shakers, comparing and contrasting pour " +
332
+ "rates, construction materials, and overall " +
333
+ "aesthetics. Come and join the party!",
334
+ readers, &rss20_maker)
335
+ _assert_itunes_summary("This week we talk about metric vs. old " +
336
+ "english socket wrenches. Which one is " +
337
+ "better? Do you really need both? Get all " +
338
+ "of your answers here.",
339
+ readers, &rss20_maker)
340
+ _assert_itunes_summary("This week we talk about surviving in a " +
341
+ "Red state if you're a Blue person. Or " +
342
+ "vice versa.",
343
+ readers, &rss20_maker)
344
+ end
345
+ end
346
+ end
347
+ end
@@ -0,0 +1,474 @@
1
+ require "rss-testcase"
2
+
3
+ require "rss/maker"
4
+
5
+ module RSS
6
+ class TestMaker09 < TestCase
7
+ def test_supported?
8
+ assert(RSS::Maker.supported?("0.9"))
9
+ assert(RSS::Maker.supported?("rss0.9"))
10
+ assert(RSS::Maker.supported?("0.91"))
11
+ assert(RSS::Maker.supported?("rss0.91"))
12
+ assert(RSS::Maker.supported?("0.92"))
13
+ assert(RSS::Maker.supported?("rss0.92"))
14
+ assert(!RSS::Maker.supported?("0.93"))
15
+ assert(!RSS::Maker.supported?("rss0.93"))
16
+ end
17
+
18
+ def test_find_class
19
+ assert_equal(RSS::Maker::RSS091, RSS::Maker["0.91"])
20
+ assert_equal(RSS::Maker::RSS091, RSS::Maker["rss0.91"])
21
+ assert_equal(RSS::Maker::RSS092, RSS::Maker["0.9"])
22
+ assert_equal(RSS::Maker::RSS092, RSS::Maker["0.92"])
23
+ assert_equal(RSS::Maker::RSS092, RSS::Maker["rss0.92"])
24
+ end
25
+
26
+ def test_rss
27
+ assert_raise(LocalJumpError) do
28
+ RSS::Maker.make("0.91")
29
+ end
30
+
31
+ rss = RSS::Maker.make("0.9") do |maker|
32
+ setup_dummy_channel(maker)
33
+ setup_dummy_image(maker)
34
+ end
35
+ assert_equal("0.92", rss.rss_version)
36
+
37
+ rss = RSS::Maker.make("0.91") do |maker|
38
+ setup_dummy_channel(maker)
39
+ setup_dummy_image(maker)
40
+ end
41
+ assert_equal("0.91", rss.rss_version)
42
+
43
+
44
+ rss = RSS::Maker.make("0.91") do |maker|
45
+ setup_dummy_channel(maker)
46
+ setup_dummy_image(maker)
47
+
48
+ maker.encoding = "EUC-JP"
49
+ end
50
+ assert_equal("0.91", rss.rss_version)
51
+ assert_equal("EUC-JP", rss.encoding)
52
+
53
+ rss = RSS::Maker.make("0.91") do |maker|
54
+ setup_dummy_channel(maker)
55
+ setup_dummy_image(maker)
56
+
57
+ maker.standalone = "yes"
58
+ end
59
+ assert_equal("0.91", rss.rss_version)
60
+ assert_equal("yes", rss.standalone)
61
+
62
+ rss = RSS::Maker.make("0.91") do |maker|
63
+ setup_dummy_channel(maker)
64
+ setup_dummy_image(maker)
65
+
66
+ maker.encoding = "EUC-JP"
67
+ maker.standalone = "yes"
68
+ end
69
+ assert_equal("0.91", rss.rss_version)
70
+ assert_equal("EUC-JP", rss.encoding)
71
+ assert_equal("yes", rss.standalone)
72
+ end
73
+
74
+ def test_channel
75
+ title = "fugafuga"
76
+ link = "http://hoge.com"
77
+ description = "fugafugafugafuga"
78
+ language = "ja"
79
+ copyright = "foo"
80
+ managingEditor = "bar"
81
+ webMaster = "web master"
82
+ 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))'
83
+ docs = "http://foo.com/doc"
84
+ skipDays = [
85
+ "Sunday",
86
+ "Monday",
87
+ ]
88
+ skipHours = [
89
+ "0",
90
+ "13",
91
+ ]
92
+ pubDate = Time.now
93
+ lastBuildDate = Time.now
94
+
95
+ image_url = "http://example.com/logo.png"
96
+ image_title = "Logo"
97
+
98
+ rss = RSS::Maker.make("0.91") do |maker|
99
+ maker.channel.title = title
100
+ maker.channel.link = link
101
+ maker.channel.description = description
102
+ maker.channel.language = language
103
+ maker.channel.copyright = copyright
104
+ maker.channel.managingEditor = managingEditor
105
+ maker.channel.webMaster = webMaster
106
+ maker.channel.rating = rating
107
+ maker.channel.docs = docs
108
+ maker.channel.pubDate = pubDate
109
+ maker.channel.lastBuildDate = lastBuildDate
110
+
111
+ skipDays.each do |day|
112
+ maker.channel.skipDays.new_day do |new_day|
113
+ new_day.content = day
114
+ end
115
+ end
116
+ skipHours.each do |hour|
117
+ maker.channel.skipHours.new_hour do |new_hour|
118
+ new_hour.content = hour
119
+ end
120
+ end
121
+
122
+ maker.image.url = image_url
123
+ maker.image.title = image_title
124
+ end
125
+ channel = rss.channel
126
+
127
+ assert_equal(title, channel.title)
128
+ assert_equal(link, channel.link)
129
+ assert_equal(description, channel.description)
130
+ assert_equal(language, channel.language)
131
+ assert_equal(copyright, channel.copyright)
132
+ assert_equal(managingEditor, channel.managingEditor)
133
+ assert_equal(webMaster, channel.webMaster)
134
+ assert_equal(rating, channel.rating)
135
+ assert_equal(docs, channel.docs)
136
+ assert_equal(pubDate, channel.pubDate)
137
+ assert_equal(pubDate, channel.date)
138
+ assert_equal(lastBuildDate, channel.lastBuildDate)
139
+
140
+ skipDays.each_with_index do |day, i|
141
+ assert_equal(day, channel.skipDays.days[i].content)
142
+ end
143
+ skipHours.each_with_index do |hour, i|
144
+ assert_equal(hour.to_i, channel.skipHours.hours[i].content)
145
+ end
146
+
147
+ assert(channel.items.empty?)
148
+
149
+ assert_equal(image_url, channel.image.url)
150
+ assert_equal(image_title, channel.image.title)
151
+ assert_equal(link, channel.image.link)
152
+
153
+ assert_nil(channel.textInput)
154
+ end
155
+
156
+ def test_not_valid_channel
157
+ title = "fugafuga"
158
+ link = "http://hoge.com"
159
+ description = "fugafugafugafuga"
160
+ language = "ja"
161
+
162
+ assert_not_set_error("maker.channel", %w(title)) do
163
+ RSS::Maker.make("0.91") do |maker|
164
+ # maker.channel.title = title
165
+ maker.channel.link = link
166
+ maker.channel.description = description
167
+ maker.channel.language = language
168
+ end
169
+ end
170
+
171
+ assert_not_set_error("maker.channel", %w(link)) do
172
+ RSS::Maker.make("0.91") do |maker|
173
+ maker.channel.title = title
174
+ # maker.channel.link = link
175
+ maker.channel.link = nil
176
+ maker.channel.description = description
177
+ maker.channel.language = language
178
+ end
179
+ end
180
+
181
+ assert_not_set_error("maker.channel", %w(description)) do
182
+ RSS::Maker.make("0.91") do |maker|
183
+ maker.channel.title = title
184
+ maker.channel.link = link
185
+ # maker.channel.description = description
186
+ maker.channel.language = language
187
+ end
188
+ end
189
+
190
+ assert_not_set_error("maker.channel", %w(language)) do
191
+ RSS::Maker.make("0.91") do |maker|
192
+ maker.channel.title = title
193
+ maker.channel.link = link
194
+ maker.channel.description = description
195
+ # maker.channel.language = language
196
+ end
197
+ end
198
+ end
199
+
200
+ def test_image
201
+ title = "fugafuga"
202
+ link = "http://hoge.com"
203
+ url = "http://hoge.com/hoge.png"
204
+ width = "144"
205
+ height = "400"
206
+ description = "an image"
207
+
208
+ rss = RSS::Maker.make("0.91") do |maker|
209
+ setup_dummy_channel(maker)
210
+ maker.channel.link = link
211
+
212
+ maker.image.title = title
213
+ maker.image.url = url
214
+ maker.image.width = width
215
+ maker.image.height = height
216
+ maker.image.description = description
217
+ end
218
+ image = rss.image
219
+ assert_equal(title, image.title)
220
+ assert_equal(link, image.link)
221
+ assert_equal(url, image.url)
222
+ assert_equal(width.to_i, image.width)
223
+ assert_equal(height.to_i, image.height)
224
+ assert_equal(description, image.description)
225
+
226
+ assert_not_set_error("maker.channel", %w(description title language)) do
227
+ RSS::Maker.make("0.91") do |maker|
228
+ # setup_dummy_channel(maker)
229
+ maker.channel.link = link
230
+
231
+ maker.image.title = title
232
+ maker.image.url = url
233
+ maker.image.width = width
234
+ maker.image.height = height
235
+ maker.image.description = description
236
+ end
237
+ end
238
+ end
239
+
240
+ def test_not_valid_image
241
+ title = "fugafuga"
242
+ link = "http://hoge.com"
243
+ url = "http://hoge.com/hoge.png"
244
+ width = "144"
245
+ height = "400"
246
+ description = "an image"
247
+
248
+ assert_not_set_error("maker.image", %w(title)) do
249
+ RSS::Maker.make("0.91") do |maker|
250
+ setup_dummy_channel(maker)
251
+ maker.channel.link = link
252
+
253
+ # maker.image.title = title
254
+ maker.image.url = url
255
+ maker.image.width = width
256
+ maker.image.height = height
257
+ maker.image.description = description
258
+ end
259
+ end
260
+
261
+ assert_not_set_error("maker.channel", %w(link)) do
262
+ RSS::Maker.make("0.91") do |maker|
263
+ setup_dummy_channel(maker)
264
+ # maker.channel.link = link
265
+ maker.channel.link = nil
266
+
267
+ maker.image.title = title
268
+ maker.image.url = url
269
+ maker.image.width = width
270
+ maker.image.height = height
271
+ maker.image.description = description
272
+ end
273
+ end
274
+
275
+ assert_not_set_error("maker.image", %w(url)) do
276
+ RSS::Maker.make("0.91") do |maker|
277
+ setup_dummy_channel(maker)
278
+ maker.channel.link = link
279
+
280
+ maker.image.title = title
281
+ # maker.image.url = url
282
+ maker.image.width = width
283
+ maker.image.height = height
284
+ maker.image.description = description
285
+ end
286
+ end
287
+ end
288
+
289
+ def test_items(with_convenience_way=true)
290
+ title = "TITLE"
291
+ link = "http://hoge.com/"
292
+ description = "text hoge fuga"
293
+
294
+ rss = RSS::Maker.make("0.91") do |maker|
295
+ setup_dummy_channel(maker)
296
+ setup_dummy_image(maker)
297
+ end
298
+ assert(rss.channel.items.empty?)
299
+
300
+ rss = RSS::Maker.make("0.91") do |maker|
301
+ setup_dummy_channel(maker)
302
+
303
+ maker.items.new_item do |item|
304
+ item.title = title
305
+ item.link = link
306
+ # item.description = description
307
+ end
308
+
309
+ setup_dummy_image(maker)
310
+ end
311
+ assert_equal(1, rss.channel.items.size)
312
+ item = rss.channel.items.first
313
+ assert_equal(title, item.title)
314
+ assert_equal(link, item.link)
315
+ assert_nil(item.description)
316
+
317
+
318
+ item_size = 5
319
+ rss = RSS::Maker.make("0.91") do |maker|
320
+ setup_dummy_channel(maker)
321
+
322
+ item_size.times do |i|
323
+ maker.items.new_item do |_item|
324
+ _item.title = "#{title}#{i}"
325
+ _item.link = "#{link}#{i}"
326
+ _item.description = "#{description}#{i}"
327
+ end
328
+ end
329
+ maker.items.do_sort = true
330
+
331
+ setup_dummy_image(maker)
332
+ end
333
+ assert_equal(item_size, rss.items.size)
334
+ rss.channel.items.each_with_index do |_item, i|
335
+ assert_equal("#{title}#{i}", _item.title)
336
+ assert_equal("#{link}#{i}", _item.link)
337
+ assert_equal("#{description}#{i}", _item.description)
338
+ end
339
+
340
+ rss = RSS::Maker.make("0.91") do |maker|
341
+ setup_dummy_channel(maker)
342
+
343
+ item_size.times do |i|
344
+ maker.items.new_item do |_item|
345
+ _item.title = "#{title}#{i}"
346
+ _item.link = "#{link}#{i}"
347
+ _item.description = "#{description}#{i}"
348
+ end
349
+ end
350
+ maker.items.do_sort = Proc.new do |x, y|
351
+ if with_convenience_way
352
+ y.title[-1] <=> x.title[-1]
353
+ else
354
+ y.title {|t| t.content[-1]} <=> x.title {|t| t.content[-1]}
355
+ end
356
+ end
357
+
358
+ setup_dummy_image(maker)
359
+ end
360
+ assert_equal(item_size, rss.items.size)
361
+ rss.channel.items.reverse.each_with_index do |_item, i|
362
+ assert_equal("#{title}#{i}", _item.title)
363
+ assert_equal("#{link}#{i}", _item.link)
364
+ assert_equal("#{description}#{i}", _item.description)
365
+ end
366
+ end
367
+
368
+ def test_items_with_new_api_since_018
369
+ test_items(false)
370
+ end
371
+
372
+ def test_textInput
373
+ title = "fugafuga"
374
+ description = "text hoge fuga"
375
+ name = "hoge"
376
+ link = "http://hoge.com"
377
+
378
+ rss = RSS::Maker.make("0.91") do |maker|
379
+ setup_dummy_channel(maker)
380
+ setup_dummy_image(maker)
381
+
382
+ maker.textinput.title = title
383
+ maker.textinput.description = description
384
+ maker.textinput.name = name
385
+ maker.textinput.link = link
386
+ end
387
+ textInput = rss.channel.textInput
388
+ assert_equal(title, textInput.title)
389
+ assert_equal(description, textInput.description)
390
+ assert_equal(name, textInput.name)
391
+ assert_equal(link, textInput.link)
392
+
393
+ assert_not_set_error("maker.channel",
394
+ %w(link language description title)) do
395
+ RSS::Maker.make("0.91") do |maker|
396
+ # setup_dummy_channel(maker)
397
+
398
+ maker.textinput.title = title
399
+ maker.textinput.description = description
400
+ maker.textinput.name = name
401
+ maker.textinput.link = link
402
+ end
403
+ end
404
+ end
405
+
406
+ def test_not_valid_textInput
407
+ title = "fugafuga"
408
+ description = "text hoge fuga"
409
+ name = "hoge"
410
+ link = "http://hoge.com"
411
+
412
+ rss = RSS::Maker.make("0.91") do |maker|
413
+ setup_dummy_channel(maker)
414
+ setup_dummy_image(maker)
415
+
416
+ # maker.textinput.title = title
417
+ maker.textinput.description = description
418
+ maker.textinput.name = name
419
+ maker.textinput.link = link
420
+ end
421
+ assert_nil(rss.channel.textInput)
422
+
423
+ rss = RSS::Maker.make("0.91") do |maker|
424
+ setup_dummy_channel(maker)
425
+ setup_dummy_image(maker)
426
+
427
+ maker.textinput.title = title
428
+ # maker.textinput.description = description
429
+ maker.textinput.name = name
430
+ maker.textinput.link = link
431
+ end
432
+ assert_nil(rss.channel.textInput)
433
+
434
+ rss = RSS::Maker.make("0.91") do |maker|
435
+ setup_dummy_channel(maker)
436
+ setup_dummy_image(maker)
437
+
438
+ maker.textinput.title = title
439
+ maker.textinput.description = description
440
+ # maker.textinput.name = name
441
+ maker.textinput.link = link
442
+ end
443
+ assert_nil(rss.channel.textInput)
444
+
445
+ rss = RSS::Maker.make("0.91") do |maker|
446
+ setup_dummy_channel(maker)
447
+ setup_dummy_image(maker)
448
+
449
+ maker.textinput.title = title
450
+ maker.textinput.description = description
451
+ maker.textinput.name = name
452
+ # maker.textinput.link = link
453
+ end
454
+ assert_nil(rss.channel.textInput)
455
+ end
456
+
457
+ def test_date_in_string
458
+ date = Time.now
459
+
460
+ rss = RSS::Maker.make("0.91") do |maker|
461
+ setup_dummy_channel(maker)
462
+ setup_dummy_image(maker)
463
+
464
+ maker.items.new_item do |item|
465
+ item.title = "The first item"
466
+ item.link = "http://example.com/blog/1.html"
467
+ item.date = date.rfc822
468
+ end
469
+ end
470
+
471
+ assert_equal(date.iso8601, rss.items[0].date.iso8601)
472
+ end
473
+ end
474
+ end