Commit 0ca9cda30359761ca22b6d4bcda3b0c1bc1ac317

Authored by Antonio Terceiro
1 parent 4a5fd335

ActionItem935: additional changes needed

  * Fixing BlogArchivesBlock to list the years in the correct order
  * Changing Article#recent to consider published_at instead of
    created_at for listing recent content.
  * small refactoring in FeedHandler (rename variable)
  * Better wording in blog edition template
app/models/article.rb
@@ -109,7 +109,7 @@ class Article < ActiveRecord::Base @@ -109,7 +109,7 @@ class Article < ActiveRecord::Base
109 ((articles.type != ? and articles.type != ? and articles.type != ?) OR articles.type is NULL)", true, true, true, true, 'UploadedFile', 'RssFeed', 'Blog' 109 ((articles.type != ? and articles.type != ? and articles.type != ?) OR articles.type is NULL)", true, true, true, true, 'UploadedFile', 'RssFeed', 'Blog'
110 ], 110 ],
111 :include => 'profile', 111 :include => 'profile',
112 - :order => 'articles.updated_at desc, articles.id desc' 112 + :order => 'articles.published_at desc, articles.id desc'
113 } 113 }
114 if ( scoped_methods && scoped_methods.last && 114 if ( scoped_methods && scoped_methods.last &&
115 scoped_methods.last[:find] && 115 scoped_methods.last[:find] &&
app/models/blog_archives_block.rb
@@ -18,7 +18,7 @@ class BlogArchivesBlock < Block @@ -18,7 +18,7 @@ class BlogArchivesBlock < Block
18 return nil unless owner.has_blog? 18 return nil unless owner.has_blog?
19 results = '' 19 results = ''
20 posts = owner.blog.posts 20 posts = owner.blog.posts
21 - posts.group_by{|i| i.published_at.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.each do |month, results_by_month|
app/views/cms/_blog.rhtml
@@ -26,7 +26,7 @@ @@ -26,7 +26,7 @@
26 <%= labelled_form_field( _('Feed address'), efeed.text_field(:address) ) %> 26 <%= labelled_form_field( _('Feed address'), efeed.text_field(:address) ) %>
27 <div id='external-feed-options-only-once'> 27 <div id='external-feed-options-only-once'>
28 <%= labelled_radio_button( _('Fetch posts only once'), 'article[external_feed_builder][only_once]', 'true', only_once) %> 28 <%= labelled_radio_button( _('Fetch posts only once'), 'article[external_feed_builder][only_once]', 'true', only_once) %>
29 - <%= labelled_radio_button( _('Fetch posts always'), 'article[external_feed_builder][only_once]', 'false', !only_once) %> 29 + <%= labelled_radio_button( _('Fetch posts periodically'), 'article[external_feed_builder][only_once]', 'false', !only_once) %>
30 </div> 30 </div>
31 </div> 31 </div>
32 </div> 32 </div>
@@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
9 # 9 #
10 # It's strongly recommended to check this file into your version control system. 10 # It's strongly recommended to check this file into your version control system.
11 11
12 -ActiveRecord::Schema.define(:version => 64) do 12 +ActiveRecord::Schema.define(:version => 65) do
13 13
14 create_table "article_versions", :force => true do |t| 14 create_table "article_versions", :force => true do |t|
15 t.integer "article_id" 15 t.integer "article_id"
lib/feed_handler.rb
@@ -27,9 +27,9 @@ class FeedHandler @@ -27,9 +27,9 @@ class FeedHandler
27 container.clear 27 container.clear
28 content = fetch(container.address) 28 content = fetch(container.address)
29 container.fetched_at = Time.now 29 container.fetched_at = Time.now
30 - parse = parse(content)  
31 - container.feed_title = parse.title  
32 - parse.items[0..container.limit-1].each do |item| 30 + parsed_feed = parse(content)
  31 + container.feed_title = parsed_feed.title
  32 + parsed_feed.items[0..container.limit-1].each do |item|
33 container.add_item(item.title, item.link, item.date, item.content) 33 container.add_item(item.title, item.link, item.date, item.content)
34 end 34 end
35 container.finish_fetch 35 container.finish_fetch
test/unit/article_test.rb
@@ -181,17 +181,19 @@ class ArticleTest &lt; Test::Unit::TestCase @@ -181,17 +181,19 @@ class ArticleTest &lt; Test::Unit::TestCase
181 assert_equal [ ], Article.recent(nil) 181 assert_equal [ ], Article.recent(nil)
182 end 182 end
183 183
184 - should 'order recent articles by updated_at' do 184 + should 'order recent articles by published_at' do
185 p = create_user('usr1').person 185 p = create_user('usr1').person
186 Article.destroy_all 186 Article.destroy_all
187 187
188 - first = p.articles.build(:name => 'first', :public_article => true); first.save!  
189 - second = p.articles.build(:name => 'second', :public_article => true, :updated_at => first.updated_at + 1.second); second.save! 188 + now = Time.now
  189 +
  190 + first = p.articles.build(:name => 'first', :public_article => true, :created_at => now, :published_at => now); first.save!
  191 + second = p.articles.build(:name => 'second', :public_article => true, :updated_at => now, :published_at => now + 1.second); second.save!
190 192
191 assert_equal [ second, first ], Article.recent(2) 193 assert_equal [ second, first ], Article.recent(2)
192 194
193 Article.record_timestamps = false 195 Article.record_timestamps = false
194 - first.update_attributes!(:updated_at => second.updated_at + 1.second) 196 + first.update_attributes!(:published_at => second.published_at + 1.second)
195 Article.record_timestamps = true 197 Article.record_timestamps = true
196 198
197 assert_equal [ first, second ], Article.recent(2) 199 assert_equal [ first, second ], Article.recent(2)
test/unit/blog_archives_block_test.rb
@@ -56,6 +56,16 @@ class BlogArchivesBlockTest &lt; ActiveSupport::TestCase @@ -56,6 +56,16 @@ class BlogArchivesBlockTest &lt; ActiveSupport::TestCase
56 :sibling => {:tag => 'li', :content => 'May (1)'}}}} 56 :sibling => {:tag => 'li', :content => 'May (1)'}}}}
57 end 57 end
58 58
  59 + should 'order years' do
  60 + blog = profile.blog
  61 + for year in 2005..2009
  62 + post = TextileArticle.create!(:name => "post #{year}", :profile => profile, :parent => blog, :published_at => Date.new(year, 1, 1))
  63 + end
  64 + block = BlogArchivesBlock.new
  65 + block.stubs(:owner).returns(profile)
  66 + assert_match(/2009.*2008.*2007.*2006.*2005/m, block.content)
  67 + end
  68 +
59 should 'not display any content if has no blog' do 69 should 'not display any content if has no blog' do
60 profile.stubs(:has_blog?).returns(false) 70 profile.stubs(:has_blog?).returns(false)
61 assert !profile.has_blog? 71 assert !profile.has_blog?