Commit e283f47133d51ac066571543f000f7d53f4b62dd
1 parent
a51eb353
Exists in
master
and in
29 other branches
ActionItem1141: reverse the ordering of posts
Showing
2 changed files
with
11 additions
and
1 deletions
Show diff stats
app/models/blog_archives_block.rb
| ... | ... | @@ -21,7 +21,7 @@ class BlogArchivesBlock < Block |
| 21 | 21 | posts.group_by {|i| i.published_at.year }.sort_by { |year,count| -year }.each do |year, results_by_year| |
| 22 | 22 | results << content_tag('li', content_tag('strong', "#{year} (#{results_by_year.size})")) |
| 23 | 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 | 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 | 26 | end |
| 27 | 27 | results << "</ul>" | ... | ... |
test/unit/blog_archives_block_test.rb
| ... | ... | @@ -66,6 +66,16 @@ class BlogArchivesBlockTest < ActiveSupport::TestCase |
| 66 | 66 | assert_match(/2009.*2008.*2007.*2006.*2005/m, block.content) |
| 67 | 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 | 79 | should 'not display any content if has no blog' do |
| 70 | 80 | profile.stubs(:has_blog?).returns(false) |
| 71 | 81 | assert !profile.has_blog? | ... | ... |