Commit e6804db53297868da972db1b7153ec94a7c07c97
1 parent
bad1cc53
Exists in
staging
and in
42 other branches
ActionItem737: ordering articles by updated_at instead of created_at
Showing
2 changed files
with
18 additions
and
1 deletions
Show diff stats
app/models/article.rb
| ... | ... | @@ -86,7 +86,7 @@ class Article < ActiveRecord::Base |
| 86 | 86 | 'profiles.public_profile' => true |
| 87 | 87 | }, |
| 88 | 88 | :include => 'profile', |
| 89 | - :order => 'articles.created_at desc, articles.id desc' | |
| 89 | + :order => 'articles.updated_at desc, articles.id desc' | |
| 90 | 90 | } |
| 91 | 91 | if ( scoped_methods && scoped_methods.last && |
| 92 | 92 | scoped_methods.last[:find] && | ... | ... |
test/unit/article_test.rb
| 1 | 1 | require File.dirname(__FILE__) + '/../test_helper' |
| 2 | +require 'mocha' | |
| 2 | 3 | |
| 3 | 4 | class ArticleTest < Test::Unit::TestCase |
| 4 | 5 | |
| ... | ... | @@ -169,6 +170,22 @@ class ArticleTest < Test::Unit::TestCase |
| 169 | 170 | assert_equal [ ], Article.recent(nil) |
| 170 | 171 | end |
| 171 | 172 | |
| 173 | + should 'order recent articles by updated_at' do | |
| 174 | + p = create_user('usr1').person | |
| 175 | + Article.destroy_all | |
| 176 | + | |
| 177 | + first = p.articles.build(:name => 'first', :public_article => true); first.save! | |
| 178 | + second = p.articles.build(:name => 'second', :public_article => true, :updated_at => first.updated_at + 1.second); second.save! | |
| 179 | + | |
| 180 | + assert_equal [ second, first ], Article.recent(2) | |
| 181 | + | |
| 182 | + Article.record_timestamps = false | |
| 183 | + first.update_attributes!(:updated_at => second.updated_at + 1.second) | |
| 184 | + Article.record_timestamps = true | |
| 185 | + | |
| 186 | + assert_equal [ first, second ], Article.recent(2) | |
| 187 | + end | |
| 188 | + | |
| 172 | 189 | should 'require that subclasses define description' do |
| 173 | 190 | assert_raise NotImplementedError do |
| 174 | 191 | Article.description | ... | ... |
-
mentioned in commit e9259e24b5e1e0cf04789301df2abfe92548a8b5