require 'spec_helper'
describe "SitemapGenerator" do
it "should not include media element unless provided" do
xml_fragment = SitemapGenerator::Builder::SitemapUrl.new('link_with_alternates.html',
:host => 'http://www.example.com',
:alternates => [
{
:lang => 'de',
:href => 'http://www.example.de/link_with_alternate.html'
}
]
).to_xml
doc = Nokogiri::XML.parse("#{xml_fragment}")
url = doc.css('url')
url.should_not be_nil
url.css('loc').text.should == 'http://www.example.com/link_with_alternates.html'
alternate = url.at_xpath('xhtml:link')
alternate.should_not be_nil
alternate.attribute('rel').value.should == 'alternate'
alternate.attribute('hreflang').value.should == 'de'
alternate.attribute('media').should be_nil
end
it "should add alternate links to sitemap" do
xml_fragment = SitemapGenerator::Builder::SitemapUrl.new('link_with_alternates.html',
:host => 'http://www.example.com',
:alternates => [
{
:lang => 'de',
:href => 'http://www.example.de/link_with_alternate.html',
:media => 'only screen and (max-width: 640px)'
}
]
).to_xml
doc = Nokogiri::XML.parse("#{xml_fragment}")
url = doc.css('url')
url.should_not be_nil
url.css('loc').text.should == 'http://www.example.com/link_with_alternates.html'
alternate = url.at_xpath('xhtml:link')
alternate.should_not be_nil
alternate.attribute('rel').value.should == 'alternate'
alternate.attribute('hreflang').value.should == 'de'
alternate.attribute('href').value.should == 'http://www.example.de/link_with_alternate.html'
alternate.attribute('media').value.should == 'only screen and (max-width: 640px)'
end
it "should add alternate links to sitemap with rel nofollow" do
xml_fragment = SitemapGenerator::Builder::SitemapUrl.new('link_with_alternates.html',
:host => 'http://www.example.com',
:alternates => [
{
:lang => 'de',
:href => 'http://www.example.de/link_with_alternate.html',
:nofollow => true,
:media => 'only screen and (max-width: 640px)'
}
]
).to_xml
doc = Nokogiri::XML.parse("#{xml_fragment}")
url = doc.css('url')
url.should_not be_nil
url.css('loc').text.should == 'http://www.example.com/link_with_alternates.html'
alternate = url.at_xpath('xhtml:link')
alternate.should_not be_nil
alternate.attribute('rel').value.should == 'alternate nofollow'
alternate.attribute('hreflang').value.should == 'de'
alternate.attribute('href').value.should == 'http://www.example.de/link_with_alternate.html'
alternate.attribute('media').value.should == 'only screen and (max-width: 640px)'
end
end