aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Gemfile2
-rw-r--r--app/controllers/general_controller.rb7
-rw-r--r--spec/controllers/general_controller_spec.rb11
-rw-r--r--spec/fixtures/files/blog_feed.atom39
4 files changed, 50 insertions, 9 deletions
diff --git a/Gemfile b/Gemfile
index 777f0dcc8..5e4c60ea0 100644
--- a/Gemfile
+++ b/Gemfile
@@ -27,7 +27,7 @@ gem 'vpim'
gem 'will_paginate'
# when 1.2.9 is released by the maintainer, we can stop using this fork:
gem 'xapian-full-alaveteli', '~> 1.2.9.5'
-gem 'xml-simple'
+gem 'xml-simple', :require => 'xmlsimple'
gem 'zip'
gem 'capistrano'
gem 'syslog_protocol'
diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb
index 075d35ba0..0df685829 100644
--- a/app/controllers/general_controller.rb
+++ b/app/controllers/general_controller.rb
@@ -5,13 +5,6 @@
# Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved.
# Email: hello@mysociety.org; WWW: http://www.mysociety.org/
-begin
- require 'xmlsimple'
-rescue LoadError
- # Debian maintainers put their xmlsimple in a different location :(
- require 'lib/xmlsimple'
-end
-
require 'open-uri'
class GeneralController < ApplicationController
diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb
index 9a88dbc3a..4a1c8b134 100644
--- a/spec/controllers/general_controller_spec.rb
+++ b/spec/controllers/general_controller_spec.rb
@@ -19,8 +19,11 @@ end
describe GeneralController, 'when getting the blog feed' do
- it 'should add a lang param correctly to a url with no querystring' do
+ before do
AlaveteliConfiguration.stub!(:blog_feed).and_return("http://blog.example.com")
+ end
+
+ it 'should add a lang param correctly to a url with no querystring' do
get :blog
assigns[:feed_url].should == "http://blog.example.com?lang=en"
end
@@ -31,6 +34,12 @@ describe GeneralController, 'when getting the blog feed' do
assigns[:feed_url].should == "http://blog.example.com?alt=rss&lang=en"
end
+ it 'should parse an item from an example feed' do
+ controller.stub!(:quietly_try_to_open).and_return(load_file_fixture("blog_feed.atom"))
+ get :blog
+ assigns[:blog_items].count.should == 1
+ end
+
end
describe GeneralController, "when showing the frontpage" do
diff --git a/spec/fixtures/files/blog_feed.atom b/spec/fixtures/files/blog_feed.atom
new file mode 100644
index 000000000..f49693938
--- /dev/null
+++ b/spec/fixtures/files/blog_feed.atom
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<rss version="2.0"
+ xmlns:content="http://purl.org/rss/1.0/modules/content/"
+ xmlns:wfw="http://wellformedweb.org/CommentAPI/"
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:atom="http://www.w3.org/2005/Atom"
+ xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
+ xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
+ >
+
+<channel>
+ <title>A Blog Feed</title>
+ <atom:link href="http://example.com/feed/" rel="self" type="application/rss+xml" />
+ <link>http://www.example.com</link>
+ <description>Stuff</description>
+ <lastBuildDate>Tue, 30 Apr 2013 14:34:15 +0000</lastBuildDate>
+ <language>en</language>
+ <sy:updatePeriod>hourly</sy:updatePeriod>
+ <sy:updateFrequency>1</sy:updateFrequency>
+ <generator>http://wordpress.org/?v=3.3.2</generator>
+ <item>
+ <title>Example Post</title>
+ <link>http://www.example.com/example-post</link>
+ <comments>http://www.example.com/example-post#comments</comments>
+ <pubDate>Mon, 01 Apr 2013 19:26:08 +0000</pubDate>
+ <dc:creator>Example Blogger</dc:creator>
+ <category><![CDATA[FOI]]></category>
+
+ <guid isPermaLink="false">http://www.example.com/?id=333</guid>
+ <description><![CDATA[An example post [...]]]></description>
+ <content:encoded><![CDATA[<h3>A blog post</h3>
+<p>Example post</p>
+]]></content:encoded>
+ <wfw:commentRss>http://www.example.com/feed/</wfw:commentRss>
+ <slash:comments>2</slash:comments>
+ </item>
+
+ </channel>
+</rss>