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>
* lib/rss/image.rb: added Image prefix.

View file

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

View file

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

View file

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

View file

@ -63,14 +63,20 @@ module RSS
%w(width height).each do |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}=")
end
alias width= image_width=
alias width image_width
alias height= image_height=
alias height image_height
def initialize(about=nil, resource=nil)
super()
@about = about
@resource = resource
self.about = about
self.resource = resource
end
def full_name
@ -87,29 +93,6 @@ module RSS
rv
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
def _tags
[
@ -177,13 +160,27 @@ module RSS
install_get_attribute(name, uri, required)
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
def initialize(about=nil, size=nil)
super()
@about = about
@size = size
self.about = about
self.size = size
end
def full_name

View file

@ -117,10 +117,13 @@ module RSS
end
class NotAvailableValueError < InvalidRSSError
attr_reader :tag, :value
def initialize(tag, value)
@tag, @value = tag, value
super("value <#{value}> of tag <#{tag}> is not available.")
attr_reader :tag, :value, :attribute
def initialize(tag, value, attribute=nil)
@tag, @value, @attribute = tag, value, attribute
message = "value <#{value}> of "
message << "attribute <#{attribute}> of " if attribute
message << "tag <#{tag}> is not available."
super(message)
end
end
@ -192,11 +195,11 @@ EOC
end
end
def install_text_element(name)
def install_text_element(name, type=nil, disp_name=name)
self::ELEMENTS << name
add_need_initialize_variable(name)
attr_writer name
def_corresponded_attr_writer name, type, disp_name
convert_attr_reader name
install_element(name) do |n, elem_name|
<<-EOC
@ -306,6 +309,68 @@ EOC
EOC
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)
module_eval(<<-EOC, *get_file_and_line_from_caller(2))
def #{plural_name}
@ -437,14 +502,31 @@ EOC
end
end
def self.install_get_attribute(name, uri, required=true)
attr_writer name
def self.install_get_attribute(name, uri, required=true,
type=nil, disp_name=name)
def_corresponded_attr_writer name, type, disp_name
convert_attr_reader name
if type == :boolean and /^is/ =~ name
alias_method "\#{$POSTMATCH}?", name
end
GET_ATTRIBUTES << [name, uri, required]
end
def self.content_setup
attr_writer :content
def self.def_corresponded_attr_writer(name, type=nil, disp_name=name)
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
def_content_only_to_s
@have_content = true

View file

@ -17,8 +17,12 @@ module RSS
super
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
%w(updateBase).each do |name|
@ -31,12 +35,6 @@ module RSS
validate_sy_updatePeriod(new_value) if @do_validate
self._sy_updatePeriod = new_value
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
end
@ -61,15 +59,6 @@ module RSS
raise NotAvailableValueError.new("updatePeriod", value)
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
class RDF

View file

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

View file

@ -75,9 +75,9 @@ module RSS
generator = "MightyInHouse Content System v2.3"
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
@ -85,7 +85,9 @@ module RSS
managingEditor webMaster pubDate lastBuildDate
generator docs ttl rating)
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
categories.each do |cat|
channel.categories << Rss::Channel::Category.new(cat[:domain],
@ -103,7 +105,8 @@ module RSS
case x
when "pubDate", "lastBuildDate"
assert_equal(expected, Time.parse(elem.text))
when "ttl", "rating"
when "ttl"
expected = channel.__send__(x)
assert_equal(expected, elem.text.to_i)
else
assert_equal(expected, elem.text)
@ -124,7 +127,7 @@ module RSS
def test_channel_cloud
cloud_params = {
:domain => "rpc.sys.com",
:port => 80,
:port => "80",
:path => "/RPC2",
:registerProcedure => "myCloud.rssPleaseNotify",
:protocol => "xml-rpc",
@ -134,7 +137,8 @@ module RSS
cloud_params[:path],
cloud_params[:registerProcedure],
cloud_params[:protocol])
cloud_params[:port] = cloud.port
doc = REXML::Document.new(cloud.to_s)
cloud_elem = doc.root
@ -151,8 +155,8 @@ module RSS
:url => "http://hoge.com/hoge.png",
:title => "fugafuga",
:link => "http://hoge.com",
:width => 144,
:height => 400,
:width => "144",
:height => "400",
:description => "an image",
}
image = Rss::Channel::Image.new(image_params[:url],
@ -166,6 +170,7 @@ module RSS
image_elem = doc.root
image_params.each do |name, value|
value = image.__send__(name)
actual = image_elem.elements[name.to_s].text
actual = actual.to_i if [:width, :height].include?(name)
assert_equal(value, actual)
@ -213,8 +218,8 @@ module RSS
def test_channel_skip_hours
skipHours_values = [
0,
13,
"0",
"13",
]
skipHours = Rss::Channel::SkipHours.new
skipHours_values.each do |value|
@ -225,7 +230,8 @@ module RSS
hours_elem = doc.root
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
@ -252,7 +258,9 @@ module RSS
elems = %w(title link description author comments pubDate)
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
categories.each do |cat|
item.categories << Rss::Channel::Category.new(cat[:domain],
@ -290,23 +298,21 @@ module RSS
def test_item_enclosure
enclosure_params = {
:url => "http://www.scripting.com/mp3s/weatherReportSuite.mp3",
:length => 12216320,
:length => "12216320",
:type => "audio/mpeg",
}
enclosure = Rss::Channel::Item::Enclosure.new(enclosure_params[:url],
enclosure_params[:length],
enclosure_params[:type])
enclosure_params[:length] = enclosure.length
doc = REXML::Document.new(enclosure.to_s)
enclosure_elem = doc.root
actual = {}
enclosure_elem.attributes.each do |name, value|
if name == "length"
enclosure_params[name.to_sym] = value.to_i
value = value.to_i
end
value = value.to_i if name == "length"
actual[name.to_sym] = value
end
assert_equal(enclosure_params, actual)
@ -326,13 +332,22 @@ module RSS
test_params.each do |guid_params|
guid = Rss::Channel::Item::Guid.new(guid_params[:isPermaLink],
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)
guid_elem = doc.root
actual = {}
actual[:content] = guid_elem.text if guid_elem.text
guid_elem.attributes.each do |name, value|
value = value == "true" if name == "isPermaLink"
actual[name.to_sym] = value
end
assert_equal(guid_params, actual)

View file

@ -2,13 +2,13 @@ require "rss-testcase"
require "rss/1.0"
require "rss/2.0"
require "rss/syndication"
require "rss/image"
module RSS
class TestAccessor < TestCase
def test_date
channel = Rss::Channel.new
channel.do_validate = false
channel.pubDate = nil
assert_nil(channel.pubDate)
@ -16,9 +16,88 @@ module RSS
channel.pubDate = time
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
assert_nil(channel.pubDate)
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

View file

@ -26,8 +26,8 @@ module RSS
},
{
"dc:title" => "Example Image",
"#{@prefix}:width" => 100,
"#{@prefix}:height" => 65,
"#{@prefix}:width" => "100",
"#{@prefix}:height" => "65",
},
],
[
@ -36,8 +36,8 @@ module RSS
},
{
"dc:title" => "Culture",
"#{@prefix}:width" => 80,
"#{@prefix}:height" => 50,
"#{@prefix}:width" => "80",
"#{@prefix}:height" => "50",
},
]
]
@ -93,6 +93,23 @@ EOR
assert_equal(@favicon_attrs[full_name], favicon.__send__(name))
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),
].each do |name, full_name, new_value|
@ -120,10 +137,19 @@ EOR
end
[
["width", "image:width", 111],
["image_width", "image:width", 44],
["height", "image:height", 222],
["image_height", "image:height", 88],
["width", "image:width", "111"],
["image_width", "image:width", "44"],
["height", "image:height", "222"],
["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"],
].each do |name, full_name, new_value|
assert_equal(contents[full_name], image_item.__send__(name))

View file

@ -55,15 +55,15 @@ module RSS
copyright = "foo"
managingEditor = "bar"
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"
skipDays = [
"Sunday",
"Monday",
]
skipHours = [
0,
13,
"0",
"13",
]
pubDate = Time.now
lastBuildDate = Time.now
@ -109,7 +109,7 @@ module RSS
assert_equal(day, channel.skipDays.days[i].content)
end
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
assert(channel.items.empty?)
@ -165,8 +165,8 @@ module RSS
title = "fugafuga"
link = "http://hoge.com"
url = "http://hoge.com/hoge.png"
width = 144
height = 400
width = "144"
height = "400"
description = "an image"
rss = RSS::Maker.make("0.91") do |maker|
@ -183,8 +183,8 @@ module RSS
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(width.to_i, image.width)
assert_equal(height.to_i, image.height)
assert_equal(description, image.description)
assert_not_set_error("maker.channel", %w(description title language)) do
@ -205,8 +205,8 @@ module RSS
title = "fugafuga"
link = "http://hoge.com"
url = "http://hoge.com/hoge.png"
width = 144
height = 400
width = "144"
height = "400"
description = "an image"
rss = RSS::Maker.make("0.91") do |maker|

View file

@ -55,7 +55,7 @@ module RSS
assert_equal(title, channel.title)
assert_equal(link, channel.link)
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.textinput)

View file

@ -49,15 +49,15 @@ module RSS
copyright = "foo"
managingEditor = "bar"
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"
skipDays = [
"Sunday",
"Monday",
]
skipHours = [
0,
13,
"0",
"13",
]
pubDate = Time.now
lastBuildDate = Time.now
@ -66,7 +66,7 @@ module RSS
"misc",
]
generator = "RSS Maker"
ttl = 60
ttl = "60"
rss = RSS::Maker.make("2.0") do |maker|
maker.channel.title = title
@ -117,7 +117,7 @@ module RSS
assert_equal(day, channel.skipDays.days[i].content)
end
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
channel.categories.each_with_index do |category, i|
@ -125,7 +125,7 @@ module RSS
end
assert_equal(generator, channel.generator)
assert_equal(ttl, channel.ttl)
assert_equal(ttl.to_i, channel.ttl)
assert(channel.items.empty?)
assert_nil(channel.image)
@ -193,7 +193,7 @@ module RSS
end
cloud = rss.channel.cloud
assert_equal(domain, cloud.domain)
assert_equal(port, cloud.port)
assert_equal(port.to_i, cloud.port)
assert_equal(path, cloud.path)
assert_equal(registerProcedure, cloud.registerProcedure)
assert_equal(protocol, cloud.protocol)
@ -267,8 +267,8 @@ module RSS
title = "fugafuga"
link = "http://hoge.com"
url = "http://hoge.com/hoge.png"
width = 144
height = 400
width = "144"
height = "400"
description = "an image"
rss = RSS::Maker.make("2.0") do |maker|
@ -285,8 +285,8 @@ module RSS
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(width.to_i, image.width)
assert_equal(height.to_i, image.height)
assert_equal(description, image.description)
assert_not_set_error("maker.channel", %w(title description)) do
@ -307,8 +307,8 @@ module RSS
title = "fugafuga"
link = "http://hoge.com"
url = "http://hoge.com/hoge.png"
width = 144
height = 400
width = "144"
height = "400"
description = "an image"
rss = RSS::Maker.make("2.0") do |maker|
@ -418,7 +418,7 @@ module RSS
end
def test_guid
isPermaLink = true
isPermaLink = "true"
content = "http://inessential.com/2002/09/01.php#a2"
rss = RSS::Maker.make("2.0") do |maker|
@ -430,7 +430,7 @@ module RSS
guid.content = content
end
guid = rss.channel.items.last.guid
assert_equal(isPermaLink, guid.isPermaLink)
assert_equal(isPermaLink == "true", guid.isPermaLink)
assert_equal(content, guid.content)
end
@ -463,7 +463,7 @@ module RSS
end
enclosure = rss.channel.items.last.enclosure
assert_equal(url, enclosure.url)
assert_equal(length, enclosure.length)
assert_equal(length.to_i, enclosure.length)
assert_equal(type, enclosure.type)
end

View file

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

View file

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

View file

@ -13,15 +13,15 @@ module RSS
copyright = "foo"
managingEditor = "bar"
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"
skipDays = [
"Sunday",
"Monday",
]
skipHours = [
0,
13,
"0",
"13",
]
pubDate = Time.now
lastBuildDate = Time.now
@ -70,7 +70,7 @@ module RSS
assert_equal(day, channel.skipDays.days[i].content)
end
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
assert(channel.items.empty?)
@ -82,8 +82,8 @@ module RSS
title = "fugafuga"
link = "http://hoge.com"
url = "http://hoge.com/hoge.png"
width = 144
height = 400
width = "144"
height = "400"
description = "an image"
rss = RSS::Maker.make("0.91") do |maker|
@ -106,8 +106,8 @@ module RSS
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(width.to_i, image.width)
assert_equal(height.to_i, image.height)
assert_equal(description, image.description)
end

View file

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

View file

@ -13,15 +13,15 @@ module RSS
copyright = "foo"
managingEditor = "bar"
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"
skipDays = [
"Sunday",
"Monday",
]
skipHours = [
0,
13,
"0",
"13",
]
pubDate = Time.now
lastBuildDate = Time.now
@ -30,7 +30,7 @@ module RSS
"misc",
]
generator = "RSS Maker"
ttl = 60
ttl = "60"
rss = RSS::Maker.make("2.0") do |maker|
maker.channel.title = title
@ -85,7 +85,7 @@ module RSS
assert_equal(day, channel.skipDays.days[i].content)
end
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
@ -94,7 +94,7 @@ module RSS
end
assert_equal(generator, channel.generator)
assert_equal(ttl, channel.ttl)
assert_equal(ttl.to_i, channel.ttl)
assert(channel.items.empty?)
@ -106,8 +106,8 @@ module RSS
title = "fugafuga"
link = "http://hoge.com"
url = "http://hoge.com/hoge.png"
width = 144
height = 400
width = "144"
height = "400"
description = "an image"
rss = RSS::Maker.make("2.0") do |maker|
@ -130,8 +130,8 @@ module RSS
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(width.to_i, image.width)
assert_equal(height.to_i, image.height)
assert_equal(description, image.description)
end
@ -170,7 +170,7 @@ module RSS
comments = "http://www.myblog.org/cgi-local/mt/mt-comments.cgi?entry_id=290"
pubDate = Time.now
guid_isPermaLink = true
guid_isPermaLink = "true"
guid_content = "http://inessential.com/2002/09/01.php#a2"
enclosure_url = "http://www.scripting.com/mp3s/weatherReportSuite.mp3"
@ -234,11 +234,11 @@ module RSS
assert_equal("#{comments}#{i}", item.comments)
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(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(source_url, item.source.url)

View file

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

View file

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