Commit 0ca9cda30359761ca22b6d4bcda3b0c1bc1ac317
1 parent
4a5fd335
Exists in
staging
and in
42 other branches
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
Showing
7 changed files
with
23 additions
and
11 deletions
Show diff stats
app/models/article.rb
... | ... | @@ -109,7 +109,7 @@ class Article < ActiveRecord::Base |
109 | 109 | ((articles.type != ? and articles.type != ? and articles.type != ?) OR articles.type is NULL)", true, true, true, true, 'UploadedFile', 'RssFeed', 'Blog' |
110 | 110 | ], |
111 | 111 | :include => 'profile', |
112 | - :order => 'articles.updated_at desc, articles.id desc' | |
112 | + :order => 'articles.published_at desc, articles.id desc' | |
113 | 113 | } |
114 | 114 | if ( scoped_methods && scoped_methods.last && |
115 | 115 | scoped_methods.last[:find] && | ... | ... |
app/models/blog_archives_block.rb
... | ... | @@ -18,7 +18,7 @@ class BlogArchivesBlock < Block |
18 | 18 | return nil unless owner.has_blog? |
19 | 19 | results = '' |
20 | 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 | 22 | results << content_tag('li', content_tag('strong', "#{year} (#{results_by_year.size})")) |
23 | 23 | results << "<ul class='#{year}-archive'>" |
24 | 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 | 26 | <%= labelled_form_field( _('Feed address'), efeed.text_field(:address) ) %> |
27 | 27 | <div id='external-feed-options-only-once'> |
28 | 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 | 30 | </div> |
31 | 31 | </div> |
32 | 32 | </div> | ... | ... |
db/schema.rb
... | ... | @@ -9,7 +9,7 @@ |
9 | 9 | # |
10 | 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 | 14 | create_table "article_versions", :force => true do |t| |
15 | 15 | t.integer "article_id" | ... | ... |
lib/feed_handler.rb
... | ... | @@ -27,9 +27,9 @@ class FeedHandler |
27 | 27 | container.clear |
28 | 28 | content = fetch(container.address) |
29 | 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 | 33 | container.add_item(item.title, item.link, item.date, item.content) |
34 | 34 | end |
35 | 35 | container.finish_fetch | ... | ... |
test/unit/article_test.rb
... | ... | @@ -181,17 +181,19 @@ class ArticleTest < Test::Unit::TestCase |
181 | 181 | assert_equal [ ], Article.recent(nil) |
182 | 182 | end |
183 | 183 | |
184 | - should 'order recent articles by updated_at' do | |
184 | + should 'order recent articles by published_at' do | |
185 | 185 | p = create_user('usr1').person |
186 | 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 | 193 | assert_equal [ second, first ], Article.recent(2) |
192 | 194 | |
193 | 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 | 197 | Article.record_timestamps = true |
196 | 198 | |
197 | 199 | assert_equal [ first, second ], Article.recent(2) | ... | ... |
test/unit/blog_archives_block_test.rb
... | ... | @@ -56,6 +56,16 @@ class BlogArchivesBlockTest < ActiveSupport::TestCase |
56 | 56 | :sibling => {:tag => 'li', :content => 'May (1)'}}}} |
57 | 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 | 69 | should 'not display any content if has no blog' do |
60 | 70 | profile.stubs(:has_blog?).returns(false) |
61 | 71 | assert !profile.has_blog? | ... | ... |