mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/rss/maker/dublincore.rb: _really_ supported multiple Dublin
Core items. * test/rss/rss-assertions.rb (assert_multiple_dublin_core): added an assertion for testing multiple Dublin Core items. * test/rss/test_maker_dc.rb (test_rss10_multiple): added a test for making multiple Dublin Core items. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8259 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f1587ee5a0
commit
c3410fc1e1
4 changed files with 81 additions and 7 deletions
20
ChangeLog
20
ChangeLog
|
@ -1,3 +1,14 @@
|
|||
Thu Apr 7 11:49:53 2005 Kouhei Sutou <kou@cozmixng.org>
|
||||
|
||||
* lib/rss/maker/dublincore.rb: _really_ supported multiple Dublin
|
||||
Core items.
|
||||
|
||||
* test/rss/rss-assertions.rb (assert_multiple_dublin_core): added
|
||||
an assertion for testing multiple Dublin Core items.
|
||||
|
||||
* test/rss/test_maker_dc.rb (test_rss10_multiple): added a test
|
||||
for making multiple Dublin Core items.
|
||||
|
||||
Wed Apr 6 16:06:30 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
|
||||
|
||||
* test/ruby/test_env.rb (test_key): should test ENV.key instead of
|
||||
|
@ -20,7 +31,7 @@ Tue Apr 5 15:45:33 2005 Kouhei Sutou <kou@cozmixng.org>
|
|||
|
||||
Tue Apr 5 15:15:26 2005 Kouhei Sutou <kou@cozmixng.org>
|
||||
|
||||
* lib/rss/dublincore.rb: supported multiple DublinCore items.
|
||||
* lib/rss/dublincore.rb: supported multiple Dublin Core items.
|
||||
|
||||
* lib/rss/parser.rb: added class name registry for complex model
|
||||
elements. (ex. have childlen elements, have some attributes and
|
||||
|
@ -28,9 +39,10 @@ Tue Apr 5 15:15:26 2005 Kouhei Sutou <kou@cozmixng.org>
|
|||
|
||||
* lib/rss/maker/base.rb: added default current_element implementation.
|
||||
|
||||
* lib/rss/maker/dublincore.rb: supported multiple DublinCore items.
|
||||
* lib/rss/maker/dublincore.rb: supported multiple Dublin Core
|
||||
items.
|
||||
|
||||
* lib/rss/maker/image.rb: supproted new DublinCore API.
|
||||
* lib/rss/maker/image.rb: supproted new Dublin Core API.
|
||||
|
||||
|
||||
* lib/rss/trackback.rb (RSS::TrackBackUtils.new_with_value_if_need):
|
||||
|
@ -53,7 +65,7 @@ Tue Apr 5 15:15:26 2005 Kouhei Sutou <kou@cozmixng.org>
|
|||
|
||||
|
||||
* test/test_dublincore.rb: added tests for plural accessor and
|
||||
multiple DublinCore items.
|
||||
multiple Dublin Core items.
|
||||
|
||||
* test/test_setup_maker_1.0.rb: fixed swapped actual and expected
|
||||
values.
|
||||
|
|
|
@ -83,12 +83,14 @@ EOC
|
|||
plural_name ||= "#{name}s"
|
||||
klass_name = Utils.to_class_name(name)
|
||||
plural_klass_name = "DublinCore#{Utils.to_class_name(plural_name)}"
|
||||
full_klass_name = "DublinCore#{klass_name}"
|
||||
klass.module_eval(<<-EOC, *Utils.get_file_and_line_from_caller(1))
|
||||
class #{plural_klass_name} < #{plural_klass_name}Base
|
||||
class #{klass_name} < #{klass_name}Base
|
||||
def to_rss(rss, current)
|
||||
if value and current.respond_to?(:dc_#{name})
|
||||
current.dc_#{name} = value
|
||||
new_item = current.class::#{full_klass_name}.new(value)
|
||||
current.dc_#{plural_name} << new_item
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -394,6 +394,16 @@ module RSS
|
|||
end
|
||||
end
|
||||
|
||||
def assert_multiple_dublin_core(elems, target)
|
||||
_wrap_assertion do
|
||||
elems.each do |name, values, plural|
|
||||
plural ||= "#{name}s"
|
||||
actual = target.__send__("dc_#{plural}").collect{|x| x.value}
|
||||
assert_equal(values, actual)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def assert_syndication(elems, target)
|
||||
_wrap_assertion do
|
||||
elems.each do |name, value|
|
||||
|
|
|
@ -56,16 +56,66 @@ module RSS
|
|||
assert_dublin_core(@elements, rss.textinput)
|
||||
end
|
||||
|
||||
def test_rss10_multiple
|
||||
elems = []
|
||||
@elements.each do |name, value|
|
||||
plural = name.to_s + (name == :rights ? "es" : "s")
|
||||
values = [value]
|
||||
if name == :date
|
||||
values << value + 60
|
||||
else
|
||||
values << value * 2
|
||||
end
|
||||
elems << [name, values, plural]
|
||||
end
|
||||
|
||||
rss = RSS::Maker.make("1.0") do |maker|
|
||||
setup_dummy_channel(maker)
|
||||
set_multiple_elements(maker.channel, elems)
|
||||
|
||||
setup_dummy_image(maker)
|
||||
set_multiple_elements(maker.image, elems)
|
||||
|
||||
setup_dummy_item(maker)
|
||||
item = maker.items.last
|
||||
elems.each do |name, values, plural|
|
||||
dc_elems = item.__send__("dc_#{plural}")
|
||||
values.each do |value|
|
||||
elem = dc_elems.__send__("new_#{name}")
|
||||
elem.value = value
|
||||
end
|
||||
end
|
||||
|
||||
setup_dummy_textinput(maker)
|
||||
set_multiple_elements(maker.textinput, elems)
|
||||
end
|
||||
assert_multiple_dublin_core(elems, rss.channel)
|
||||
assert_multiple_dublin_core(elems, rss.image)
|
||||
assert_multiple_dublin_core(elems, rss.items.last)
|
||||
assert_multiple_dublin_core(elems, rss.textinput)
|
||||
end
|
||||
|
||||
private
|
||||
def accessor_name(name)
|
||||
"dc_#{name}"
|
||||
end
|
||||
|
||||
def set_elements(target)
|
||||
@elements.each do |name, value|
|
||||
def set_elements(target, elems=@elements)
|
||||
elems.each do |name, value|
|
||||
target.__send__("#{accessor_name(name)}=", value)
|
||||
end
|
||||
end
|
||||
|
||||
def set_multiple_elements(target, elems)
|
||||
elems.each do |name, values, plural|
|
||||
plural ||= "#{name}s"
|
||||
dc_elems = target.__send__("dc_#{plural}")
|
||||
values.each do |value|
|
||||
new_dc_elem = dc_elems.__send__("new_#{name}")
|
||||
new_dc_elem.value = value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue