diff options
author | kou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-04-05 06:42:03 +0000 |
---|---|---|
committer | kou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-04-05 06:42:03 +0000 |
commit | d12dff187a86d0f21ad1628472cd797505ddeabe (patch) | |
tree | 006f7ea1d0995dfc481a63601cc5e19a58d5baba /test/rss/test_dublincore.rb | |
parent | 5ddcd35cf12613969b27c06cf3ca1b57ce68a3f0 (diff) | |
download | ruby-d12dff187a86d0f21ad1628472cd797505ddeabe.tar.gz |
* lib/rss/dublincore.rb: supported multiple DublinCore items.
* lib/rss/parser.rb: added class name registry for complex model
elements. (ex. have childlen elements, have some attributes and
a child element and so on.)
* lib/rss/maker/base.rb: added default current_element implementation.
* lib/rss/maker/dublincore.rb: supported multiple DublinCore items.
* lib/rss/maker/image.rb: supproted new DublinCore API.
* lib/rss/trackback.rb (RSS::TrackBackUtils.new_with_value_if_need):
moved to RSS::Utils.
* lib/rss/utils.rb (RSS::Utils.new_with_value_if_need):
moved from RSS::TrackBackUtils.
* lib/rss/maker/image.rb: fixed invalid argument of
add_need_initialize_variable bug.
* lib/rss/maker/trackback.rb: ditto.
* lib/rss/rss.rb (Hash#merge): added for ruby 1.6.
* lib/rss/rss.rb (RSS::BaseModel.date_writer): changed to accept nil
for date value.
* test/test_dublincore.rb: added tests for plural accessor and
multiple DublinCore items.
* test/test_setup_maker_1.0.rb: fixed swapped actual and expected
values.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8252 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/rss/test_dublincore.rb')
-rw-r--r-- | test/rss/test_dublincore.rb | 72 |
1 files changed, 62 insertions, 10 deletions
diff --git a/test/rss/test_dublincore.rb b/test/rss/test_dublincore.rb index e1ee929afb..5ad9311fb5 100644 --- a/test/rss/test_dublincore.rb +++ b/test/rss/test_dublincore.rb @@ -54,26 +54,35 @@ EOR end def test_parser - assert_nothing_raised do Parser.parse(@rss_source) end @elems.each do |tag, value| - assert_too_much_tag(tag.to_s, "channel") do - Parser.parse(make_RDF(<<-EOR, {@prefix => @uri})) + rss = nil + assert_nothing_raised do + rss = Parser.parse(make_RDF(<<-EOR, {@prefix => @uri})) #{make_channel(("<" + @prefix + ":" + tag.to_s + ">" + value.to_s + "</" + @prefix + ":" + tag.to_s + ">") * 2)} #{make_item} EOR end + plural_reader = "dc_#{tag}" + (tag == :rights ? "es" : "s") + values = rss.channel.__send__(plural_reader).collect do |x| + val = x.value + if val.kind_of?(String) + CGI.escapeHTML(val) + else + val + end + end + assert_equal([value, value], values) end end - - def test_accessor - + + def test_singular_accessor new_value = "hoge" @elems.each do |name, value| @@ -101,15 +110,58 @@ EOR end end end + end + def test_plural_accessor + new_value = "hoge" + + @elems.each do |name, value| + @parents.each do |parent| + parsed_value = @rss.send(parent).send("dc_#{name}") + if parsed_value.kind_of?(String) + parsed_value = CGI.escapeHTML(parsed_value) + end + assert_equal(value, parsed_value) + + plural_reader = "dc_#{name}" + (name == :rights ? "es" : "s") + klass_name = "DublinCore#{Utils.to_class_name(name.to_s)}" + klass = DublinCoreModel.const_get(klass_name) + if name == :date + t = Time.iso8601("2003-01-01T02:30:23+09:00") + class << t + alias_method(:to_s, :iso8601) + end + elems = @rss.send(parent).send(plural_reader) + elems << klass.new(t.iso8601) + values = @rss.send(parent).send(plural_reader).collect{|x| x.value} + assert_equal([@rss.send(parent).send("dc_#{name}"), t], + values) + else + elems = @rss.send(parent).send(plural_reader) + elems << klass.new(new_value) + values = @rss.send(parent).send(plural_reader).collect{|x| x.value} + assert_equal([@rss.send(parent).send("dc_#{name}"), new_value], + values) + end + end + end end def test_to_s - @elems.each do |name, value| excepted = "<#{@prefix}:#{name}>#{value}</#{@prefix}:#{name}>" @parents.each do |parent| - assert_equal(excepted, @rss.send(parent).send("dc_#{name}_element")) + assert_equal(excepted, @rss.send(parent).send("dc_#{name}_elements")) + end + + excepted = Array.new(2, excepted).join("\n") + @parents.each do |parent| + reader = "dc_#{name}" + (name == :rights ? "es" : "s") + elems = @rss.send(parent).send(reader) + klass_name = "DublinCore#{Utils.to_class_name(name.to_s)}" + klass = DublinCoreModel.const_get(klass_name) + elems << klass.new(@rss.send(parent).send("dc_#{name}")) + assert_equal(excepted, @rss.send(parent).send("dc_#{name}_elements")) end end @@ -117,12 +169,12 @@ EOR if @parents.include?(parent.name) parent.each_element do |elem| if elem.namespace == @uri - assert_equal(CGI.escapeHTML(elem.text), @elems[elem.name.intern].to_s) + assert_equal(CGI.escapeHTML(elem.text), + @elems[elem.name.intern].to_s) end end end end - end end |