Support namespace addons

This commit is contained in:
2018-10-11 00:04:26 +11:00
parent 0c08823178
commit b6aab1edb5
6 changed files with 125 additions and 20 deletions

View File

@@ -15,26 +15,6 @@
require "./spec_helper"
describe RSS do
ex_cloud = RSS::Cloud.new(
domain: "rpc.sys.com",
port: 80,
path: "/RPC2",
register_procedure: "pingMe",
protocol: "soap"
)
ex_enclosure = RSS::Enclosure.new(
url: "http://live.curry.com/mp3/celebritySCms.mp3",
length: 1069871,
type: "audio/mpeg"
)
base_channel = RSS::Channel.new(
link: "http://www.goupstate.com/",
title: "GoUpstate.com News Headlines",
description: "The latest news from GoUpstate.com, a Spartanburg Herald-Journal Web site."
)
it "builds enclosure" do
w3 = HEADER + ENCLOSURE_TEST
@@ -85,5 +65,23 @@ describe RSS do
chan = base_channel
chan.skip_days = [RSS::Day::Monday, RSS::Day::Wednesday]
chan.skip_hours = [2, 6, 18, 22]
chan.to_s.strip.should eq SKIP_DAY_TEST
end
it "adds namespace" do
chan = base_channel
chan.add_ns(dc: "http://purl.org/dc/elements/1.1")
chan.ns("dc") do |dc|
dc["rights"] = "Copyright 2002"
end
item = RSS::Item.new(title: "New item")
item.ns("dc") do |dc|
dc["subject"] = "CSS"
end
chan << item
chan.to_s.strip.should eq NAMESPACE_TEST
end
end

View File

@@ -15,6 +15,32 @@
require "spec"
require "../src/cryss"
def ex_cloud
RSS::Cloud.new(
domain: "rpc.sys.com",
port: 80,
path: "/RPC2",
register_procedure: "pingMe",
protocol: "soap"
)
end
def ex_enclosure
RSS::Enclosure.new(
url: "http://live.curry.com/mp3/celebritySCms.mp3",
length: 1069871,
type: "audio/mpeg"
)
end
def base_channel
RSS::Channel.new(
link: "http://www.goupstate.com/",
title: "GoUpstate.com News Headlines",
description: "The latest news from GoUpstate.com, a Spartanburg Herald-Journal Web site."
)
end
HEADER = "<?xml version=\"1.0\"?>\n"
CLOUD_TEST = "<cloud domain=\"rpc.sys.com\" port=\"80\" path=\"/RPC2\" registerProcedure=\"pingMe\" protocol=\"soap\"/>"
@@ -63,6 +89,8 @@ SKIP_DAY_TEST = HEADER + <<-XML
<title>GoUpstate.com News Headlines</title>
<link>http://www.goupstate.com/</link>
<description>The latest news from GoUpstate.com, a Spartanburg Herald-Journal Web site.</description>
<docs>https://validator.w3.org/feed/docs/rss2.html</docs>
<generator>cryss</generator>
<skipHours>
<hour>2</hour>
<hour>6</hour>
@@ -76,3 +104,20 @@ SKIP_DAY_TEST = HEADER + <<-XML
</channel>
</rss>
XML
NAMESPACE_TEST = HEADER + <<-XML
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1">
<channel>
<title>GoUpstate.com News Headlines</title>
<link>http://www.goupstate.com/</link>
<description>The latest news from GoUpstate.com, a Spartanburg Herald-Journal Web site.</description>
<docs>https://validator.w3.org/feed/docs/rss2.html</docs>
<generator>cryss</generator>
<dc:rights>Copyright 2002</dc:rights>
<item>
<title>New item</title>
<dc:subject>CSS</dc:subject>
</item>
</channel>
</rss>
XML