From 11619aa74dc09890d5d49b65cf0c1bd9b7cfb617 Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Sat, 5 Jun 2010 14:02:26 -0300 Subject: [PATCH] Apply proper ordering in the per-tag RSS feeds --- app/controllers/public/profile_controller.rb | 2 +- test/functional/profile_controller_test.rb | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb index be8e655..a87f0f5 100644 --- a/app/controllers/public/profile_controller.rb +++ b/app/controllers/public/profile_controller.rb @@ -31,7 +31,7 @@ class ProfileController < PublicController def tag_feed @tag = params[:id] - tagged = profile.find_tagged_with(@tag).paginate(:per_page => 20, :page => 1) + tagged = profile.articles.paginate(:per_page => 20, :page => 1, :order => 'published_at DESC', :include => :tags, :conditions => ['tags.name LIKE ?', @tag]) feed_writer = FeedWriter.new data = feed_writer.write( tagged, diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb index a4b444e..cd69526 100644 --- a/test/functional/profile_controller_test.rb +++ b/test/functional/profile_controller_test.rb @@ -704,4 +704,25 @@ class ProfileControllerTest < Test::Unit::TestCase assert_response 302 end + should 'reverse the order of posts in tag feed' do + TextileArticle.create!(:name => 'First post', :profile => profile, :tag_list => 'tag1', :published_at => Time.now) + TextileArticle.create!(:name => 'Second post', :profile => profile, :tag_list => 'tag1', :published_at => Time.now + 1.day) + + get :tag_feed, :profile => profile.identifier, :id => 'tag1' + assert_match(/Second.*First/, @response.body) + end + + should 'display the most recent posts in tag feed' do + start = Time.now - 30.days + first = TextileArticle.create!(:name => 'First post', :profile => profile, :tag_list => 'tag1', :published_at => start) + 20.times do |i| + TextileArticle.create!(:name => 'Post #' + i.to_s, :profile => profile, :tag_list => 'tag1', :published_at => start + i.days) + end + last = TextileArticle.create!(:name => 'Last post', :profile => profile, :tag_list => 'tag1', :published_at => Time.now) + + get :tag_feed, :profile => profile.identifier, :id => 'tag1' + assert_no_match(/First post/, @response.body) # First post is older than other 20 posts already + assert_match(/Last post/, @response.body) # Latest post must come in the feed + end + end -- libgit2 0.21.2