Commit e283f47133d51ac066571543f000f7d53f4b62dd

Authored by Antonio Terceiro
1 parent a51eb353

ActionItem1141: reverse the ordering of posts

app/models/blog_archives_block.rb
@@ -21,7 +21,7 @@ class BlogArchivesBlock < Block @@ -21,7 +21,7 @@ class BlogArchivesBlock < Block
21 posts.group_by {|i| i.published_at.year }.sort_by { |year,count| -year }.each do |year, results_by_year| 21 posts.group_by {|i| i.published_at.year }.sort_by { |year,count| -year }.each do |year, results_by_year|
22 results << content_tag('li', content_tag('strong', "#{year} (#{results_by_year.size})")) 22 results << content_tag('li', content_tag('strong', "#{year} (#{results_by_year.size})"))
23 results << "<ul class='#{year}-archive'>" 23 results << "<ul class='#{year}-archive'>"
24 - results_by_year.group_by{|i| [ ('%02d' % i.published_at.month()), gettext(MONTHS[i.published_at.month() - 1])]}.sort.each do |month, results_by_month| 24 + results_by_year.group_by{|i| [ ('%02d' % i.published_at.month()), gettext(MONTHS[i.published_at.month() - 1])]}.sort.reverse.each do |month, results_by_month|
25 results << content_tag('li', link_to("#{month[1]} (#{results_by_month.size})", owner.generate_url(:controller => 'content_viewer', :action => 'view_page', :page => [owner.blog.path], :year => year, :month => month[0]))) 25 results << content_tag('li', link_to("#{month[1]} (#{results_by_month.size})", owner.generate_url(:controller => 'content_viewer', :action => 'view_page', :page => [owner.blog.path], :year => year, :month => month[0])))
26 end 26 end
27 results << "</ul>" 27 results << "</ul>"
test/unit/blog_archives_block_test.rb
@@ -66,6 +66,16 @@ class BlogArchivesBlockTest &lt; ActiveSupport::TestCase @@ -66,6 +66,16 @@ class BlogArchivesBlockTest &lt; ActiveSupport::TestCase
66 assert_match(/2009.*2008.*2007.*2006.*2005/m, block.content) 66 assert_match(/2009.*2008.*2007.*2006.*2005/m, block.content)
67 end 67 end
68 68
  69 + should 'order months from later to former' do
  70 + blog = profile.blog
  71 + for month in 1..3
  72 + post = TextileArticle.create!(:name => "post #{month}", :profile => profile, :parent => blog, :published_at => Date.new(2009, month, 1))
  73 + end
  74 + block = BlogArchivesBlock.new
  75 + block.stubs(:owner).returns(profile)
  76 + assert_match(/.*March.*February.*January.*/m, block.content)
  77 + end
  78 +
69 should 'not display any content if has no blog' do 79 should 'not display any content if has no blog' do
70 profile.stubs(:has_blog?).returns(false) 80 profile.stubs(:has_blog?).returns(false)
71 assert !profile.has_blog? 81 assert !profile.has_blog?