Ref #52 RSS url detection

This commit is contained in:
erwanlr
2012-12-20 17:46:06 +01:00
parent 221068ef1b
commit c0a05a4119
3 changed files with 62 additions and 1 deletions

View File

@@ -93,7 +93,7 @@ module WebSite
def homepage_hash
unless @homepage_hash
@homepage_hash = WebSite.page_hash(self.url)
@homepage_hash = WebSite.page_hash(@uri.to_s)
end
@homepage_hash
end
@@ -106,4 +106,11 @@ module WebSite
end
@error_404_hash
end
# Will try to find the rss url in the homepage
# Only the first one found iw returned
def rss_url
homepage_body = Browser.instance.get(@uri.to_s).body
homepage_body[%r{<link .* type="application/rss\+xml" .* href="([^"]+)" />}, 1]
end
end

View File

@@ -0,0 +1,42 @@
<!DOCTYPE html>
<!--[if IE 7]>
<html class="ie ie7" lang="en-US">
<![endif]-->
<!--[if IE 8]>
<html class="ie ie8" lang="en-US">
<![endif]-->
<!--[if !(IE 7) | !(IE 8) ]><!-->
<html lang="en-US">
<!--<![endif]-->
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<title>Wordpress 3.5 | Just another WordPress site</title>
<link rel="profile" href="http://gmpg.org/xfn/11" />
<link rel="pingback" href="http://lamp-wp/wordpress-3.5/xmlrpc.php" />
<!--[if lt IE 9]>
<script src="http://lamp-wp/wordpress-3.5/wp-content/themes/twentytwelve/js/html5.js" type="text/javascript"></script>
<![endif]-->
<meta name='robots' content='noindex,nofollow' />
<link rel="alternate" type="application/rss+xml" title="Wordpress 3.5 &raquo; Feed" href="http://lamp-wp/wordpress-3.5/?feed=rss2" />
<link rel="alternate" type="application/rss+xml" title="Wordpress 3.5 &raquo; Comments Feed" href="http://lamp-wp/wordpress-3.5/?feed=comments-rss2" />
<link rel='stylesheet' id='admin-bar-css' href='http://lamp-wp/wordpress-3.5/wp-includes/css/admin-bar.min.css?ver=3.5' type='text/css' media='all' />
<link rel='stylesheet' id='twentytwelve-fonts-css' href='http://fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,400,700&#038;subset=latin,latin-ext' type='text/css' media='all' />
<link rel='stylesheet' id='twentytwelve-style-css' href='http://lamp-wp/wordpress-3.5/wp-content/themes/twentytwelve/style.css?ver=3.5' type='text/css' media='all' />
<!--[if lt IE 9]>
<link rel='stylesheet' id='twentytwelve-ie-css' href='http://lamp-wp/wordpress-3.5/wp-content/themes/twentytwelve/css/ie.css?ver=20121010' type='text/css' media='all' />
<![endif]-->
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://lamp-wp/wordpress-3.5/xmlrpc.php?rsd" />
<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://lamp-wp/wordpress-3.5/wp-includes/wlwmanifest.xml" />
<meta name="generator" content="WordPress 3.5" />
<style type="text/css">.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}</style>
<style type="text/css" media="print">#wpadminbar { display:none; }</style>
<style type="text/css" media="screen">
html { margin-top: 28px !important; }
* html body { margin-top: 28px !important; }
</style>
</head>
<body class="home blog logged-in admin-bar no-customize-support custom-font-enabled single-author">
</body>
</html>

View File

@@ -148,4 +148,16 @@ shared_examples_for "WebSite" do
web_site.error_404_hash.should === Digest::MD5.hexdigest("404 page !")
end
end
describe "#rss_url" do
it "should return nil if the url is not found" do
stub_request(:get, web_site.url).to_return(:body => "No RSS link in this body !")
web_site.rss_url.should be_nil
end
it "should return 'http://lamp-wp/wordpress-3.5/?feed=rss2'" do
stub_request_to_fixture(:url => web_site.url, :fixture => fixtures_dir + "/rss_url/wordpress-3.5.htm")
web_site.rss_url.should === "http://lamp-wp/wordpress-3.5/?feed=rss2"
end
end
end