rss 0.2.8 → 0.2.9

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