1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/rss/maker/base.rb (RSS::Maker::RSSBase#to_feed): raise

exception not return nil if RSS::Maker.make can't get required information.
* test/rss/rss-assertions.rb: follow the above change.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17673 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
kou 2008-06-29 08:42:46 +00:00
parent 7556f66e9c
commit 94031b9628
3 changed files with 40 additions and 20 deletions

View file

@ -1,3 +1,10 @@
Sun Jun 29 17:41:42 2008 Kouhei Sutou <kou@cozmixng.org>
* lib/rss/maker/base.rb (RSS::Maker::RSSBase#to_feed): raise
exception not return nil if RSS::Maker.make can't get required
information.
* test/rss/rss-assertions.rb: follow the above change.
Sun Jun 29 17:37:23 2008 Kouhei Sutou <kou@cozmixng.org> Sun Jun 29 17:37:23 2008 Kouhei Sutou <kou@cozmixng.org>
* lib/rss/maker/base.rb (RSS::Maker::RSSBase#make): require block. * lib/rss/maker/base.rb (RSS::Maker::RSSBase#make): require block.

View file

@ -420,11 +420,8 @@ module RSS
setup_xml_stylesheets(feed) setup_xml_stylesheets(feed)
setup_elements(feed) setup_elements(feed)
setup_other_elements(feed) setup_other_elements(feed)
if feed.valid? feed.validate
feed feed
else
nil
end
end end
private private

View file

@ -1272,22 +1272,32 @@ EOA
invalid_feed_checker=nil) invalid_feed_checker=nil)
_wrap_assertion do _wrap_assertion do
elements = [] elements = []
invalid_feed = false invalid_feed_exception = nil
feed = RSS::Maker.make("atom:#{feed_type}") do |maker| feed = nil
yield maker begin
targets = chain_reader(maker, maker_readers) feed = RSS::Maker.make("atom:#{feed_type}") do |maker|
targets.each do |target| yield maker
element = maker_extractor.call(target) targets = chain_reader(maker, maker_readers)
elements << element if element targets.each do |target|
element = maker_extractor.call(target)
elements << element if element
end
if invalid_feed_checker
invalid_feed_exception = invalid_feed_checker.call(targets)
end
end end
if invalid_feed_checker rescue RSS::Error
invalid_feed = invalid_feed_checker.call(targets) if invalid_feed_exception.is_a?(RSS::TooMuchTagError)
assert_too_much_tag(invalid_feed_exception.tag,
invalid_feed_exception.parent) do
raise
end
else
raise
end end
end end
if invalid_feed if invalid_feed_exception.nil?
assert_nil(feed)
else
actual_elements = chain_reader(feed, feed_readers) || [] actual_elements = chain_reader(feed, feed_readers) || []
actual_elements = actual_elements.collect do |target| actual_elements = actual_elements.collect do |target|
feed_extractor.call(target) feed_extractor.call(target)
@ -1542,18 +1552,24 @@ EOA
:length => target.length, :length => target.length,
} }
end end
if feed_readers.first == "entries"
parent = "entry"
else
parent = feed_type
end
invalid_feed_checker = Proc.new do |targets| invalid_feed_checker = Proc.new do |targets|
infos = {} infos = {}
invalid = false invalid_exception = nil
targets.each do |target| targets.each do |target|
key = [target.hreflang, target.type] key = [target.hreflang, target.type]
if infos.has_key?(key) if infos.has_key?(key)
invalid = true invalid_exception = RSS::TooMuchTagError.new("link", parent)
break break
end end
infos[key] = true if target.rel.nil? or target.rel == "alternate" infos[key] = true if target.rel.nil? or target.rel == "alternate"
end end
invalid invalid_exception
end end
invalid_feed_checker = nil if allow_duplication invalid_feed_checker = nil if allow_duplication
_assert_maker_atom_elements(feed_type, maker_readers, feed_readers, _assert_maker_atom_elements(feed_type, maker_readers, feed_readers,