Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
Index: test/functional/feed_controller_test.rb =================================================================== --- test/functional/feed_controller_test.rb (revision 2878) +++ test/functional/feed_controller_test.rb (working copy) @@ -5,14 +5,22 @@ class FeedController; def rescue_action(e) raise e end; end class FeedControllerTest < Test::Unit::TestCase - fixtures :contents, :sections, :assigned_sections, :sites + fixtures :contents, :sections, :assigned_sections, :sites, :users def setup @controller = FeedController.new @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new end - + + def test_feed_has_namespaces + get :feed, :sections =>[] + # can't do feed[xmlns:thr] + assert_select 'feed', 1 do |feed| + assert_equal 'http://www.w3.org/2005/Atom', feed[0]['xmlns'] + assert_equal 'http://purl.org/syndication/thread/1.0', feed[0]['xmlns:thr'] + end + end def test_feed_comes_from_site host! 'cupcake.com' get :feed, :sections => ['about'] @@ -78,12 +86,20 @@ specify "should show correct links" do assert_select 'feed>link[href=?][type=?]', 'http://test.host/about', 'text/html' - assert_select 'feed>entry>link[href]', 4 do |hrefs| + assert_select 'feed>entry>link[href][rel=alternate]', 3 do |hrefs| assert_equal "http://test.host/about", hrefs[0]['href'] - assert_match /asset\.mp3$/, hrefs[1]['href'] - assert_equal "http://test.host/about/about-this-page", hrefs[2]['href'] - assert_equal "http://test.host/about/the-site-map", hrefs[3]['href'] + assert_equal "http://test.host/about/about-this-page", hrefs[1]['href'] + assert_equal "http://test.host/about/the-site-map", hrefs[2]['href'] end + assert_select 'feed>entry>link[href][rel=enclosure]', 1 do |hrefs| + assert_match /asset\.mp3$/, hrefs[0]['href'] + end + assert_select 'feed>entry>link[href][rel=replies]' , 3 do |hrefs| + assert_equal "http://test.host/about#comments", hrefs[0]['href'] + assert_equal "http://test.host/about/about-this-page#comments", hrefs[1]['href'] + assert_equal "http://test.host/about/the-site-map#comments", hrefs[2]['href'] + end + end end @@ -107,10 +123,16 @@ specify "should show correct links" do assert_select 'feed>link[href=?][type=?]', 'http://test.host/', 'text/html' - assert_select 'feed>entry>link[href]', 3 do |hrefs| + assert_select 'feed>entry>link[href][rel=enclosure]', 1 do |hrefs| + assert_match /asset\.mp3$/, hrefs[0]['href'] + end + assert_select 'feed>entry>link[href][rel=replies]', 2 do |hrefs| + assert_match /\/welcome-to-mephisto#comments$/,hrefs[0]['href'] + assert_match /\/another-welcome-to-mephisto#comments$/, hrefs[1]['href'] + end + assert_select 'feed>entry>link[href][rel=alternate]', 2 do |hrefs| assert_match /\/welcome-to-mephisto$/, hrefs[0]['href'] - assert_match /asset\.mp3$/, hrefs[1]['href'] - assert_match /\/another-welcome-to-mephisto$/, hrefs[2]['href'] + assert_match /\/another-welcome-to-mephisto$/, hrefs[1]['href'] end end @@ -143,4 +165,4 @@ assert !text.ends_with(CGI::escapeHTML(evil)), "'#{text.inspect}' was not sanitized" assert text.ends_with(CGI::escapeHTML(good)), "'#{text.inspect}' was not sanitized" end -end \ No newline at end of file +end Index: app/views/feed/_article.rxml =================================================================== --- app/views/feed/_article.rxml (revision 2878) +++ app/views/feed/_article.rxml (working copy) @@ -11,8 +11,13 @@ article.tags.each do |tag| xm.category "term" => tag.name end + url = "http://#{request.host_with_port}#{request.relative_url_root}#{section_url_for article}" + xm.link "rel" => "alternate", "type" => "text/html", - "href" => "http://#{request.host_with_port}#{request.relative_url_root}#{section_url_for article}" + "href" => url + xm.link "rel" => "replies", "type" => "text/html", + "href" => url+'#comments', + "thr:count" => article.comments.size.to_s xm.title strip_tags(article.title) unless article.excerpt_html.blank? xm << %{<summary type="html">#{sanitize_feed_content article.excerpt_html}</summary>} @@ -20,7 +25,7 @@ unless article.body_html.blank? xm << %{<content type="html"> #{sanitize_feed_content [article.excerpt_html, article.body_html].compact * "\n"} - </content>} + </content>\n} end article.add_xml(xm) -end \ No newline at end of file +end Index: app/views/feed/feed.rxml =================================================================== --- app/views/feed/feed.rxml (revision 2878) +++ app/views/feed/feed.rxml (working copy) @@ -1,6 +1,8 @@ xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8" -xml.feed "xml:lang" => "en-US", "xmlns" => 'http://www.w3.org/2005/Atom' do +xml.feed "xml:lang" => "en-US", + "xmlns" => 'http://www.w3.org/2005/Atom', + "xmlns:thr" => "http://purl.org/syndication/thread/1.0" do xml.title "#{site.title || 'Mephisto'} - #{@section ? @section.name : 'All'}#{' Comments' if @comments && @articles.nil?}" xml.id "tag:#{request.host},#{Time.now.utc.year}:mephisto#{"/#{@section.path}" if @section}#{ '/comments' if @comments && @articles.nil?}" xml.generator "Mephisto #{Mephisto::Version::TITLE}", :uri => "http://mephistoblog.com", :version => "#{Mephisto::Version::STRING}"
This paste will be private.
From the Design Piracy series on my blog: