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

* lib/rss/rss.rb: improved type conversion.

* lib/rss/1.0.rb: ditto.
* lib/rss/0.9.rb: ditto.
* lib/rss/2.0.rb: ditto.
* lib/rss/image.rb: ditto.
* lib/rss/syndication.rb: ditto.

* test/rss/test_2.0.rb: added type conversion tests.
* test/rss/test_accessor.rb: ditto.
* test/rss/test_to_s.rb: ditto.
* test/rss/test_syndication.rb: ditto.
* test/rss/test_setup_maker_2.0.rb: ditto.
* test/rss/test_setup_maker_1.0.rb: ditto.
* test/rss/test_setup_maker_0.9.rb: ditto.
* test/rss/test_maker_sy.rb: ditto.
* test/rss/test_maker_image.rb: ditto.
* test/rss/test_maker_2.0.rb: ditto.
* test/rss/test_maker_0.9.rb: ditto.
* test/rss/test_image.rb: ditto.

* test/rss/test_maker_1.0.rb: use assert instead of assert_equal.

* test/rss/rss-assertions.rb: improved type conversion assertions.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9610 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
kou 2005-11-25 03:43:48 +00:00
parent ea0e7c1599
commit 456ba712fe
21 changed files with 461 additions and 218 deletions

View file

@ -1,3 +1,29 @@
Fri Nov 25 12:39:56 2005 Kouhei Sutou <kou@cozmixng.org>
* lib/rss/rss.rb: improved type conversion.
* lib/rss/1.0.rb: ditto.
* lib/rss/0.9.rb: ditto.
* lib/rss/2.0.rb: ditto.
* lib/rss/image.rb: ditto.
* lib/rss/syndication.rb: ditto.
* test/rss/test_2.0.rb: added type conversion tests.
* test/rss/test_accessor.rb: ditto.
* test/rss/test_to_s.rb: ditto.
* test/rss/test_syndication.rb: ditto.
* test/rss/test_setup_maker_2.0.rb: ditto.
* test/rss/test_setup_maker_1.0.rb: ditto.
* test/rss/test_setup_maker_0.9.rb: ditto.
* test/rss/test_maker_sy.rb: ditto.
* test/rss/test_maker_image.rb: ditto.
* test/rss/test_maker_2.0.rb: ditto.
* test/rss/test_maker_0.9.rb: ditto.
* test/rss/test_image.rb: ditto.
* test/rss/test_maker_1.0.rb: use assert instead of assert_equal.
* test/rss/rss-assertions.rb: improved type conversion assertions.
Fri Nov 25 10:38:20 2005 Kouhei Sutou <kou@cozmixng.org> Fri Nov 25 10:38:20 2005 Kouhei Sutou <kou@cozmixng.org>
* lib/rss/image.rb: added Image prefix. * lib/rss/image.rb: added Image prefix.

View file

@ -269,7 +269,7 @@ module RSS
def initialize(content=nil) def initialize(content=nil)
super() super()
@content = content self.content = content
end end
end end
@ -310,18 +310,12 @@ module RSS
class Hour < Element class Hour < Element
include RSS09 include RSS09
content_setup content_setup(:integer)
def initialize(content=nil) def initialize(content=nil)
super() super()
@content = content self.content = content
end end
remove_method :content=
def content=(value)
@content = value.to_i
end
end end
end end
@ -334,20 +328,24 @@ module RSS
install_text_element(name) install_text_element(name)
install_model(name, nil) install_model(name, nil)
end end
%w(width height description).each do |name| [
install_text_element(name) ["width", :integer],
["height", :integer],
["description"],
].each do |name, type|
install_text_element(name, type)
install_model(name, "?") install_model(name, "?")
end end
def initialize(url=nil, title=nil, link=nil, width=nil, height=nil, def initialize(url=nil, title=nil, link=nil, width=nil, height=nil,
description=nil) description=nil)
super() super()
@url = url self.url = url
@title = title self.title = title
@link = link self.link = link
@width = width self.width = width
@height = height self.height = height
@description = description self.description = description
end end
def to_s(need_convert=true, indent=calc_indent) def to_s(need_convert=true, indent=calc_indent)
@ -386,21 +384,21 @@ module RSS
[ [
["domain", nil, true], ["domain", nil, true],
["port", nil, true], ["port", nil, true, :integer],
["path", nil, true], ["path", nil, true],
["registerProcedure", nil, true], ["registerProcedure", nil, true],
["protocol", nil ,true], ["protocol", nil, true],
].each do |name, uri, required| ].each do |name, uri, required, type|
install_get_attribute(name, uri, required) install_get_attribute(name, uri, required, type)
end end
def initialize(domain=nil, port=nil, path=nil, rp=nil, protocol=nil) def initialize(domain=nil, port=nil, path=nil, rp=nil, protocol=nil)
super() super()
@domain = domain self.domain = domain
@port = port self.port = port
@path = path self.path = path
@registerProcedure = rp self.registerProcedure = rp
@protocol = protocol self.protocol = protocol
end end
def to_s(need_convert=true, indent=calc_indent) def to_s(need_convert=true, indent=calc_indent)
@ -511,8 +509,8 @@ module RSS
def initialize(url=nil, content=nil) def initialize(url=nil, content=nil)
super() super()
@url = url self.url = url
@content = content self.content = content
end end
private private
@ -543,17 +541,17 @@ module RSS
[ [
["url", nil, true], ["url", nil, true],
["length", nil, true], ["length", nil, true, :integer],
["type", nil, true], ["type", nil, true],
].each do |name, uri, required| ].each do |name, uri, required, type|
install_get_attribute(name, uri, required) install_get_attribute(name, uri, required, type)
end end
def initialize(url=nil, length=nil, type=nil) def initialize(url=nil, length=nil, type=nil)
super() super()
@url = url self.url = url
@length = length self.length = length
@type = type self.type = type
end end
def to_s(need_convert=true, indent=calc_indent) def to_s(need_convert=true, indent=calc_indent)
@ -596,8 +594,8 @@ module RSS
def initialize(domain=nil, content=nil) def initialize(domain=nil, content=nil)
super() super()
@domain = domain self.domain = domain
@content = content self.content = content
end end
private private
@ -631,10 +629,10 @@ module RSS
def initialize(title=nil, description=nil, name=nil, link=nil) def initialize(title=nil, description=nil, name=nil, link=nil)
super() super()
@title = title self.title = title
@description = description self.description = description
@name = name self.name = name
@link = link self.link = link
end end
def to_s(need_convert=true, indent=calc_indent) def to_s(need_convert=true, indent=calc_indent)

View file

@ -113,7 +113,7 @@ module RSS
def initialize(resource=nil) def initialize(resource=nil)
super() super()
@resource = resource self.resource = resource
end end
def full_name def full_name
@ -293,7 +293,7 @@ module RSS
def initialize(about=nil) def initialize(about=nil)
super() super()
@about = about self.about = about
end end
def to_s(need_convert=true, indent=calc_indent) def to_s(need_convert=true, indent=calc_indent)
@ -364,7 +364,7 @@ module RSS
def initialize(resource=nil) def initialize(resource=nil)
super() super()
@resource = resource self.resource = resource
end end
def to_s(need_convert=true, indent=calc_indent) def to_s(need_convert=true, indent=calc_indent)
@ -401,7 +401,7 @@ module RSS
def initialize(resource=nil) def initialize(resource=nil)
super() super()
@resource = resource self.resource = resource
end end
def to_s(need_convert=true, indent=calc_indent) def to_s(need_convert=true, indent=calc_indent)
@ -509,7 +509,7 @@ module RSS
def initialize(about=nil) def initialize(about=nil)
super() super()
@about = about self.about = about
end end
def to_s(need_convert=true, indent=calc_indent) def to_s(need_convert=true, indent=calc_indent)
@ -579,7 +579,7 @@ module RSS
def initialize(about=nil) def initialize(about=nil)
super() super()
@about = about self.about = about
end end
def to_s(need_convert=true, indent=calc_indent) def to_s(need_convert=true, indent=calc_indent)
@ -654,7 +654,7 @@ module RSS
def initialize(about=nil) def initialize(about=nil)
super() super()
@about = about self.about = about
end end
def to_s(need_convert=true, indent=calc_indent) def to_s(need_convert=true, indent=calc_indent)

View file

@ -6,16 +6,14 @@ module RSS
class Channel class Channel
%w(generator ttl).each do |name| [
install_text_element(name) ["generator"],
["ttl", :integer],
].each do |name, type|
install_text_element(name, type)
install_model(name, '?') install_model(name, '?')
end end
remove_method :ttl=
def ttl=(value)
@ttl = value.to_i
end
[ [
%w(category categories), %w(category categories),
].each do |name, plural_name| ].each do |name, plural_name|
@ -126,17 +124,24 @@ EOT
include RSS09 include RSS09
[ [
["isPermaLink", nil, false] ["isPermaLink", nil, false, :boolean]
].each do |name, uri, required| ].each do |name, uri, required, type|
install_get_attribute(name, uri, required) install_get_attribute(name, uri, required, type)
end end
content_setup content_setup
def initialize(isPermaLink=nil, content=nil) def initialize(isPermaLink=nil, content=nil)
super() super()
@isPermaLink = isPermaLink self.isPermaLink = isPermaLink
@content = content self.content = content
end
alias_method :_PermaLink?, :PermaLink?
private :_PermaLink?
def PermaLink?
perma = _PermaLink?
perma or perma.nil?
end end
private private

View file

@ -63,14 +63,20 @@ module RSS
%w(width height).each do |tag| %w(width height).each do |tag|
full_name = "#{IMAGE_PREFIX}_#{tag}" full_name = "#{IMAGE_PREFIX}_#{tag}"
install_text_element(full_name) disp_name = "#{IMAGE_PREFIX}:#{tag}"
install_text_element(full_name, :integer, disp_name)
BaseListener.install_get_text_element(IMAGE_URI, tag, "#{full_name}=") BaseListener.install_get_text_element(IMAGE_URI, tag, "#{full_name}=")
end end
alias width= image_width=
alias width image_width
alias height= image_height=
alias height image_height
def initialize(about=nil, resource=nil) def initialize(about=nil, resource=nil)
super() super()
@about = about self.about = about
@resource = resource self.resource = resource
end end
def full_name def full_name
@ -87,29 +93,6 @@ module RSS
rv rv
end end
alias _image_width= image_width=
def image_width=(new_value)
if @do_validate
self._image_width = Integer(new_value)
else
self._image_width = new_value.to_i
end
end
alias _image_height= image_height=
def image_height=(new_value)
if @do_validate
self._image_height = Integer(new_value)
else
self._image_height = new_value.to_i
end
end
alias width= image_width=
alias width image_width
alias height= image_height=
alias height image_height
private private
def _tags def _tags
[ [
@ -177,13 +160,27 @@ module RSS
install_get_attribute(name, uri, required) install_get_attribute(name, uri, required)
end end
AVAILABLE_SIZES = %w(small medium large)
alias_method :_size=, :size=
private :_size=
def size=(new_value)
if @do_validate and !new_value.nil?
new_value = new_value.strip
unless AVAILABLE_SIZES.include?(new_value)
attr_name = "#{IMAGE_PREFIX}:size"
raise NotAvailableValueError.new(full_name, new_value, attr_name)
end
end
funcall(:_size=, new_value)
end
alias image_size= size= alias image_size= size=
alias image_size size alias image_size size
def initialize(about=nil, size=nil) def initialize(about=nil, size=nil)
super() super()
@about = about self.about = about
@size = size self.size = size
end end
def full_name def full_name

View file

@ -117,10 +117,13 @@ module RSS
end end
class NotAvailableValueError < InvalidRSSError class NotAvailableValueError < InvalidRSSError
attr_reader :tag, :value attr_reader :tag, :value, :attribute
def initialize(tag, value) def initialize(tag, value, attribute=nil)
@tag, @value = tag, value @tag, @value, @attribute = tag, value, attribute
super("value <#{value}> of tag <#{tag}> is not available.") message = "value <#{value}> of "
message << "attribute <#{attribute}> of " if attribute
message << "tag <#{tag}> is not available."
super(message)
end end
end end
@ -192,11 +195,11 @@ EOC
end end
end end
def install_text_element(name) def install_text_element(name, type=nil, disp_name=name)
self::ELEMENTS << name self::ELEMENTS << name
add_need_initialize_variable(name) add_need_initialize_variable(name)
attr_writer name def_corresponded_attr_writer name, type, disp_name
convert_attr_reader name convert_attr_reader name
install_element(name) do |n, elem_name| install_element(name) do |n, elem_name|
<<-EOC <<-EOC
@ -306,6 +309,68 @@ EOC
EOC EOC
end end
def integer_writer(name, disp_name=name)
module_eval(<<-EOC, *get_file_and_line_from_caller(2))
def #{name}=(new_value)
if new_value.nil?
@#{name} = new_value
else
if @do_validate
begin
@#{name} = Integer(new_value)
rescue ArgumentError
raise NotAvailableValueError.new('#{disp_name}', new_value)
end
else
@#{name} = new_value.to_i
end
end
end
EOC
end
def positive_integer_writer(name, disp_name=name)
module_eval(<<-EOC, *get_file_and_line_from_caller(2))
def #{name}=(new_value)
if new_value.nil?
@#{name} = new_value
else
if @do_validate
begin
tmp = Integer(new_value)
raise ArgumentError if tmp <= 0
@#{name} = tmp
rescue ArgumentError
raise NotAvailableValueError.new('#{disp_name}', new_value)
end
else
@#{name} = new_value.to_i
end
end
end
EOC
end
def boolean_writer(name, disp_name=name)
module_eval(<<-EOC, *get_file_and_line_from_caller(2))
def #{name}=(new_value)
if new_value.nil?
@#{name} = new_value
else
if @do_validate and
![true, false, "true", "false"].include?(new_value)
raise NotAvailableValueError.new('#{disp_name}', new_value)
end
if [true, false].include?(new_value)
@#{name} = new_value
else
@#{name} = new_value == "true"
end
end
end
EOC
end
def def_children_accessor(accessor_name, plural_name) def def_children_accessor(accessor_name, plural_name)
module_eval(<<-EOC, *get_file_and_line_from_caller(2)) module_eval(<<-EOC, *get_file_and_line_from_caller(2))
def #{plural_name} def #{plural_name}
@ -437,14 +502,31 @@ EOC
end end
end end
def self.install_get_attribute(name, uri, required=true) def self.install_get_attribute(name, uri, required=true,
attr_writer name type=nil, disp_name=name)
def_corresponded_attr_writer name, type, disp_name
convert_attr_reader name convert_attr_reader name
if type == :boolean and /^is/ =~ name
alias_method "\#{$POSTMATCH}?", name
end
GET_ATTRIBUTES << [name, uri, required] GET_ATTRIBUTES << [name, uri, required]
end end
def self.content_setup def self.def_corresponded_attr_writer(name, type=nil, disp_name=name)
attr_writer :content case type
when :integer
integer_writer name, disp_name
when :positive_integer
positive_integer_writer name, disp_name
when :boolean
boolean_writer name, disp_name
else
attr_writer name
end
end
def self.content_setup(type=nil)
def_corresponded_attr_writer "content", type
convert_attr_reader :content convert_attr_reader :content
def_content_only_to_s def_content_only_to_s
@have_content = true @have_content = true

View file

@ -17,8 +17,12 @@ module RSS
super super
klass.module_eval(<<-EOC, *get_file_and_line_from_caller(1)) klass.module_eval(<<-EOC, *get_file_and_line_from_caller(1))
%w(updatePeriod updateFrequency).each do |name| [
install_text_element("\#{SY_PREFIX}_\#{name}") ["updatePeriod"],
["updateFrequency", :positive_integer]
].each do |name, type|
install_text_element("\#{SY_PREFIX}_\#{name}", type,
"\#{SY_PREFIX}:\#{name}")
end end
%w(updateBase).each do |name| %w(updateBase).each do |name|
@ -31,12 +35,6 @@ module RSS
validate_sy_updatePeriod(new_value) if @do_validate validate_sy_updatePeriod(new_value) if @do_validate
self._sy_updatePeriod = new_value self._sy_updatePeriod = new_value
end end
alias_method(:_sy_updateFrequency=, :sy_updateFrequency=)
def sy_updateFrequency=(new_value)
validate_sy_updateFrequency(new_value) if @do_validate
self._sy_updateFrequency = new_value.to_i
end
EOC EOC
end end
@ -61,15 +59,6 @@ module RSS
raise NotAvailableValueError.new("updatePeriod", value) raise NotAvailableValueError.new("updatePeriod", value)
end end
end end
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
end
end end
class RDF class RDF

View file

@ -83,7 +83,7 @@ module RSS
end end
end end
def assert_not_available_value(tag, value) def assert_not_available_value(tag, value, attribute=nil)
_wrap_assertion do _wrap_assertion do
begin begin
yield yield
@ -91,6 +91,7 @@ module RSS
rescue ::RSS::NotAvailableValueError => e rescue ::RSS::NotAvailableValueError => e
assert_equal(tag, e.tag) assert_equal(tag, e.tag)
assert_equal(value, e.value) assert_equal(value, e.value)
assert_equal(attribute, e.attribute)
end end
end end
end end
@ -256,14 +257,16 @@ module RSS
_wrap_assertion do _wrap_assertion do
hours = skipHours.hours hours = skipHours.hours
contents.each_with_index do |content, i| contents.each_with_index do |content, i|
assert_equal(content, hours[i].content) assert_equal(content.to_i, hours[i].content)
end end
end end
end end
def assert_image09(attrs, image) def assert_image09(attrs, image)
_wrap_assertion do _wrap_assertion do
names = %w(url link title description width height) names = %w(url link title description)
names << ["width", :integer]
names << ["height", :integer]
assert_attributes(attrs, names, image) assert_attributes(attrs, names, image)
end end
end end
@ -291,7 +294,8 @@ module RSS
names = %w(title link description language copyright names = %w(title link description language copyright
managingEditor webMaster pubDate managingEditor webMaster pubDate
lastBuildDate generator docs ttl rating) lastBuildDate generator docs rating)
names << ["ttl", :integer]
assert_attributes(attrs, names, channel) assert_attributes(attrs, names, channel)
%w(cloud categories skipHours skipDays).each do |name| %w(cloud categories skipHours skipDays).each do |name|
@ -314,7 +318,8 @@ module RSS
def assert_channel20_cloud(attrs, cloud) def assert_channel20_cloud(attrs, cloud)
_wrap_assertion do _wrap_assertion do
names = %w(domain port path registerProcedure protocol) names = %w(domain path registerProcedure protocol)
names << ["port", :integer]
assert_attributes(attrs, names, cloud) assert_attributes(attrs, names, cloud)
end end
end end
@ -330,7 +335,9 @@ module RSS
def assert_image20(attrs, image) def assert_image20(attrs, image)
_wrap_assertion do _wrap_assertion do
names = %w(url link title description width height) names = %w(url link title description)
names << ["width", :integer]
names << ["height", :integer]
assert_attributes(attrs, names, image) assert_attributes(attrs, names, image)
end end
end end
@ -362,7 +369,7 @@ module RSS
def assert_items20_enclosure(attrs, enclosure) def assert_items20_enclosure(attrs, enclosure)
_wrap_assertion do _wrap_assertion do
names = %w(url length type) names = ["url", ["length", :integer], "type"]
assert_attributes(attrs, names, enclosure) assert_attributes(attrs, names, enclosure)
end end
end end
@ -375,7 +382,8 @@ module RSS
def assert_items20_guid(attrs, guid) def assert_items20_guid(attrs, guid)
_wrap_assertion do _wrap_assertion do
assert_attributes(attrs, %w(isPermaLink content), guid) names = [["isPermaLink", :boolean], ["content"]]
assert_attributes(attrs, names, guid)
end end
end end
@ -408,7 +416,9 @@ module RSS
def assert_syndication(elems, target) def assert_syndication(elems, target)
_wrap_assertion do _wrap_assertion do
elems.each do |name, value| elems.each do |name, value|
assert_equal(value, target.__send__("sy_#{name}")) meth = "sy_#{name}"
value = value.to_i if meth == "sy_updateFrequency"
assert_equal(value, target.__send__(meth ))
end end
end end
end end
@ -458,13 +468,25 @@ module RSS
def assert_attributes(attrs, names, target) def assert_attributes(attrs, names, target)
_wrap_assertion do _wrap_assertion do
n_attrs = normalized_attrs(attrs) n_attrs = normalized_attrs(attrs)
names.each do |name| names.each do |info|
if info.is_a?(String)
name = info
type = nil
else
name, type = info
end
value = n_attrs[name] value = n_attrs[name]
if value.is_a?(Time) if value.is_a?(Time)
actual = target.__send__(name) actual = target.__send__(name)
assert_instance_of(Time, actual) assert_instance_of(Time, actual)
assert_equal(value.to_i, actual.to_i) assert_equal(value.to_i, actual.to_i)
elsif value elsif value
case type
when :integer
value = value.to_i
when :boolean
value = value == "true" if value.is_a?(String)
end
assert_equal(value, target.__send__(name)) assert_equal(value, target.__send__(name))
end end
end end

View file

@ -75,9 +75,9 @@ module RSS
generator = "MightyInHouse Content System v2.3" generator = "MightyInHouse Content System v2.3"
docs = "http://blogs.law.harvard.edu/tech/rss" docs = "http://blogs.law.harvard.edu/tech/rss"
ttl = 60 ttl = "60"
rating = 6 rating = '(PICS-1.1 "http://www.rsac.org/ratingsv01.html" l gen true comment "RSACi North America Server" for "http://www.rsac.org" on "1996.04.16T08:15-0500" r (n 0 s 0 v 0 l 0))'
channel = Rss::Channel.new channel = Rss::Channel.new
@ -85,7 +85,9 @@ module RSS
managingEditor webMaster pubDate lastBuildDate managingEditor webMaster pubDate lastBuildDate
generator docs ttl rating) generator docs ttl rating)
elems.each do |x| elems.each do |x|
channel.__send__("#{x}=", instance_eval(x)) value = instance_eval(x)
value = value.rfc822 if %w(pubDate lastBuildDate).include?(x)
channel.__send__("#{x}=", value)
end end
categories.each do |cat| categories.each do |cat|
channel.categories << Rss::Channel::Category.new(cat[:domain], channel.categories << Rss::Channel::Category.new(cat[:domain],
@ -103,7 +105,8 @@ module RSS
case x case x
when "pubDate", "lastBuildDate" when "pubDate", "lastBuildDate"
assert_equal(expected, Time.parse(elem.text)) assert_equal(expected, Time.parse(elem.text))
when "ttl", "rating" when "ttl"
expected = channel.__send__(x)
assert_equal(expected, elem.text.to_i) assert_equal(expected, elem.text.to_i)
else else
assert_equal(expected, elem.text) assert_equal(expected, elem.text)
@ -124,7 +127,7 @@ module RSS
def test_channel_cloud def test_channel_cloud
cloud_params = { cloud_params = {
:domain => "rpc.sys.com", :domain => "rpc.sys.com",
:port => 80, :port => "80",
:path => "/RPC2", :path => "/RPC2",
:registerProcedure => "myCloud.rssPleaseNotify", :registerProcedure => "myCloud.rssPleaseNotify",
:protocol => "xml-rpc", :protocol => "xml-rpc",
@ -134,7 +137,8 @@ module RSS
cloud_params[:path], cloud_params[:path],
cloud_params[:registerProcedure], cloud_params[:registerProcedure],
cloud_params[:protocol]) cloud_params[:protocol])
cloud_params[:port] = cloud.port
doc = REXML::Document.new(cloud.to_s) doc = REXML::Document.new(cloud.to_s)
cloud_elem = doc.root cloud_elem = doc.root
@ -151,8 +155,8 @@ module RSS
:url => "http://hoge.com/hoge.png", :url => "http://hoge.com/hoge.png",
:title => "fugafuga", :title => "fugafuga",
:link => "http://hoge.com", :link => "http://hoge.com",
:width => 144, :width => "144",
:height => 400, :height => "400",
:description => "an image", :description => "an image",
} }
image = Rss::Channel::Image.new(image_params[:url], image = Rss::Channel::Image.new(image_params[:url],
@ -166,6 +170,7 @@ module RSS
image_elem = doc.root image_elem = doc.root
image_params.each do |name, value| image_params.each do |name, value|
value = image.__send__(name)
actual = image_elem.elements[name.to_s].text actual = image_elem.elements[name.to_s].text
actual = actual.to_i if [:width, :height].include?(name) actual = actual.to_i if [:width, :height].include?(name)
assert_equal(value, actual) assert_equal(value, actual)
@ -213,8 +218,8 @@ module RSS
def test_channel_skip_hours def test_channel_skip_hours
skipHours_values = [ skipHours_values = [
0, "0",
13, "13",
] ]
skipHours = Rss::Channel::SkipHours.new skipHours = Rss::Channel::SkipHours.new
skipHours_values.each do |value| skipHours_values.each do |value|
@ -225,7 +230,8 @@ module RSS
hours_elem = doc.root hours_elem = doc.root
skipHours_values.each_with_index do |value, i| skipHours_values.each_with_index do |value, i|
assert_equal(value, hours_elem.elements[i + 1].text.to_i) expected = skipHours.hours[i].content
assert_equal(expected, hours_elem.elements[i + 1].text.to_i)
end end
end end
@ -252,7 +258,9 @@ module RSS
elems = %w(title link description author comments pubDate) elems = %w(title link description author comments pubDate)
elems.each do |x| elems.each do |x|
item.__send__("#{x}=", instance_eval(x)) value = instance_eval(x)
value = value.rfc822 if x == "pubDate"
item.__send__("#{x}=", value)
end end
categories.each do |cat| categories.each do |cat|
item.categories << Rss::Channel::Category.new(cat[:domain], item.categories << Rss::Channel::Category.new(cat[:domain],
@ -290,23 +298,21 @@ module RSS
def test_item_enclosure def test_item_enclosure
enclosure_params = { enclosure_params = {
:url => "http://www.scripting.com/mp3s/weatherReportSuite.mp3", :url => "http://www.scripting.com/mp3s/weatherReportSuite.mp3",
:length => 12216320, :length => "12216320",
:type => "audio/mpeg", :type => "audio/mpeg",
} }
enclosure = Rss::Channel::Item::Enclosure.new(enclosure_params[:url], enclosure = Rss::Channel::Item::Enclosure.new(enclosure_params[:url],
enclosure_params[:length], enclosure_params[:length],
enclosure_params[:type]) enclosure_params[:type])
enclosure_params[:length] = enclosure.length
doc = REXML::Document.new(enclosure.to_s) doc = REXML::Document.new(enclosure.to_s)
enclosure_elem = doc.root enclosure_elem = doc.root
actual = {} actual = {}
enclosure_elem.attributes.each do |name, value| enclosure_elem.attributes.each do |name, value|
if name == "length" value = value.to_i if name == "length"
enclosure_params[name.to_sym] = value.to_i
value = value.to_i
end
actual[name.to_sym] = value actual[name.to_sym] = value
end end
assert_equal(enclosure_params, actual) assert_equal(enclosure_params, actual)
@ -326,13 +332,22 @@ module RSS
test_params.each do |guid_params| test_params.each do |guid_params|
guid = Rss::Channel::Item::Guid.new(guid_params[:isPermaLink], guid = Rss::Channel::Item::Guid.new(guid_params[:isPermaLink],
guid_params[:content]) guid_params[:content])
if guid_params.has_key?(:isPermaLink)
guid_params[:isPermaLink] = guid.isPermaLink
end
if guid.isPermaLink.nil?
assert_equal(true, guid.PermaLink?)
else
assert_equal(guid.isPermaLink, guid.PermaLink?)
end
doc = REXML::Document.new(guid.to_s) doc = REXML::Document.new(guid.to_s)
guid_elem = doc.root guid_elem = doc.root
actual = {} actual = {}
actual[:content] = guid_elem.text if guid_elem.text actual[:content] = guid_elem.text if guid_elem.text
guid_elem.attributes.each do |name, value| guid_elem.attributes.each do |name, value|
value = value == "true" if name == "isPermaLink"
actual[name.to_sym] = value actual[name.to_sym] = value
end end
assert_equal(guid_params, actual) assert_equal(guid_params, actual)

View file

@ -2,13 +2,13 @@ require "rss-testcase"
require "rss/1.0" require "rss/1.0"
require "rss/2.0" require "rss/2.0"
require "rss/syndication"
require "rss/image"
module RSS module RSS
class TestAccessor < TestCase class TestAccessor < TestCase
def test_date def test_date
channel = Rss::Channel.new channel = Rss::Channel.new
channel.do_validate = false
channel.pubDate = nil channel.pubDate = nil
assert_nil(channel.pubDate) assert_nil(channel.pubDate)
@ -16,9 +16,88 @@ module RSS
channel.pubDate = time channel.pubDate = time
assert_equal(time, channel.pubDate) assert_equal(time, channel.pubDate)
time = Time.parse(Time.now.rfc822)
channel.pubDate = time.rfc822
assert_equal(time, channel.pubDate)
time = Time.parse(Time.now.iso8601)
value = time.iso8601
assert_not_available_value("pubDate", value) do
channel.pubDate = value
end
channel.do_validate = false
time = Time.parse(Time.now.iso8601)
value = time.iso8601
channel.pubDate = value
assert_equal(time, channel.pubDate)
channel.pubDate = nil channel.pubDate = nil
assert_nil(channel.pubDate) assert_nil(channel.pubDate)
end end
def test_integer
image_item = RDF::Item::ImageItem.new
image_item.width = nil
assert_nil(image_item.width)
width = 10
image_item.width = width
assert_equal(width, image_item.width)
width = 10.0
image_item.width = width
assert_equal(width, image_item.width)
width = "10"
image_item.width = width
assert_equal(width.to_i, image_item.width)
width = "10.0"
assert_not_available_value("image:width", width) do
image_item.width = width
end
image_item.do_validate = false
width = "10.0"
image_item.width = width
assert_equal(width.to_i, image_item.width)
image_item.width = nil
assert_nil(image_item.width)
end
def test_positive_integer
channel = RDF::Channel.new
channel.sy_updateFrequency = nil
assert_nil(channel.sy_updateFrequency)
freq = 10
channel.sy_updateFrequency = freq
assert_equal(freq, channel.sy_updateFrequency)
freq = 10.0
channel.sy_updateFrequency = freq
assert_equal(freq, channel.sy_updateFrequency)
freq = "10"
channel.sy_updateFrequency = freq
assert_equal(freq.to_i, channel.sy_updateFrequency)
freq = "10.0"
assert_not_available_value("sy:updateFrequency", freq) do
channel.sy_updateFrequency = freq
end
channel.do_validate = false
freq = "10.0"
channel.sy_updateFrequency = freq
assert_equal(freq.to_i, channel.sy_updateFrequency)
channel.sy_updateFrequency = nil
assert_nil(channel.sy_updateFrequency)
end
end end
end end

View file

@ -26,8 +26,8 @@ module RSS
}, },
{ {
"dc:title" => "Example Image", "dc:title" => "Example Image",
"#{@prefix}:width" => 100, "#{@prefix}:width" => "100",
"#{@prefix}:height" => 65, "#{@prefix}:height" => "65",
}, },
], ],
[ [
@ -36,8 +36,8 @@ module RSS
}, },
{ {
"dc:title" => "Culture", "dc:title" => "Culture",
"#{@prefix}:width" => 80, "#{@prefix}:width" => "80",
"#{@prefix}:height" => 50, "#{@prefix}:height" => "50",
}, },
] ]
] ]
@ -93,6 +93,23 @@ EOR
assert_equal(@favicon_attrs[full_name], favicon.__send__(name)) assert_equal(@favicon_attrs[full_name], favicon.__send__(name))
end end
%w(small medium large).each do |value|
assert_nothing_raised do
favicon.size = value
favicon.image_size = value
end
end
%w(aaa AAA SMALL MEDIUM LARGE).each do |value|
args = ["#{@prefix}:favicon", value, "#{@prefix}:size"]
assert_not_available_value(*args) do
favicon.size = value
end
assert_not_available_value(*args) do
favicon.image_size = value
end
end
[ [
%w(dc_title dc:title sample-favicon), %w(dc_title dc:title sample-favicon),
].each do |name, full_name, new_value| ].each do |name, full_name, new_value|
@ -120,10 +137,19 @@ EOR
end end
[ [
["width", "image:width", 111], ["width", "image:width", "111"],
["image_width", "image:width", 44], ["image_width", "image:width", "44"],
["height", "image:height", 222], ["height", "image:height", "222"],
["image_height", "image:height", 88], ["image_height", "image:height", "88"],
].each do |name, full_name, new_value|
assert_equal(contents[full_name].to_i, image_item.__send__(name))
image_item.__send__("#{name}=", new_value)
assert_equal(new_value.to_i, image_item.__send__(name))
image_item.__send__("#{name}=", contents[full_name])
assert_equal(contents[full_name].to_i, image_item.__send__(name))
end
[
["dc_title", "dc:title", "sample-image"], ["dc_title", "dc:title", "sample-image"],
].each do |name, full_name, new_value| ].each do |name, full_name, new_value|
assert_equal(contents[full_name], image_item.__send__(name)) assert_equal(contents[full_name], image_item.__send__(name))

View file

@ -55,15 +55,15 @@ module RSS
copyright = "foo" copyright = "foo"
managingEditor = "bar" managingEditor = "bar"
webMaster = "web master" webMaster = "web master"
rating = "6" rating = '(PICS-1.1 "http://www.rsac.org/ratingsv01.html" l gen true comment "RSACi North America Server" for "http://www.rsac.org" on "1996.04.16T08:15-0500" r (n 0 s 0 v 0 l 0))'
docs = "http://foo.com/doc" docs = "http://foo.com/doc"
skipDays = [ skipDays = [
"Sunday", "Sunday",
"Monday", "Monday",
] ]
skipHours = [ skipHours = [
0, "0",
13, "13",
] ]
pubDate = Time.now pubDate = Time.now
lastBuildDate = Time.now lastBuildDate = Time.now
@ -109,7 +109,7 @@ module RSS
assert_equal(day, channel.skipDays.days[i].content) assert_equal(day, channel.skipDays.days[i].content)
end end
skipHours.each_with_index do |hour, i| skipHours.each_with_index do |hour, i|
assert_equal(hour, channel.skipHours.hours[i].content) assert_equal(hour.to_i, channel.skipHours.hours[i].content)
end end
assert(channel.items.empty?) assert(channel.items.empty?)
@ -165,8 +165,8 @@ module RSS
title = "fugafuga" title = "fugafuga"
link = "http://hoge.com" link = "http://hoge.com"
url = "http://hoge.com/hoge.png" url = "http://hoge.com/hoge.png"
width = 144 width = "144"
height = 400 height = "400"
description = "an image" description = "an image"
rss = RSS::Maker.make("0.91") do |maker| rss = RSS::Maker.make("0.91") do |maker|
@ -183,8 +183,8 @@ module RSS
assert_equal(title, image.title) assert_equal(title, image.title)
assert_equal(link, image.link) assert_equal(link, image.link)
assert_equal(url, image.url) assert_equal(url, image.url)
assert_equal(width, image.width) assert_equal(width.to_i, image.width)
assert_equal(height, image.height) assert_equal(height.to_i, image.height)
assert_equal(description, image.description) assert_equal(description, image.description)
assert_not_set_error("maker.channel", %w(description title language)) do assert_not_set_error("maker.channel", %w(description title language)) do
@ -205,8 +205,8 @@ module RSS
title = "fugafuga" title = "fugafuga"
link = "http://hoge.com" link = "http://hoge.com"
url = "http://hoge.com/hoge.png" url = "http://hoge.com/hoge.png"
width = 144 width = "144"
height = 400 height = "400"
description = "an image" description = "an image"
rss = RSS::Maker.make("0.91") do |maker| rss = RSS::Maker.make("0.91") do |maker|

View file

@ -55,7 +55,7 @@ module RSS
assert_equal(title, channel.title) assert_equal(title, channel.title)
assert_equal(link, channel.link) assert_equal(link, channel.link)
assert_equal(description, channel.description) assert_equal(description, channel.description)
assert_equal(true, channel.items.Seq.lis.empty?) assert(channel.items.Seq.lis.empty?)
assert_nil(channel.image) assert_nil(channel.image)
assert_nil(channel.textinput) assert_nil(channel.textinput)

View file

@ -49,15 +49,15 @@ module RSS
copyright = "foo" copyright = "foo"
managingEditor = "bar" managingEditor = "bar"
webMaster = "web master" webMaster = "web master"
rating = "6" rating = '(PICS-1.1 "http://www.rsac.org/ratingsv01.html" l gen true comment "RSACi North America Server" for "http://www.rsac.org" on "1996.04.16T08:15-0500" r (n 0 s 0 v 0 l 0))'
docs = "http://foo.com/doc" docs = "http://foo.com/doc"
skipDays = [ skipDays = [
"Sunday", "Sunday",
"Monday", "Monday",
] ]
skipHours = [ skipHours = [
0, "0",
13, "13",
] ]
pubDate = Time.now pubDate = Time.now
lastBuildDate = Time.now lastBuildDate = Time.now
@ -66,7 +66,7 @@ module RSS
"misc", "misc",
] ]
generator = "RSS Maker" generator = "RSS Maker"
ttl = 60 ttl = "60"
rss = RSS::Maker.make("2.0") do |maker| rss = RSS::Maker.make("2.0") do |maker|
maker.channel.title = title maker.channel.title = title
@ -117,7 +117,7 @@ module RSS
assert_equal(day, channel.skipDays.days[i].content) assert_equal(day, channel.skipDays.days[i].content)
end end
skipHours.each_with_index do |hour, i| skipHours.each_with_index do |hour, i|
assert_equal(hour, channel.skipHours.hours[i].content) assert_equal(hour.to_i, channel.skipHours.hours[i].content)
end end
channel.categories.each_with_index do |category, i| channel.categories.each_with_index do |category, i|
@ -125,7 +125,7 @@ module RSS
end end
assert_equal(generator, channel.generator) assert_equal(generator, channel.generator)
assert_equal(ttl, channel.ttl) assert_equal(ttl.to_i, channel.ttl)
assert(channel.items.empty?) assert(channel.items.empty?)
assert_nil(channel.image) assert_nil(channel.image)
@ -193,7 +193,7 @@ module RSS
end end
cloud = rss.channel.cloud cloud = rss.channel.cloud
assert_equal(domain, cloud.domain) assert_equal(domain, cloud.domain)
assert_equal(port, cloud.port) assert_equal(port.to_i, cloud.port)
assert_equal(path, cloud.path) assert_equal(path, cloud.path)
assert_equal(registerProcedure, cloud.registerProcedure) assert_equal(registerProcedure, cloud.registerProcedure)
assert_equal(protocol, cloud.protocol) assert_equal(protocol, cloud.protocol)
@ -267,8 +267,8 @@ module RSS
title = "fugafuga" title = "fugafuga"
link = "http://hoge.com" link = "http://hoge.com"
url = "http://hoge.com/hoge.png" url = "http://hoge.com/hoge.png"
width = 144 width = "144"
height = 400 height = "400"
description = "an image" description = "an image"
rss = RSS::Maker.make("2.0") do |maker| rss = RSS::Maker.make("2.0") do |maker|
@ -285,8 +285,8 @@ module RSS
assert_equal(title, image.title) assert_equal(title, image.title)
assert_equal(link, image.link) assert_equal(link, image.link)
assert_equal(url, image.url) assert_equal(url, image.url)
assert_equal(width, image.width) assert_equal(width.to_i, image.width)
assert_equal(height, image.height) assert_equal(height.to_i, image.height)
assert_equal(description, image.description) assert_equal(description, image.description)
assert_not_set_error("maker.channel", %w(title description)) do assert_not_set_error("maker.channel", %w(title description)) do
@ -307,8 +307,8 @@ module RSS
title = "fugafuga" title = "fugafuga"
link = "http://hoge.com" link = "http://hoge.com"
url = "http://hoge.com/hoge.png" url = "http://hoge.com/hoge.png"
width = 144 width = "144"
height = 400 height = "400"
description = "an image" description = "an image"
rss = RSS::Maker.make("2.0") do |maker| rss = RSS::Maker.make("2.0") do |maker|
@ -418,7 +418,7 @@ module RSS
end end
def test_guid def test_guid
isPermaLink = true isPermaLink = "true"
content = "http://inessential.com/2002/09/01.php#a2" content = "http://inessential.com/2002/09/01.php#a2"
rss = RSS::Maker.make("2.0") do |maker| rss = RSS::Maker.make("2.0") do |maker|
@ -430,7 +430,7 @@ module RSS
guid.content = content guid.content = content
end end
guid = rss.channel.items.last.guid guid = rss.channel.items.last.guid
assert_equal(isPermaLink, guid.isPermaLink) assert_equal(isPermaLink == "true", guid.isPermaLink)
assert_equal(content, guid.content) assert_equal(content, guid.content)
end end
@ -463,7 +463,7 @@ module RSS
end end
enclosure = rss.channel.items.last.enclosure enclosure = rss.channel.items.last.enclosure
assert_equal(url, enclosure.url) assert_equal(url, enclosure.url)
assert_equal(length, enclosure.length) assert_equal(length.to_i, enclosure.length)
assert_equal(type, enclosure.type) assert_equal(type, enclosure.type)
end end

View file

@ -17,8 +17,8 @@ module RSS
"about" => "http://www.example.org/item.png", "about" => "http://www.example.org/item.png",
"resource" => "http://www.example.org/item", "resource" => "http://www.example.org/item",
"dc_title" => "Example Image", "dc_title" => "Example Image",
"image_width" => 100, "image_width" => "100",
"image_height" => 65, "image_height" => "65",
} }
end end
@ -53,8 +53,8 @@ module RSS
item = target.items.last.image_item item = target.items.last.image_item
assert_equal(@item_infos["about"], item.about) assert_equal(@item_infos["about"], item.about)
assert_equal(@item_infos["resource"], item.resource) assert_equal(@item_infos["resource"], item.resource)
assert_equal(@item_infos["image_width"], item.image_width) assert_equal(@item_infos["image_width"].to_i, item.image_width)
assert_equal(@item_infos["image_height"], item.image_height) assert_equal(@item_infos["image_height"].to_i, item.image_height)
assert_equal(@item_infos["dc_title"], item.dc_title) assert_equal(@item_infos["dc_title"], item.dc_title)
end end
end end

View file

@ -15,7 +15,7 @@ module RSS
@elements = { @elements = {
:updatePeriod => "hourly", :updatePeriod => "hourly",
:updateFrequency => 2, :updateFrequency => "2",
:updateBase => t, :updateBase => t,
} }
end end

View file

@ -13,15 +13,15 @@ module RSS
copyright = "foo" copyright = "foo"
managingEditor = "bar" managingEditor = "bar"
webMaster = "web master" webMaster = "web master"
rating = "6" rating = '(PICS-1.1 "http://www.rsac.org/ratingsv01.html" l gen true comment "RSACi North America Server" for "http://www.rsac.org" on "1996.04.16T08:15-0500" r (n 0 s 0 v 0 l 0))'
docs = "http://foo.com/doc" docs = "http://foo.com/doc"
skipDays = [ skipDays = [
"Sunday", "Sunday",
"Monday", "Monday",
] ]
skipHours = [ skipHours = [
0, "0",
13, "13",
] ]
pubDate = Time.now pubDate = Time.now
lastBuildDate = Time.now lastBuildDate = Time.now
@ -70,7 +70,7 @@ module RSS
assert_equal(day, channel.skipDays.days[i].content) assert_equal(day, channel.skipDays.days[i].content)
end end
skipHours.each_with_index do |hour, i| skipHours.each_with_index do |hour, i|
assert_equal(hour, channel.skipHours.hours[i].content) assert_equal(hour.to_i, channel.skipHours.hours[i].content)
end end
assert(channel.items.empty?) assert(channel.items.empty?)
@ -82,8 +82,8 @@ module RSS
title = "fugafuga" title = "fugafuga"
link = "http://hoge.com" link = "http://hoge.com"
url = "http://hoge.com/hoge.png" url = "http://hoge.com/hoge.png"
width = 144 width = "144"
height = 400 height = "400"
description = "an image" description = "an image"
rss = RSS::Maker.make("0.91") do |maker| rss = RSS::Maker.make("0.91") do |maker|
@ -106,8 +106,8 @@ module RSS
assert_equal(title, image.title) assert_equal(title, image.title)
assert_equal(link, image.link) assert_equal(link, image.link)
assert_equal(url, image.url) assert_equal(url, image.url)
assert_equal(width, image.width) assert_equal(width.to_i, image.width)
assert_equal(height, image.height) assert_equal(height.to_i, image.height)
assert_equal(description, image.description) assert_equal(description, image.description)
end end

View file

@ -32,7 +32,7 @@ module RSS
@sy_elems = { @sy_elems = {
:updatePeriod => "hourly", :updatePeriod => "hourly",
:updateFrequency => 2, :updateFrequency => "2",
:updateBase => t, :updateBase => t,
} }
@ -107,6 +107,7 @@ module RSS
end end
@sy_elems.each do |var, value| @sy_elems.each do |var, value|
value = value.to_i if var == :updateFrequency
assert_equal(value, channel.__send__("sy_#{var}")) assert_equal(value, channel.__send__("sy_#{var}"))
end end
@ -473,6 +474,7 @@ module RSS
assert_equal(value, channel.__send__("dc_#{var}")) assert_equal(value, channel.__send__("dc_#{var}"))
end end
@sy_elems.each do |var, value| @sy_elems.each do |var, value|
value = value.to_i if var == :updateFrequency
assert_equal(value, channel.__send__("sy_#{var}")) assert_equal(value, channel.__send__("sy_#{var}"))
end end

View file

@ -13,15 +13,15 @@ module RSS
copyright = "foo" copyright = "foo"
managingEditor = "bar" managingEditor = "bar"
webMaster = "web master" webMaster = "web master"
rating = "6" rating = '(PICS-1.1 "http://www.rsac.org/ratingsv01.html" l gen true comment "RSACi North America Server" for "http://www.rsac.org" on "1996.04.16T08:15-0500" r (n 0 s 0 v 0 l 0))'
docs = "http://foo.com/doc" docs = "http://foo.com/doc"
skipDays = [ skipDays = [
"Sunday", "Sunday",
"Monday", "Monday",
] ]
skipHours = [ skipHours = [
0, "0",
13, "13",
] ]
pubDate = Time.now pubDate = Time.now
lastBuildDate = Time.now lastBuildDate = Time.now
@ -30,7 +30,7 @@ module RSS
"misc", "misc",
] ]
generator = "RSS Maker" generator = "RSS Maker"
ttl = 60 ttl = "60"
rss = RSS::Maker.make("2.0") do |maker| rss = RSS::Maker.make("2.0") do |maker|
maker.channel.title = title maker.channel.title = title
@ -85,7 +85,7 @@ module RSS
assert_equal(day, channel.skipDays.days[i].content) assert_equal(day, channel.skipDays.days[i].content)
end end
skipHours.each_with_index do |hour, i| skipHours.each_with_index do |hour, i|
assert_equal(hour, channel.skipHours.hours[i].content) assert_equal(hour.to_i, channel.skipHours.hours[i].content)
end end
@ -94,7 +94,7 @@ module RSS
end end
assert_equal(generator, channel.generator) assert_equal(generator, channel.generator)
assert_equal(ttl, channel.ttl) assert_equal(ttl.to_i, channel.ttl)
assert(channel.items.empty?) assert(channel.items.empty?)
@ -106,8 +106,8 @@ module RSS
title = "fugafuga" title = "fugafuga"
link = "http://hoge.com" link = "http://hoge.com"
url = "http://hoge.com/hoge.png" url = "http://hoge.com/hoge.png"
width = 144 width = "144"
height = 400 height = "400"
description = "an image" description = "an image"
rss = RSS::Maker.make("2.0") do |maker| rss = RSS::Maker.make("2.0") do |maker|
@ -130,8 +130,8 @@ module RSS
assert_equal(title, image.title) assert_equal(title, image.title)
assert_equal(link, image.link) assert_equal(link, image.link)
assert_equal(url, image.url) assert_equal(url, image.url)
assert_equal(width, image.width) assert_equal(width.to_i, image.width)
assert_equal(height, image.height) assert_equal(height.to_i, image.height)
assert_equal(description, image.description) assert_equal(description, image.description)
end end
@ -170,7 +170,7 @@ module RSS
comments = "http://www.myblog.org/cgi-local/mt/mt-comments.cgi?entry_id=290" comments = "http://www.myblog.org/cgi-local/mt/mt-comments.cgi?entry_id=290"
pubDate = Time.now pubDate = Time.now
guid_isPermaLink = true guid_isPermaLink = "true"
guid_content = "http://inessential.com/2002/09/01.php#a2" guid_content = "http://inessential.com/2002/09/01.php#a2"
enclosure_url = "http://www.scripting.com/mp3s/weatherReportSuite.mp3" enclosure_url = "http://www.scripting.com/mp3s/weatherReportSuite.mp3"
@ -234,11 +234,11 @@ module RSS
assert_equal("#{comments}#{i}", item.comments) assert_equal("#{comments}#{i}", item.comments)
assert_equal(pubDate, item.pubDate) assert_equal(pubDate, item.pubDate)
assert_equal(guid_isPermaLink, item.guid.isPermaLink) assert_equal(guid_isPermaLink == "true", item.guid.isPermaLink)
assert_equal(guid_content, item.guid.content) assert_equal(guid_content, item.guid.content)
assert_equal(enclosure_url, item.enclosure.url) assert_equal(enclosure_url, item.enclosure.url)
assert_equal(enclosure_length, item.enclosure.length) assert_equal(enclosure_length.to_i, item.enclosure.length)
assert_equal(enclosure_type, item.enclosure.type) assert_equal(enclosure_type, item.enclosure.type)
assert_equal(source_url, item.source.url) assert_equal(source_url, item.source.url)

View file

@ -22,7 +22,7 @@ module RSS
@elems = { @elems = {
:updatePeriod => "hourly", :updatePeriod => "hourly",
:updateFrequency => 2, :updateFrequency => "2",
:updateBase => t, :updateBase => t,
} }
@ -68,16 +68,18 @@ EOR
new_value = { new_value = {
:updatePeriod => "daily", :updatePeriod => "daily",
:updateFrequency => +11, :updateFrequency => "11",
:updateBase => t, :updateBase => t,
} }
@elems.each do |name, value| @elems.each do |name, value|
value = value.to_i if name == :updateFrequency
@parents.each do |parent| @parents.each do |parent|
assert_equal(value, @rss.__send__(parent).funcall("sy_#{name}")) assert_equal(value, @rss.__send__(parent).__send__("sy_#{name}"))
@rss.__send__(parent).funcall("sy_#{name}=", new_value[name].to_s) @rss.__send__(parent).__send__("sy_#{name}=", new_value[name])
assert_equal(new_value[name], new_val = new_value[name]
@rss.__send__(parent).funcall("sy_#{name}")) new_val = new_val.to_i if name == :updateFrequency
assert_equal(new_val, @rss.__send__(parent).__send__("sy_#{name}"))
end end
end end

View file

@ -146,13 +146,13 @@ module RSS
"Friday", "Friday",
], ],
"skipHours" => [ "skipHours" => [
12, "12",
23, "23",
], ],
"date" => Time.now, "date" => Time.now,
"lastBuildDate" => Time.now - 3600, "lastBuildDate" => Time.now - 3600,
"generator" => "RSS Maker", "generator" => "RSS Maker",
"ttl" => 60, "ttl" => "60",
"cloud" => { "cloud" => {
"domain" => "rpc.sys.com", "domain" => "rpc.sys.com",
"port" => "80", "port" => "80",
@ -187,7 +187,7 @@ module RSS
"author" => "foo@example.com", "author" => "foo@example.com",
"comments" => "http://example.com/1/comments", "comments" => "http://example.com/1/comments",
"guid" => { "guid" => {
"isPermaLink" => "ture", "isPermaLink" => "true",
"content" => "http://example.com/1", "content" => "http://example.com/1",
}, },
"enclosure" => { "enclosure" => {
@ -275,7 +275,7 @@ module RSS
def setup_syndication_info def setup_syndication_info
@sy_info = { @sy_info = {
"updatePeriod" => "hourly", "updatePeriod" => "hourly",
"updateFrequency" => 2, "updateFrequency" => "2",
"updateBase" => Time.now - 3600, "updateBase" => Time.now - 3600,
} }
end end