OSDN Git Service

ruby-1.9.1-rc1
[splhack/AndroidRuby.git] / lib / ruby-1.9.1-rc1 / test / rss / test_setup_maker_itunes.rb
1 require "rss-testcase"
2
3 require "rss/maker"
4
5 module RSS
6   class TestSetupMakerITunes < TestCase
7     def test_setup_maker_simple
8       author = "John Doe"
9       block = true
10       categories = ["Audio Blogs"]
11       image = "http://example.com/podcasts/everything/AllAboutEverything.jpg"
12       duration = "4:05"
13       duration_components = [0, 4, 5]
14       explicit = true
15       keywords = ["salt", "pepper", "shaker", "exciting"]
16       new_feed_url = "http://newlocation.com/example.rss"
17       owner = {:name => "John Doe", :email => "john.doe@example.com"}
18       subtitle = "A show about everything"
19       summary = "All About Everything is a show about " +
20         "everything. Each week we dive into any " +
21         "subject known to man and talk about it " +
22         "as much as we can. Look for our Podcast " +
23         "in the iTunes Music Store"
24
25       feed = RSS::Maker.make("rss2.0") do |maker|
26         setup_dummy_channel(maker)
27         setup_dummy_item(maker)
28
29         channel = maker.channel
30         channel.itunes_author = author
31         channel.itunes_block = block
32         categories.each do |category|
33           channel.itunes_categories.new_category.text = category
34         end
35         channel.itunes_image = image
36         channel.itunes_explicit = explicit
37         channel.itunes_keywords = keywords
38         channel.itunes_owner.itunes_name = owner[:name]
39         channel.itunes_owner.itunes_email = owner[:email]
40         channel.itunes_subtitle = subtitle
41         channel.itunes_summary = summary
42
43         item = maker.items.last
44         item.itunes_author = author
45         item.itunes_block = block
46         item.itunes_duration = duration
47         item.itunes_explicit = explicit
48         item.itunes_keywords = keywords
49         item.itunes_subtitle = subtitle
50         item.itunes_summary = summary
51       end
52       assert_not_nil(feed)
53
54       new_feed = RSS::Maker.make("rss2.0") do |maker|
55         feed.setup_maker(maker)
56       end
57       assert_not_nil(new_feed)
58
59       channel = new_feed.channel
60       item = new_feed.items.last
61
62       assert_equal(author, channel.itunes_author)
63       assert_equal(author, item.itunes_author)
64
65       assert_equal(block, channel.itunes_block?)
66       assert_equal(block, item.itunes_block?)
67
68       assert_equal(categories,
69                    collect_itunes_categories(channel.itunes_categories))
70
71       assert_equal(image, channel.itunes_image.href)
72
73       assert_equal(duration_components,
74                    [item.itunes_duration.hour,
75                     item.itunes_duration.minute,
76                     item.itunes_duration.second])
77
78       assert_equal(explicit, channel.itunes_explicit?)
79       assert_equal(explicit, item.itunes_explicit?)
80
81       assert_equal(keywords, channel.itunes_keywords)
82       assert_equal(keywords, item.itunes_keywords)
83
84       assert_equal(owner,
85                    {
86                      :name => channel.itunes_owner.itunes_name,
87                      :email => channel.itunes_owner.itunes_email
88                    })
89
90       assert_equal(subtitle, channel.itunes_subtitle)
91       assert_equal(subtitle, item.itunes_subtitle)
92
93       assert_equal(summary, channel.itunes_summary)
94       assert_equal(summary, item.itunes_summary)
95     end
96
97     def test_setup_maker_with_nested_categories
98       categories = [["Arts & Entertainment", "Games"],
99                     ["Technology", "Computers"],
100                     "Audio Blogs"]
101
102       feed = RSS::Maker.make("rss2.0") do |maker|
103         setup_dummy_channel(maker)
104         setup_dummy_item(maker)
105
106         channel = maker.channel
107         categories.each do |category|
108           target = channel.itunes_categories
109           if category.is_a?(Array)
110             category.each do |sub_category|
111               target = target.new_category
112               target.text = sub_category
113             end
114           else
115             target.new_category.text = category
116           end
117         end
118       end
119       assert_not_nil(feed)
120
121       new_feed = RSS::Maker.make("rss2.0") do |maker|
122         feed.setup_maker(maker)
123       end
124       assert_not_nil(new_feed)
125
126       channel = new_feed.channel
127
128       assert_equal(categories,
129                    collect_itunes_categories(channel.itunes_categories))
130     end
131
132     private
133     def collect_itunes_categories(categories)
134       categories.collect do |c|
135         rest = collect_itunes_categories(c.itunes_categories)
136         if rest.empty?
137           c.text
138         else
139           [c.text, *rest]
140         end
141       end
142     end
143   end
144 end