diff --git a/ChangeLog b/ChangeLog index d12da1a4c8..41f963cec8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Sun Oct 31 23:12:10 2004 Kouhei Sutou + + * lib/rss/maker/*.rb: added RSS Maker. + + * test/rss/test_maker_*.rb: added tests for RSS Maker. + Sun Oct 31 16:58:12 2004 Masaki Suketa * ext/win32ole/win32ole.c: add WIN32OLE.codepage, WIN32OLE.codepage=. diff --git a/lib/rss/0.9.rb b/lib/rss/0.9.rb index dd5f93b868..d5c6b3a89d 100644 --- a/lib/rss/0.9.rb +++ b/lib/rss/0.9.rb @@ -252,7 +252,7 @@ EOT install_get_attribute(name, uri, required) end - def initialize(domain, port, path, rp, protocol) + def initialize(domain=nil, port=nil, path=nil, rp=nil, protocol=nil) super() @domain = domain @port = port diff --git a/lib/rss/maker/0.9.rb b/lib/rss/maker/0.9.rb new file mode 100644 index 0000000000..7223246647 --- /dev/null +++ b/lib/rss/maker/0.9.rb @@ -0,0 +1,163 @@ +require "rss/0.9" + +require "rss/maker/base" + +module RSS + module Maker + + class RSS09 < RSSBase + + def initialize(rss_version="0.91") + super + end + + def to_rss + rss = Rss.new(@rss_version, @version, @encoding, @standalone) + setup_xml_stylesheets(rss) + setup_channel(rss) + setup_other_elements(rss) + if rss.channel + rss + else + nil + end + end + + private + def setup_channel(rss) + @channel.to_rss(rss) + end + + class Channel < ChannelBase + + alias_method(:pubDate, :date) + alias_method(:pubDate=, :date=) + + def to_rss(rss) + channel = Rss::Channel.new + set = setup_values(channel) + if set + rss.channel = channel + setup_items(rss) + setup_image(rss) + setup_textinput(rss) + setup_other_elements(rss) + if rss.channel.image + rss + else + nil + end + end + end + + def have_required_values? + @title and @link and @description and @language and + @maker.image.have_required_values? + end + + private + def setup_items(rss) + @maker.items.to_rss(rss) + end + + def setup_image(rss) + @maker.image.to_rss(rss) + end + + def setup_textinput(rss) + @maker.textinput.to_rss(rss) + end + + def variables + super + ["pubDate"] + end + + class Cloud < CloudBase + end + + end + + class Image < ImageBase + def to_rss(rss) + image = Rss::Channel::Image.new + set = setup_values(image) + if set + image.link = link + rss.channel.image = image + setup_other_elements(rss) + end + end + + def have_required_values? + @url and @title and link + end + end + + class Items < ItemsBase + def to_rss(rss) + if rss.channel + normalize.each do |item| + item.to_rss(rss) + end + setup_other_elements(rss) + end + end + + class Item < ItemBase + def to_rss(rss) + item = Rss::Channel::Item.new + set = setup_values(item) + if set + rss.items << item + setup_other_elements(rss) + end + end + + private + def have_required_values? + @title and @link + end + + class Guid < GuidBase + def to_rss(*args) + end + end + + class Enclosure < EnclosureBase + def to_rss(*args) + end + end + + class Source < SourceBase + def to_rss(*args) + end + end + + class Category < CategoryBase + def to_rss(*args) + end + end + + end + end + + class Textinput < TextinputBase + def to_rss(rss) + textInput = Rss::Channel::TextInput.new + set = setup_values(textInput) + if set + rss.channel.textInput = textInput + setup_other_elements(rss) + end + end + + private + def have_required_values? + @title and @description and @name and @link + end + end + end + + add_maker(filename_to_version(__FILE__), RSS09) + end +end diff --git a/lib/rss/maker/1.0.rb b/lib/rss/maker/1.0.rb new file mode 100644 index 0000000000..894bcc0a24 --- /dev/null +++ b/lib/rss/maker/1.0.rb @@ -0,0 +1,184 @@ +require "rss/1.0" + +require "rss/maker/base" + +module RSS + module Maker + + class RSS10 < RSSBase + + def initialize + super("1.0") + end + + def to_rss + rss = RDF.new(@version, @encoding, @standalone) + setup_xml_stylesheets(rss) + setup_channel(rss) + setup_image(rss) + setup_items(rss) + setup_textinput(rss) + setup_other_elements(rss) + if rss.channel + rss + else + nil + end + end + + private + def setup_channel(rss) + @channel.to_rss(rss) + end + + def setup_image(rss) + @image.to_rss(rss) + end + + def setup_items(rss) + @items.to_rss(rss) + end + + def setup_textinput(rss) + @textinput.to_rss(rss) + end + + class Channel < ChannelBase + + def to_rss(rss) + if @about + channel = RDF::Channel.new(@about) + set = setup_values(channel) + if set + rss.channel = channel + setup_items(rss) + setup_image(rss) + setup_textinput(rss) + setup_other_elements(rss) + end + end + end + + def have_required_values? + @about and @title and @link and @description + end + + private + def setup_items(rss) + items = RDF::Channel::Items.new + seq = items.Seq + @maker.items.normalize.each do |item| + seq.lis << RDF::Channel::Items::Seq::Li.new(item.link) + end + rss.channel.items = items + end + + def setup_image(rss) + if @maker.image.have_required_values? + rss.channel.image = RDF::Channel::Image.new(@maker.image.url) + end + end + + def setup_textinput(rss) + if @maker.textinput.have_required_values? + textinput = RDF::Channel::Textinput.new(@maker.textinput.link) + rss.channel.textinput = textinput + end + end + + class Cloud < CloudBase + end + end + + class Image < ImageBase + def to_rss(rss) + if @url + image = RDF::Image.new(@url) + set = setup_values(image) + if set + rss.image = image + setup_other_elements(rss) + end + end + end + + def have_required_values? + @url and @title and link and @maker.channel.have_required_values? + end + + private + def variables + super + ["link"] + end + end + + class Items < ItemsBase + def to_rss(rss) + if rss.channel + normalize.each do |item| + item.to_rss(rss) + end + setup_other_elements(rss) + end + end + + class Item < ItemBase + def to_rss(rss) + if @link + item = RDF::Item.new(@link) + set = setup_values(item) + if set + rss.items << item + setup_other_elements(rss) + end + end + end + + def have_required_values? + @title and @link + end + + class Guid < GuidBase + def to_rss(*args) + end + end + + class Enclosure < EnclosureBase + def to_rss(*args) + end + end + + class Source < SourceBase + def to_rss(*args) + end + end + + class Category < CategoryBase + def to_rss(*args) + end + end + end + end + + class Textinput < TextinputBase + def to_rss(rss) + if @link + textinput = RDF::Textinput.new(@link) + set = setup_values(textinput) + if set + rss.textinput = textinput + setup_other_elements(rss) + end + end + end + + def have_required_values? + @title and @description and @name and @link and + @maker.channel.have_required_values? + end + end + end + + add_maker(filename_to_version(__FILE__), RSS10) + end +end diff --git a/lib/rss/maker/2.0.rb b/lib/rss/maker/2.0.rb new file mode 100644 index 0000000000..2fa61e80e6 --- /dev/null +++ b/lib/rss/maker/2.0.rb @@ -0,0 +1,131 @@ +require "rss/2.0" + +require "rss/maker/0.9" + +module RSS + module Maker + + class RSS20 < RSS09 + + def initialize(rss_version="2.0") + super + end + + class Channel < RSS09::Channel + + add_other_element("cloud") + + def have_required_values? + @title and @link and @description + end + + private + def setup_cloud(rss, current) + @maker.channel.cloud.to_rss(rss) + end + + class Cloud < RSS09::Channel::Cloud + def to_rss(rss) + cloud = Rss::Channel::Cloud.new + set = setup_values(cloud) + if set + rss.channel.cloud = cloud + setup_other_elements(rss) + end + end + + def have_required_values? + @domain and @port and @path and + @registerProcedure and @protocol + end + end + end + + class Image < RSS09::Image + end + + class Items < RSS09::Items + + class Item < RSS09::Items::Item + + alias_method(:pubDate, :date) + + def have_required_values? + @title or @description + end + + private + def variables + super + ["pubDate"] + end + + class Guid < RSS09::Items::Item::Guid + def to_rss(rss, item) + guid = Rss::Channel::Item::Guid.new + set = setup_values(guid) + if set + item.guid = guid + setup_other_elements(rss) + end + end + + def have_required_values? + @content + end + end + + class Enclosure < RSS09::Items::Item::Enclosure + def to_rss(rss, item) + enclosure = Rss::Channel::Item::Enclosure.new + set = setup_values(enclosure) + if set + item.enclosure = enclosure + setup_other_elements(rss) + end + end + + def have_required_values? + @url and @length and @type + end + end + + class Source < RSS09::Items::Item::Source + def to_rss(rss, item) + source = Rss::Channel::Item::Source.new + set = setup_values(source) + if set + item.source = source + setup_other_elements(rss) + end + end + + def have_required_values? + @url and @content + end + end + + class Category < RSS09::Items::Item::Category + def to_rss(rss, item) + category = Rss::Channel::Item::Category.new + set = setup_values(category) + if set + item.category = category + setup_other_elements(rss) + end + end + + def have_required_values? + @content + end + end + end + + end + + class Textinput < RSS09::Textinput + end + end + + add_maker(filename_to_version(__FILE__), RSS20) + end +end diff --git a/lib/rss/maker/base.rb b/lib/rss/maker/base.rb new file mode 100644 index 0000000000..a9f1639503 --- /dev/null +++ b/lib/rss/maker/base.rb @@ -0,0 +1,380 @@ +require 'forwardable' + +require 'rss/rss' + +module RSS + module Maker + + module Base + + def self.append_features(klass) + super + + klass.module_eval(<<-EOC, __FILE__, __LINE__) + + OTHER_ELEMENTS = [] + NEED_INITIALIZE_VARIABLES = [] + + def self.inherited(subclass) + subclass.const_set("OTHER_ELEMENTS", + OTHER_ELEMENTS.dup) + subclass.const_set("NEED_INITIALIZE_VARIABLES", + NEED_INITIALIZE_VARIABLES.dup) + end + + def self.add_other_element(variable_name) + const_get("OTHER_ELEMENTS") << variable_name + end + + def self.other_elements + const_get("OTHER_ELEMENTS") + end + + def self.add_need_initialize_variable(variable_name) + const_get("NEED_INITIALIZE_VARIABLES") << variable_name + end + + def self.need_initialize_variables + const_get("NEED_INITIALIZE_VARIABLES") + end + EOC + end + + def initialize(maker) + @maker = maker + initialize_variables + end + + def have_required_values? + true + end + + private + def initialize_variables + self.class.need_initialize_variables.each do |variable_name| + instance_eval("@#{variable_name} = nil", __FILE__, __LINE__) + end + end + + def setup_other_elements(rss) + self.class.other_elements.each do |element| + __send__("setup_#{element}", rss, current_element(rss)) + end + end + + def setup_values(target) + set = false + if have_required_values? + variables.each do |var| + setter = "#{var}=" + if target.respond_to?(setter) + value = self.__send__(var) + if value + target.__send__(setter, value) + set = true + end + end + end + end + set + end + + def variables + self.class.need_initialize_variables + end + + end + + class RSSBase + include Base + + class << self + def make(&block) + new.make(&block) + end + end + + attr_reader :rss_version, :xml_stylesheets + attr_reader :channel, :image, :items, :textinput + + attr_accessor :version, :encoding, :standalone + + def initialize(rss_version) + super(self) + @rss_version = rss_version + @version = "1.0" + @encoding = "UTF-8" + @standalone = nil + @xml_stylesheets = make_xml_stylesheets + @channel = make_channel + @image = make_image + @items = make_items + @textinput = make_textinput + end + + def make(&block) + block.call(self) if block + to_rss + end + + def current_element(rss) + rss + end + + private + def make_xml_stylesheets + XMLStyleSheets.new(self) + end + + def make_channel + self.class::Channel.new(self) + end + + def make_image + self.class::Image.new(self) + end + + def make_items + self.class::Items.new(self) + end + + def make_textinput + self.class::Textinput.new(self) + end + + def setup_xml_stylesheets(rss) + rss.xml_stylesheets = @xml_stylesheets.normalize + end + + end + + class XMLStyleSheets + include Base + + extend Forwardable + + def_delegators(:@xml_stylesheets, :<<, :[], :[]=) + + def initialize(maker) + super + @xml_stylesheets = [] + end + + def normalize + @xml_stylesheets.collect do |info| + make_xml_stylesheet(info) + end + end + + private + def make_xml_stylesheet(info) + RSS::XMLStyleSheet.new(*info) + end + end + + class ChannelBase + include Base + + attr_reader :cloud + + %w(about title link description language copyright + managingEditor webMaster rating docs skipDays + skipHours date lastBuildDate category generator ttl + ).each do |element| + attr_accessor element + add_need_initialize_variable(element) + end + + def initialize(maker) + super + @cloud = make_cloud + end + + def current_element(rss) + rss.channel + end + + private + def make_cloud + self.class::Cloud.new(@maker) + end + + class CloudBase + include Base + + %w(domain port path registerProcedure protocol).each do |element| + attr_accessor element + add_need_initialize_variable(element) + end + + def current_element(rss) + rss.channel.cloud + end + + end + end + + class ImageBase + include Base + + %w(title url width height description).each do |element| + attr_accessor element + add_need_initialize_variable(element) + end + + def link + @maker.channel.link + end + + def current_element(rss) + rss.image + end + end + + class ItemsBase + include Base + + extend Forwardable + + def_delegators(:@items, :<<, :[], :[]=, :first, :last) + def_delegators(:@items, :push, :pop, :shift, :unshift) + + attr_accessor :sort + + def initialize(maker) + super + @items = [] + @sort = false + end + + def normalize + sort_if_need + end + + def current_element(rss) + rss.items + end + + def new_item + item = self.class::Item.new(@maker) + @items << item + item + end + + private + def sort_if_need + if @sort.respond_to?(:call) + @items.sort do |x, y| + @sort.call(x, y) + end + elsif @sort + @items.sort do |x, y| + y <=> x + end + else + @items + end + end + + class ItemBase + include Base + + %w(guid enclosure source category).each do |element| + attr_reader element + add_other_element(element) + module_eval(<<-EOC, __FILE__, __LINE__) + private + def setup_#{element}(rss, current) + @#{element}.to_rss(rss, current) + end + + def make_#{element} + self.class::#{element[0,1].upcase}#{element[1..-1]}.new(@maker) + end +EOC + end + + %w(title link description date author comments).each do |element| + attr_accessor element + add_need_initialize_variable(element) + end + + def initialize(maker) + super + @guid = make_guid + @enclosure = make_enclosure + @source = make_source + @category = make_category + end + + def <=>(other) + if @date and other.date + @date <=> other.date + elsif @date + 1 + elsif other.date + -1 + else + 0 + end + end + + def current_element(rss) + rss.items.last + end + + class GuidBase + include Base + + %w(isPermaLink content).each do |element| + attr_accessor element + add_need_initialize_variable(element) + end + end + + class EnclosureBase + include Base + + %w(url length type).each do |element| + attr_accessor element + add_need_initialize_variable(element) + end + end + + class SourceBase + include Base + + %w(url content).each do |element| + attr_accessor element + add_need_initialize_variable(element) + end + end + + class CategoryBase + include Base + + %w(domain content).each do |element| + attr_accessor element + add_need_initialize_variable(element) + end + end + + end + end + + class TextinputBase + include Base + + %w(title description name link).each do |element| + attr_accessor element + add_need_initialize_variable(element) + end + + def current_element(rss) + rss.textinput + end + + end + + end +end diff --git a/lib/rss/maker/content.rb b/lib/rss/maker/content.rb new file mode 100644 index 0000000000..67b237f4ef --- /dev/null +++ b/lib/rss/maker/content.rb @@ -0,0 +1,29 @@ +require 'rss/content' +require 'rss/maker/1.0' + +module RSS + module Maker + module ContentModel + def self.append_features(klass) + super + + ::RSS::ContentModel::ELEMENTS.each do |element| + klass.add_need_initialize_variable(element) + klass.add_other_element(element) + klass.__send__(:attr_accessor, element) + klass.module_eval(<<-EOC, __FILE__, __LINE__) + def setup_#{element}(rss, current) + current.#{element} = @#{element} if @#{element} + end +EOC + end + end + end + + class RSS10 + class Items + class Item; include ContentModel; end + end + end + end +end diff --git a/lib/rss/maker/dublincore.rb b/lib/rss/maker/dublincore.rb new file mode 100644 index 0000000000..6a4c64a464 --- /dev/null +++ b/lib/rss/maker/dublincore.rb @@ -0,0 +1,47 @@ +require 'rss/dublincore' +require 'rss/maker/1.0' + +module RSS + module Maker + module DublinCoreModel + def self.append_features(klass) + super + + ::RSS::DublinCoreModel::ELEMENTS.each do |element| + klass.add_need_initialize_variable(element) + klass.add_other_element(element) + klass.__send__(:attr_accessor, element) + klass.module_eval(<<-EOC, __FILE__, __LINE__) + def setup_#{element}(rss, current) + current.#{element} = #{element} if #{element} + end +EOC + end + end + end + + class RSS10 + class Channel + include DublinCoreModel + + alias_method(:_dc_date, :dc_date) + alias_method(:_dc_date=, :dc_date=) + alias_method(:dc_date, :date) + alias_method(:dc_date=, :date=) + end + + class Image; include DublinCoreModel; end + class Items + class Item + include DublinCoreModel + + alias_method(:_dc_date, :dc_date) + alias_method(:_dc_date=, :dc_date=) + alias_method(:dc_date, :date) + alias_method(:dc_date=, :date=) + end + end + class Textinput; include DublinCoreModel; end + end + end +end diff --git a/lib/rss/maker/syndication.rb b/lib/rss/maker/syndication.rb new file mode 100644 index 0000000000..ad846413ae --- /dev/null +++ b/lib/rss/maker/syndication.rb @@ -0,0 +1,27 @@ +require 'rss/syndication' +require 'rss/maker/1.0' + +module RSS + module Maker + module SyndicationModel + def self.append_features(klass) + super + + ::RSS::SyndicationModel::ELEMENTS.each do |element| + klass.add_need_initialize_variable(element) + klass.add_other_element(element) + klass.__send__(:attr_accessor, element) + klass.module_eval(<<-EOC, __FILE__, __LINE__) + def setup_#{element}(rss, current) + current.#{element} = @#{element} if @#{element} + end +EOC + end + end + end + + class RSS10 + class Channel; include SyndicationModel; end + end + end +end diff --git a/lib/rss/maker/trackback.rb b/lib/rss/maker/trackback.rb new file mode 100644 index 0000000000..ff0e1abe44 --- /dev/null +++ b/lib/rss/maker/trackback.rb @@ -0,0 +1,30 @@ +require 'rss/trackback' +require 'rss/maker/1.0' + +module RSS + module Maker + module TrackBackModel + def self.append_features(klass) + super + + %w(ping about).each do |element| + name = "#{RSS::TRACKBACK_PREFIX}_#{element}" + klass.add_need_initialize_variable(name) + klass.add_other_element(name) + klass.__send__(:attr_accessor, name) + klass.module_eval(<<-EOC, __FILE__, __LINE__) + def setup_#{name}(rss, current) + current.#{name} = @#{name} if @#{name} + end +EOC + end + end + end + + class RSS10 + class Items + class Item; include TrackBackModel; end + end + end + end +end diff --git a/lib/rss/syndication.rb b/lib/rss/syndication.rb index 75f612864d..b8200ad70d 100644 --- a/lib/rss/syndication.rb +++ b/lib/rss/syndication.rb @@ -34,7 +34,6 @@ module RSS alias_method(:_sy_updateFrequency=, :sy_updateFrequency=) def sy_updateFrequency=(new_value) - new_value = new_value.strip validate_sy_updateFrequency(new_value) if @do_validate self._sy_updateFrequency = new_value.to_i end @@ -65,6 +64,7 @@ module RSS SY_UPDATEFREQUENCY_AVAILABLE_RE = /\A\s*\+?\d+\s*\z/ def validate_sy_updateFrequency(value) + value = value.to_s.strip if SY_UPDATEFREQUENCY_AVAILABLE_RE !~ value raise NotAvailableValueError.new("updateFrequency", value) end diff --git a/test/rss/rss-assertions.rb b/test/rss/rss-assertions.rb index 40a72e93cd..6b83cbe093 100644 --- a/test/rss/rss-assertions.rb +++ b/test/rss/rss-assertions.rb @@ -1,4 +1,3 @@ -# -*- tab-width: 2 -*- vim: ts=2 module Test module Unit module Assertions @@ -134,6 +133,30 @@ module RSS pi_str = rdf.to_s.gsub(/<\?xml .*\n/, "").gsub(/\s* x.title[-1] + end + end + assert_equal(item_size, rss.items.size) + rss.channel.items.reverse.each_with_index do |item, i| + assert_equal("#{title}#{i}", item.title) + assert_equal("#{link}#{i}", item.link) + assert_equal("#{description}#{i}", item.description) + end + end + + def test_textInput + title = "fugafuga" + description = "text hoge fuga" + name = "hoge" + link = "http://hoge.com" + + rss = RSS::Maker.make("0.9") do |maker| + setup_dummy_channel(maker) + setup_dummy_image(maker) + + maker.textinput.title = title + maker.textinput.description = description + maker.textinput.name = name + maker.textinput.link = link + end + textInput = rss.channel.textInput + assert_equal(title, textInput.title) + assert_equal(description, textInput.description) + assert_equal(name, textInput.name) + assert_equal(link, textInput.link) + + rss = RSS::Maker.make("0.9") do |maker| + # setup_dummy_channel(maker) + setup_dummy_image(maker) + + maker.textinput.title = title + maker.textinput.description = description + maker.textinput.name = name + maker.textinput.link = link + end + assert_nil(rss) + end + + def test_not_valid_textInput + title = "fugafuga" + description = "text hoge fuga" + name = "hoge" + link = "http://hoge.com" + + rss = RSS::Maker.make("0.9") do |maker| + setup_dummy_channel(maker) + setup_dummy_image(maker) + + # maker.textinput.title = title + maker.textinput.description = description + maker.textinput.name = name + maker.textinput.link = link + end + assert_nil(rss.channel.textInput) + + rss = RSS::Maker.make("0.9") do |maker| + setup_dummy_channel(maker) + setup_dummy_image(maker) + + maker.textinput.title = title + # maker.textinput.description = description + maker.textinput.name = name + maker.textinput.link = link + end + assert_nil(rss.channel.textInput) + + rss = RSS::Maker.make("0.9") do |maker| + setup_dummy_channel(maker) + setup_dummy_image(maker) + + maker.textinput.title = title + maker.textinput.description = description + # maker.textinput.name = name + maker.textinput.link = link + end + assert_nil(rss.channel.textInput) + + rss = RSS::Maker.make("0.9") do |maker| + setup_dummy_channel(maker) + setup_dummy_image(maker) + + maker.textinput.title = title + maker.textinput.description = description + maker.textinput.name = name + # maker.textinput.link = link + end + assert_nil(rss.channel.textInput) + end + end +end diff --git a/test/rss/test_maker_1.0.rb b/test/rss/test_maker_1.0.rb new file mode 100644 index 0000000000..91ba29d711 --- /dev/null +++ b/test/rss/test_maker_1.0.rb @@ -0,0 +1,363 @@ +require "rss-testcase" + +require "rss/maker" + +module RSS + class TestMaker10 < TestCase + + def test_rdf + rss = RSS::Maker.make("1.0") do |maker| + setup_dummy_channel(maker) + end + assert_equal("1.0", rss.rss_version) + + rss = RSS::Maker.make("1.0") do |maker| + setup_dummy_channel(maker) + maker.encoding = "EUC-JP" + end + assert_equal("1.0", rss.rss_version) + assert_equal("EUC-JP", rss.encoding) + + rss = RSS::Maker.make("1.0") do |maker| + setup_dummy_channel(maker) + maker.standalone = "yes" + end + assert_equal("1.0", rss.rss_version) + assert_equal("yes", rss.standalone) + + rss = RSS::Maker.make("1.0") do |maker| + setup_dummy_channel(maker) + maker.encoding = "EUC-JP" + maker.standalone = "yes" + end + assert_equal("1.0", rss.rss_version) + assert_equal("EUC-JP", rss.encoding) + assert_equal("yes", rss.standalone) + end + + def test_channel + about = "http://hoge.com" + title = "fugafuga" + link = "http://hoge.com" + description = "fugafugafugafuga" + + rss = RSS::Maker.make("1.0") + assert_nil(rss) + + rss = RSS::Maker.make("1.0") do |maker| + maker.channel.about = about + maker.channel.title = title + maker.channel.link = link + maker.channel.description = description + end + channel = rss.channel + assert_equal(about, channel.about) + assert_equal(title, channel.title) + assert_equal(link, channel.link) + assert_equal(description, channel.description) + assert_equal(true, channel.items.Seq.lis.empty?) + assert_nil(channel.image) + assert_nil(channel.textinput) + + rss = RSS::Maker.make("1.0") do |maker| + maker.channel.about = about + maker.channel.title = title + maker.channel.link = link + maker.channel.description = description + + setup_dummy_image(maker) + + setup_dummy_textinput(maker) + end + channel = rss.channel + assert_equal(about, channel.about) + assert_equal(title, channel.title) + assert_equal(link, channel.link) + assert_equal(description, channel.description) + assert(channel.items.Seq.lis.empty?) + assert_equal(rss.image.about, channel.image.resource) + assert_equal(rss.textinput.about, channel.textinput.resource) + end + + def test_not_valid_channel + about = "http://hoge.com" + title = "fugafuga" + link = "http://hoge.com" + description = "fugafugafugafuga" + + rss = RSS::Maker.make("1.0") do |maker| + # maker.channel.about = about + maker.channel.title = title + maker.channel.link = link + maker.channel.description = description + end + assert_nil(rss) + + rss = RSS::Maker.make("1.0") do |maker| + maker.channel.about = about + # maker.channel.title = title + maker.channel.link = link + maker.channel.description = description + end + assert_nil(rss) + + rss = RSS::Maker.make("1.0") do |maker| + maker.channel.about = about + maker.channel.title = title + # maker.channel.link = link + maker.channel.description = description + end + assert_nil(rss) + + rss = RSS::Maker.make("1.0") do |maker| + maker.channel.about = about + maker.channel.title = title + maker.channel.link = link + # maker.channel.description = description + end + assert_nil(rss) + end + + + def test_image + title = "fugafuga" + link = "http://hoge.com" + url = "http://hoge.com/hoge.png" + + rss = RSS::Maker.make("1.0") do |maker| + setup_dummy_channel(maker) + maker.channel.link = link + + maker.image.title = title + maker.image.url = url + end + image = rss.image + assert_equal(url, image.about) + assert_equal(url, rss.channel.image.resource) + assert_equal(title, image.title) + assert_equal(link, image.link) + assert_equal(url, image.url) + + rss = RSS::Maker.make("1.0") do |maker| + # setup_dummy_channel(maker) + maker.channel.link = link + + maker.image.title = title + maker.image.url = url + end + assert_nil(rss) + end + + def test_not_valid_image + title = "fugafuga" + link = "http://hoge.com" + url = "http://hoge.com/hoge.png" + + rss = RSS::Maker.make("1.0") do |maker| + setup_dummy_channel(maker) + maker.channel.link = link + + # maker.image.url = url + maker.image.title = title + end + assert_nil(rss.channel.image) + assert_nil(rss.image) + + rss = RSS::Maker.make("1.0") do |maker| + setup_dummy_channel(maker) + maker.channel.link = link + + maker.image.url = url + # maker.image.title = title + end + assert_nil(rss.channel.image) + assert_nil(rss.image) + + rss = RSS::Maker.make("1.0") do |maker| + setup_dummy_channel(maker) + # maker.channel.link = link + maker.channel.link = nil + + maker.image.url = url + maker.image.title = title + end + assert_nil(rss) + end + + def test_items + title = "TITLE" + link = "http://hoge.com/" + description = "text hoge fuga" + + rss = RSS::Maker.make("1.0") do |maker| + setup_dummy_channel(maker) + end + assert(rss.items.empty?) + + rss = RSS::Maker.make("1.0") do |maker| + setup_dummy_channel(maker) + + item = maker.items.new_item + item.title = title + item.link = link + # item.description = description + end + assert_equal(1, rss.items.size) + item = rss.items.first + assert_equal(link, item.about) + assert_equal(title, item.title) + assert_equal(link, item.link) + assert_nil(item.description) + + + item_size = 5 + 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.sort = true + end + assert_equal(item_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 + + 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.sort = Proc.new do |x, y| + y.title[-1] <=> x.title[-1] + end + end + assert_equal(item_size, rss.items.size) + rss.items.reverse.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 + title = "TITLE" + link = "http://hoge.com/" + + rss = RSS::Maker.make("1.0") do |maker| + setup_dummy_channel(maker) + + item = maker.items.new_item + # item.title = title + item.link = link + end + assert(rss.items.empty?) + + rss = RSS::Maker.make("1.0") do |maker| + setup_dummy_channel(maker) + + item = maker.items.new_item + item.title = title + # item.link = link + end + assert(rss.items.empty?) + end + + def test_textinput + title = "fugafuga" + description = "text hoge fuga" + name = "hoge" + link = "http://hoge.com" + + rss = RSS::Maker.make("1.0") do |maker| + setup_dummy_channel(maker) + + maker.textinput.link = link + maker.textinput.title = title + maker.textinput.description = description + maker.textinput.name = name + end + textinput = rss.textinput + assert_equal(link, textinput.about) + assert_equal(link, rss.channel.textinput.resource) + assert_equal(title, textinput.title) + assert_equal(name, textinput.name) + assert_equal(description, textinput.description) + assert_equal(link, textinput.link) + + rss = RSS::Maker.make("1.0") do |maker| + # setup_dummy_channel(maker) + + maker.textinput.link = link + maker.textinput.title = title + maker.textinput.description = description + maker.textinput.name = name + end + assert_nil(rss) + end + + def test_not_valid_textinput + title = "fugafuga" + description = "text hoge fuga" + name = "hoge" + link = "http://hoge.com" + + rss = RSS::Maker.make("1.0") do |maker| + setup_dummy_channel(maker) + + # maker.textinput.link = link + maker.textinput.title = title + maker.textinput.description = description + maker.textinput.name = name + end + assert_nil(rss.channel.textinput) + assert_nil(rss.textinput) + + rss = RSS::Maker.make("1.0") do |maker| + setup_dummy_channel(maker) + + maker.textinput.link = link + # maker.textinput.title = title + maker.textinput.description = description + maker.textinput.name = name + end + assert_nil(rss.channel.textinput) + assert_nil(rss.textinput) + + rss = RSS::Maker.make("1.0") do |maker| + setup_dummy_channel(maker) + + maker.textinput.link = link + maker.textinput.title = title + # maker.textinput.description = description + maker.textinput.name = name + end + assert_nil(rss.channel.textinput) + assert_nil(rss.textinput) + + rss = RSS::Maker.make("1.0") do |maker| + setup_dummy_channel(maker) + + maker.textinput.link = link + maker.textinput.title = title + maker.textinput.description = description + # maker.textinput.name = name + end + assert_nil(rss.channel.textinput) + assert_nil(rss.textinput) + end + + end +end diff --git a/test/rss/test_maker_2.0.rb b/test/rss/test_maker_2.0.rb new file mode 100644 index 0000000000..54375934c4 --- /dev/null +++ b/test/rss/test_maker_2.0.rb @@ -0,0 +1,621 @@ +require "rss-testcase" + +require "rss/maker" + +module RSS + class TestMaker20 < TestCase + + def test_rss + rss = RSS::Maker.make("2.0") + assert_nil(rss) + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + end + assert_equal("2.0", rss.rss_version) + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + + maker.encoding = "EUC-JP" + end + assert_equal("2.0", rss.rss_version) + assert_equal("EUC-JP", rss.encoding) + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + + maker.standalone = "yes" + end + assert_equal("2.0", rss.rss_version) + assert_equal("yes", rss.standalone) + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + + maker.encoding = "EUC-JP" + maker.standalone = "yes" + end + assert_equal("2.0", rss.rss_version) + assert_equal("EUC-JP", rss.encoding) + assert_equal("yes", rss.standalone) + end + + def test_channel + title = "fugafuga" + link = "http://hoge.com" + description = "fugafugafugafuga" + language = "ja" + copyright = "foo" + managingEditor = "bar" + webMaster = "web master" + rating = "6" + docs = "http://foo.com/doc" + skipDays = "Sunday" + skipHours = "13" + pubDate = Time.now + lastBuildDate = Time.now + category = "Nespapers" + generator = "RSS Maker" + ttl = 60 + + rss = RSS::Maker.make("2.0") do |maker| + maker.channel.title = title + maker.channel.link = link + maker.channel.description = description + maker.channel.language = language + maker.channel.copyright = copyright + maker.channel.managingEditor = managingEditor + maker.channel.webMaster = webMaster + maker.channel.rating = rating + maker.channel.docs = docs + maker.channel.skipDays = skipDays + maker.channel.skipHours = skipHours + maker.channel.pubDate = pubDate + maker.channel.lastBuildDate = lastBuildDate + maker.channel.category = category + maker.channel.generator = generator + maker.channel.ttl = ttl + end + channel = rss.channel + + assert_equal(title, channel.title) + assert_equal(link, channel.link) + assert_equal(description, channel.description) + assert_equal(language, channel.language) + assert_equal(copyright, channel.copyright) + assert_equal(managingEditor, channel.managingEditor) + assert_equal(webMaster, channel.webMaster) + assert_equal(rating, channel.rating) + assert_equal(docs, channel.docs) + assert_equal(skipDays, channel.skipDays) + assert_equal(skipHours, channel.skipHours) + assert_equal(pubDate, channel.pubDate) + assert_equal(lastBuildDate, channel.lastBuildDate) + assert_equal(category, channel.category) + assert_equal(generator, channel.generator) + assert_equal(ttl, channel.ttl) + + assert(channel.items.empty?) + assert_nil(channel.image) + assert_nil(channel.textInput) + end + + def test_not_valid_channel + title = "fugafuga" + link = "http://hoge.com" + description = "fugafugafugafuga" + language = "ja" + + rss = RSS::Maker.make("2.0") do |maker| + # maker.channel.title = title + maker.channel.link = link + maker.channel.description = description + maker.channel.language = language + end + assert_nil(rss) + + rss = RSS::Maker.make("2.0") do |maker| + maker.channel.title = title + # maker.channel.link = link + maker.channel.description = description + maker.channel.language = language + end + assert_nil(rss) + + rss = RSS::Maker.make("2.0") do |maker| + maker.channel.title = title + maker.channel.link = link + # maker.channel.description = description + maker.channel.language = language + end + assert_nil(rss) + + rss = RSS::Maker.make("2.0") do |maker| + maker.channel.title = title + maker.channel.link = link + maker.channel.description = description + # maker.channel.language = language + end + assert_not_nil(rss) + end + + + def test_cloud + domain = "rpc.sys.com" + port = "80" + path = "/RPC2" + registerProcedure = "myCloud.rssPleaseNotify" + protocol = "xml-rpc" + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + + maker.channel.cloud.domain = domain + maker.channel.cloud.port = port + maker.channel.cloud.path = path + maker.channel.cloud.registerProcedure = registerProcedure + maker.channel.cloud.protocol = protocol + end + cloud = rss.channel.cloud + assert_equal(domain, cloud.domain) + assert_equal(port, cloud.port) + assert_equal(path, cloud.path) + assert_equal(registerProcedure, cloud.registerProcedure) + assert_equal(protocol, cloud.protocol) + end + + def test_not_valid_cloud + domain = "rpc.sys.com" + port = "80" + path = "/RPC2" + registerProcedure = "myCloud.rssPleaseNotify" + protocol = "xml-rpc" + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + + # maker.channel.cloud.domain = domain + maker.channel.cloud.port = port + maker.channel.cloud.path = path + maker.channel.cloud.registerProcedure = registerProcedure + maker.channel.cloud.protocol = protocol + end + assert_nil(rss.channel.cloud) + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + + maker.channel.cloud.domain = domain + # maker.channel.cloud.port = port + maker.channel.cloud.path = path + maker.channel.cloud.registerProcedure = registerProcedure + maker.channel.cloud.protocol = protocol + end + assert_nil(rss.channel.cloud) + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + + maker.channel.cloud.domain = domain + maker.channel.cloud.port = port + # maker.channel.cloud.path = path + maker.channel.cloud.registerProcedure = registerProcedure + maker.channel.cloud.protocol = protocol + end + assert_nil(rss.channel.cloud) + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + + maker.channel.cloud.domain = domain + maker.channel.cloud.port = port + maker.channel.cloud.path = path + # maker.channel.cloud.registerProcedure = registerProcedure + maker.channel.cloud.protocol = protocol + end + assert_nil(rss.channel.cloud) + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + + maker.channel.cloud.domain = domain + maker.channel.cloud.port = port + maker.channel.cloud.path = path + maker.channel.cloud.registerProcedure = registerProcedure + # maker.channel.cloud.protocol = protocol + end + assert_nil(rss.channel.cloud) + end + + + def test_image + title = "fugafuga" + link = "http://hoge.com" + url = "http://hoge.com/hoge.png" + width = 144 + height = 400 + description = "an image" + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + maker.channel.link = link + + maker.image.title = title + maker.image.url = url + maker.image.width = width + maker.image.height = height + maker.image.description = description + end + image = rss.image + assert_equal(title, image.title) + assert_equal(link, image.link) + assert_equal(url, image.url) + assert_equal(width, image.width) + assert_equal(height, image.height) + assert_equal(description, image.description) + + rss = RSS::Maker.make("2.0") do |maker| + # setup_dummy_channel(maker) + maker.channel.link = link + + maker.image.title = title + maker.image.url = url + maker.image.width = width + maker.image.height = height + maker.image.description = description + end + assert_nil(rss) + end + + def test_not_valid_image + title = "fugafuga" + link = "http://hoge.com" + url = "http://hoge.com/hoge.png" + width = 144 + height = 400 + description = "an image" + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + maker.channel.link = link + + # maker.image.title = title + maker.image.url = url + maker.image.width = width + maker.image.height = height + maker.image.description = description + end + assert_nil(rss.image) + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + # maker.channel.link = link + maker.channel.link = nil + + maker.image.title = title + maker.image.url = url + maker.image.width = width + maker.image.height = height + maker.image.description = description + end + assert_nil(rss) + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + maker.channel.link = link + + maker.image.title = title + # maker.image.url = url + maker.image.width = width + maker.image.height = height + maker.image.description = description + end + assert_nil(rss.image) + end + + def test_items + title = "TITLE" + link = "http://hoge.com/" + description = "text hoge fuga" + author = "oprah@oxygen.net" + comments = "http://www.myblog.org/cgi-local/mt/mt-comments.cgi?entry_id=290" + pubDate = Time.now + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + end + assert(rss.channel.items.empty?) + + item_size = 5 + rss = RSS::Maker.make("2.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}" + item.author = "#{author}#{i}" + item.comments = "#{comments}#{i}" + item.date = pubDate + end + end + assert_equal(item_size, rss.items.size) + rss.channel.items.each_with_index do |item, i| + assert_equal("#{title}#{i}", item.title) + assert_equal("#{link}#{i}", item.link) + assert_equal("#{description}#{i}", item.description) + assert_equal("#{author}#{i}", item.author) + assert_equal("#{comments}#{i}", item.comments) + assert_equal(pubDate, item.pubDate) + end + + rss = RSS::Maker.make("2.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}" + item.author = "#{author}#{i}" + item.comments = "#{comments}#{i}" + item.date = pubDate + end + maker.items.sort = Proc.new do |x, y| + y.title[-1] <=> x.title[-1] + end + end + assert_equal(item_size, rss.items.size) + rss.channel.items.reverse.each_with_index do |item, i| + assert_equal("#{title}#{i}", item.title) + assert_equal("#{link}#{i}", item.link) + assert_equal("#{description}#{i}", item.description) + assert_equal("#{author}#{i}", item.author) + assert_equal("#{comments}#{i}", item.comments) + assert_equal(pubDate, item.pubDate) + end + end + + def test_guid + isPermaLink = true + content = "http://inessential.com/2002/09/01.php#a2" + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + setup_dummy_item(maker) + + guid = maker.items.last.guid + guid.isPermaLink = isPermaLink + guid.content = content + end + guid = rss.channel.items.last.guid + assert_equal(isPermaLink, guid.isPermaLink) + assert_equal(content, guid.content) + end + + def test_not_valid_guid + content = "http://inessential.com/2002/09/01.php#a2" + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + setup_dummy_item(maker) + + guid = maker.items.last.guid + # guid.content = content + end + assert_nil(rss.channel.items.last.guid) + end + + def test_enclosure + url = "http://www.scripting.com/mp3s/weatherReportSuite.mp3" + length = "12216320" + type = "audio/mpeg" + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + setup_dummy_item(maker) + + enclosure = maker.items.last.enclosure + enclosure.url = url + enclosure.length = length + enclosure.type = type + end + enclosure = rss.channel.items.last.enclosure + assert_equal(url, enclosure.url) + assert_equal(length, enclosure.length) + assert_equal(type, enclosure.type) + end + + def test_not_valid_enclosure + url = "http://www.scripting.com/mp3s/weatherReportSuite.mp3" + length = "12216320" + type = "audio/mpeg" + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + setup_dummy_item(maker) + + enclosure = maker.items.last.enclosure + # enclosure.url = url + enclosure.length = length + enclosure.type = type + end + assert_nil(rss.channel.items.last.enclosure) + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + setup_dummy_item(maker) + + enclosure = maker.items.last.enclosure + enclosure.url = url + # enclosure.length = length + enclosure.type = type + end + assert_nil(rss.channel.items.last.enclosure) + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + setup_dummy_item(maker) + + enclosure = maker.items.last.enclosure + enclosure.url = url + enclosure.length = length + # enclosure.type = type + end + assert_nil(rss.channel.items.last.enclosure) + end + + + def test_source + url = "http://static.userland.com/tomalak/links2.xml" + content = "Tomalak's Realm" + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + setup_dummy_item(maker) + + source = maker.items.last.source + source.url = url + source.content = content + end + source = rss.channel.items.last.source + assert_equal(url, source.url) + assert_equal(content, source.content) + end + + def test_not_valid_source + url = "http://static.userland.com/tomalak/links2.xml" + content = "Tomalak's Realm" + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + setup_dummy_item(maker) + + source = maker.items.last.source + # source.url = url + source.content = content + end + assert_nil(rss.channel.items.last.source) + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + setup_dummy_item(maker) + + source = maker.items.last.source + source.url = url + # source.content = content + end + assert_nil(rss.channel.items.last.source) + end + + def test_category + domain = "http://www.fool.com/cusips" + content = "MSFT" + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + setup_dummy_item(maker) + + category = maker.items.last.category + category.domain = domain + category.content = content + end + category = rss.channel.items.last.category + assert_equal(domain, category.domain) + assert_equal(content, category.content) + end + + def test_not_valid_category + content = "Grateful Dead" + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + setup_dummy_item(maker) + + category = maker.items.last.category + # category.content = content + end + assert_nil(rss.channel.items.last.category) + end + + def test_textInput + title = "fugafuga" + description = "text hoge fuga" + name = "hoge" + link = "http://hoge.com" + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + + maker.textinput.title = title + maker.textinput.description = description + maker.textinput.name = name + maker.textinput.link = link + end + textInput = rss.channel.textInput + assert_equal(title, textInput.title) + assert_equal(description, textInput.description) + assert_equal(name, textInput.name) + assert_equal(link, textInput.link) + + rss = RSS::Maker.make("2.0") do |maker| + # setup_dummy_channel(maker) + + maker.textinput.title = title + maker.textinput.description = description + maker.textinput.name = name + maker.textinput.link = link + end + assert_nil(rss) + end + + def test_not_valid_textInput + title = "fugafuga" + description = "text hoge fuga" + name = "hoge" + link = "http://hoge.com" + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + + # maker.textinput.title = title + maker.textinput.description = description + maker.textinput.name = name + maker.textinput.link = link + end + assert_nil(rss.channel.textInput) + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + + maker.textinput.title = title + # maker.textinput.description = description + maker.textinput.name = name + maker.textinput.link = link + end + assert_nil(rss.channel.textInput) + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + + maker.textinput.title = title + maker.textinput.description = description + # maker.textinput.name = name + maker.textinput.link = link + end + assert_nil(rss.channel.textInput) + + rss = RSS::Maker.make("2.0") do |maker| + setup_dummy_channel(maker) + + maker.textinput.title = title + maker.textinput.description = description + maker.textinput.name = name + # maker.textinput.link = link + end + assert_nil(rss.channel.textInput) + end + end +end diff --git a/test/rss/test_maker_content.rb b/test/rss/test_maker_content.rb new file mode 100644 index 0000000000..faadd87131 --- /dev/null +++ b/test/rss/test_maker_content.rb @@ -0,0 +1,34 @@ +require "rss-testcase" + +require "rss/maker" + +module RSS + class TestMakerContent < TestCase + + def setup + @uri = "http://purl.org/rss/1.0/modules/content/" + + @elements = { + :encoded => "ATTENTION", + } + end + + def test_rss10 + rss = RSS::Maker.make("1.0", ["content"]) do |maker| + setup_dummy_channel(maker) + + setup_dummy_item(maker) + item = maker.items.last + @elements.each do |name, value| + item.__send__("#{accessor_name(name)}=", value) + end + end + assert_content(@elements, rss.items.last) + end + + private + def accessor_name(name) + "content_#{name}" + end + end +end diff --git a/test/rss/test_maker_dc.rb b/test/rss/test_maker_dc.rb new file mode 100644 index 0000000000..512622d29f --- /dev/null +++ b/test/rss/test_maker_dc.rb @@ -0,0 +1,71 @@ +require "rss-testcase" + +require "rss/maker" + +module RSS + class TestMakerDublinCore < TestCase + + def setup + @uri = "http://purl.org/dc/elements/1.1/" + + t = Time.iso8601("2000-01-01T12:00:05+00:00") + class << t + alias_method(:to_s, :iso8601) + end + + @elements = { + :title => "hoge", + :description => + " XML is placing increasingly heavy loads on + the existing technical infrastructure of the Internet.", + :creator => "Rael Dornfest (mailto:rael@oreilly.com)", + :subject => "XML", + :publisher => "The O'Reilly Network", + :contributor => "hogehoge", + :type => "fugafuga", + :format => "hohoho", + :identifier => "fufufu", + :source => "barbar", + :language => "ja", + :relation => "cococo", + :rights => "Copyright (c) 2000 O'Reilly & Associates, Inc.", + :date => t, + } + end + + def test_rss10 + rss = RSS::Maker.make("1.0", ["dublincore"]) do |maker| + setup_dummy_channel(maker) + set_elements(maker.channel) + + setup_dummy_image(maker) + set_elements(maker.image) + + setup_dummy_item(maker) + item = maker.items.last + @elements.each do |name, value| + item.__send__("#{accessor_name(name)}=", value) + end + + setup_dummy_textinput(maker) + set_elements(maker.textinput) + end + assert_dublin_core(@elements, rss.channel) + assert_dublin_core(@elements, rss.image) + assert_dublin_core(@elements, rss.items.last) + assert_dublin_core(@elements, rss.textinput) + end + + private + def accessor_name(name) + "dc_#{name}" + end + + def set_elements(target) + @elements.each do |name, value| + target.__send__("#{accessor_name(name)}=", value) + end + end + + end +end diff --git a/test/rss/test_maker_sy.rb b/test/rss/test_maker_sy.rb new file mode 100644 index 0000000000..c41ec1d310 --- /dev/null +++ b/test/rss/test_maker_sy.rb @@ -0,0 +1,43 @@ +require "rss-testcase" + +require "rss/maker" + +module RSS + class TestMakerSyndication < TestCase + + def setup + @uri = "http://purl.org/rss/1.0/modules/syndication/" + + t = Time.iso8601("2000-01-01T12:00:05+00:00") + class << t + alias_method(:to_s, :iso8601) + end + + @elements = { + :updatePeriod => "hourly", + :updateFrequency => 2, + :updateBase => t, + } + end + + def test_rss10 + rss = RSS::Maker.make("1.0", ["syndication"]) do |maker| + setup_dummy_channel(maker) + set_elements(maker.channel) + end + assert_syndication(@elements, rss.channel) + end + + private + def accessor_name(name) + "sy_#{name}" + end + + def set_elements(target) + @elements.each do |name, value| + target.__send__("#{accessor_name(name)}=", value) + end + end + + end +end diff --git a/test/rss/test_maker_trackback.rb b/test/rss/test_maker_trackback.rb new file mode 100644 index 0000000000..bffa60e963 --- /dev/null +++ b/test/rss/test_maker_trackback.rb @@ -0,0 +1,35 @@ +require "rss-testcase" + +require "rss/maker" + +module RSS + class TestMakerTrackBack < TestCase + + def setup + @uri = "http://madskills.com/public/xml/rss/module/trackback/" + + @elements = { + :ping => "http://bar.com/tb.cgi?tb_id=rssplustrackback", + :about => "http://foo.com/trackback/tb.cgi?tb_id=20020923", + } + end + + def test_rss10 + rss = RSS::Maker.make("1.0", ["trackback"]) do |maker| + setup_dummy_channel(maker) + + setup_dummy_item(maker) + item = maker.items.last + @elements.each do |name, value| + item.__send__("#{accessor_name(name)}=", value) + end + end + assert_trackback(@elements, rss.items.last) + end + + private + def accessor_name(name) + "trackback_#{name}" + end + end +end diff --git a/test/rss/test_maker_xml-stylesheet.rb b/test/rss/test_maker_xml-stylesheet.rb new file mode 100644 index 0000000000..13ab0daf8e --- /dev/null +++ b/test/rss/test_maker_xml-stylesheet.rb @@ -0,0 +1,39 @@ +require "rss-testcase" + +require "rss/maker" + +module RSS + class TestMakerXMLStyleSheet < TestCase + + def test_rss10 + href = 'a.xsl' + type = 'text/xsl' + title = 'sample' + media = 'printer' + charset = 'UTF-8' + alternate = 'yes' + + rss = RSS::Maker.make("1.0") do |maker| + maker.xml_stylesheets << { + :href => href, + :type => type, + :title => title, + :media => media, + :charset => charset, + :alternate => alternate, + } + + setup_dummy_channel(maker) + end + + xss = rss.xml_stylesheets.first + assert_equal(href, xss.href) + assert_equal(type, xss.type) + assert_equal(title, xss.title) + assert_equal(media, xss.media) + assert_equal(charset, xss.charset) + assert_equal(alternate, xss.alternate) + end + + end +end