1require "rss-testcase"
2
3require "rss/1.0"
4require "rss/2.0"
5require "rss/syndication"
6require "rss/image"
7
8module RSS
9  class TestAccessor < TestCase
10    def test_date
11      channel = Rss::Channel.new
12      channel.pubDate = nil
13      assert_nil(channel.pubDate)
14
15      time = Time.now
16      channel.pubDate = time
17      assert_equal(time, channel.pubDate)
18
19      time = Time.parse(Time.now.rfc822)
20      channel.pubDate = time.rfc822
21      assert_equal(time, channel.pubDate)
22
23      time = Time.parse(Time.now.iso8601)
24      value = time.iso8601
25      assert_not_available_value("pubDate", value) do
26        channel.pubDate = value
27      end
28
29      channel.do_validate = false
30      time = Time.parse(Time.now.iso8601)
31      value = time.iso8601
32      channel.pubDate = value
33      assert_equal(time, channel.pubDate)
34
35      channel.pubDate = nil
36      assert_nil(channel.pubDate)
37    end
38
39    def test_integer
40      image_item = RDF::Item::ImageItem.new
41
42      image_item.width = nil
43      assert_nil(image_item.width)
44
45      width = 10
46      image_item.width = width
47      assert_equal(width, image_item.width)
48
49      width = 10.0
50      image_item.width = width
51      assert_equal(width, image_item.width)
52
53      width = "10"
54      image_item.width = width
55      assert_equal(width.to_i, image_item.width)
56
57      width = "10.0"
58      assert_not_available_value("image:width", width) do
59        image_item.width = width
60      end
61
62      image_item.do_validate = false
63      width = "10.0"
64      image_item.width = width
65      assert_equal(width.to_i, image_item.width)
66
67      image_item.width = nil
68      assert_nil(image_item.width)
69    end
70
71    def test_positive_integer
72      channel = RDF::Channel.new
73
74      channel.sy_updateFrequency = nil
75      assert_nil(channel.sy_updateFrequency)
76
77      freq = 10
78      channel.sy_updateFrequency = freq
79      assert_equal(freq, channel.sy_updateFrequency)
80
81      freq = 10.0
82      channel.sy_updateFrequency = freq
83      assert_equal(freq, channel.sy_updateFrequency)
84
85      freq = "10"
86      channel.sy_updateFrequency = freq
87      assert_equal(freq.to_i, channel.sy_updateFrequency)
88
89      freq = "10.0"
90      assert_not_available_value("sy:updateFrequency", freq) do
91        channel.sy_updateFrequency = freq
92      end
93
94      channel.do_validate = false
95      freq = "10.0"
96      channel.sy_updateFrequency = freq
97      assert_equal(freq.to_i, channel.sy_updateFrequency)
98
99      channel.sy_updateFrequency = nil
100      assert_nil(channel.sy_updateFrequency)
101    end
102  end
103end
104