From 446eef82cfea0d634266489f79d901f6c50be1f0 Mon Sep 17 00:00:00 2001 From: kou Date: Fri, 16 Sep 2005 23:48:17 +0000 Subject: [PATCH] * lib/rss/maker/base.rb (RSS::Maker::ItemsBase#normalize): fixed strange RSS::Maker::Item#max_size behavior. Thanks to Kazuhiko . * test/rss/test_maker_1.0.rb (RSS::TestMaker10#test_items): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 8 ++++++ lib/rss/maker/base.rb | 6 ++++- test/rss/test_maker_1.0.rb | 54 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 6ccc9c1fa3..7d420259d4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Sat Sep 17 08:35:39 2005 Kouhei Sutou + + * lib/rss/maker/base.rb (RSS::Maker::ItemsBase#normalize): fixed + strange RSS::Maker::Item#max_size behavior. + Thanks to Kazuhiko . + + * test/rss/test_maker_1.0.rb (RSS::TestMaker10#test_items): ditto. + Sat Sep 17 08:02:53 2005 Shugo Maeda * lib/net/imap.rb: supported DIGEST-MD5. Thanks, Mathieu Arnold. diff --git a/lib/rss/maker/base.rb b/lib/rss/maker/base.rb index 4972821cf1..dbd8bf9041 100644 --- a/lib/rss/maker/base.rb +++ b/lib/rss/maker/base.rb @@ -401,7 +401,11 @@ EOC end def normalize - sort_if_need[0..@max_size] + if @max_size >= 0 + sort_if_need[0...@max_size] + else + sort_if_need[0..@max_size] + end end def current_element(rss) diff --git a/test/rss/test_maker_1.0.rb b/test/rss/test_maker_1.0.rb index 1fa86662e1..dca50f7e69 100644 --- a/test/rss/test_maker_1.0.rb +++ b/test/rss/test_maker_1.0.rb @@ -256,6 +256,60 @@ module RSS assert_equal("#{link}#{i}", item.link) assert_equal("#{description}#{i}", item.description) end + + max_size = item_size / 2 + rss = RSS::Maker.make("1.0") do |maker| + setup_dummy_channel(maker) + + item_size.times do |i| + item = maker.items.new_item + item.title = "#{title}#{i}" + item.link = "#{link}#{i}" + item.description = "#{description}#{i}" + end + maker.items.max_size = max_size + end + assert_equal(max_size, rss.items.size) + rss.items.each_with_index do |item, i| + assert_equal("#{link}#{i}", item.about) + assert_equal("#{title}#{i}", item.title) + assert_equal("#{link}#{i}", item.link) + assert_equal("#{description}#{i}", item.description) + end + + max_size = 0 + rss = RSS::Maker.make("1.0") do |maker| + setup_dummy_channel(maker) + + item_size.times do |i| + item = maker.items.new_item + item.title = "#{title}#{i}" + item.link = "#{link}#{i}" + item.description = "#{description}#{i}" + end + maker.items.max_size = max_size + end + assert_equal(max_size, rss.items.size) + + max_size = -2 + rss = RSS::Maker.make("1.0") do |maker| + setup_dummy_channel(maker) + + item_size.times do |i| + item = maker.items.new_item + item.title = "#{title}#{i}" + item.link = "#{link}#{i}" + item.description = "#{description}#{i}" + end + maker.items.max_size = max_size + end + assert_equal(item_size + max_size + 1, rss.items.size) + rss.items.each_with_index do |item, i| + assert_equal("#{link}#{i}", item.about) + assert_equal("#{title}#{i}", item.title) + assert_equal("#{link}#{i}", item.link) + assert_equal("#{description}#{i}", item.description) + end end def test_not_valid_items