Commit 892e18f75643836381e6ad406442c5c2ab31548f
1 parent
2390ac55
Exists in
master
and in
23 other branches
ActionItem153: refactoring: changin Article.recent to receive only limit paramet…
…er. Other search arguments will come from scope (e.g. Profile#recent_documents) git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1280 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
4 changed files
with
8 additions
and
14 deletions
Show diff stats
app/controllers/public/home_controller.rb
app/models/article.rb
| ... | ... | @@ -26,13 +26,10 @@ class Article < ActiveRecord::Base |
| 26 | 26 | self.find(:all, :conditions => [ 'parent_id is null and profile_id = ?', profile.id ]) |
| 27 | 27 | end |
| 28 | 28 | |
| 29 | - # retrieves the latest +limit+ articles in profile +profile+, sorted from the | |
| 30 | - # most recent to the oldest. | |
| 31 | - # | |
| 32 | - # If +profile+ is +nil+, then all profiles are searched for articles. | |
| 33 | - def self.recent(profile, limit) | |
| 29 | + # retrieves the latest +limit+ articles, sorted from the most recent to the | |
| 30 | + # oldest. | |
| 31 | + def self.recent(limit) | |
| 34 | 32 | options = { :limit => limit, :order => 'created_on' } |
| 35 | - options[:conditions] = { :profile_id => profile.id } if profile | |
| 36 | 33 | self.find(:all, options) |
| 37 | 34 | end |
| 38 | 35 | ... | ... |
app/models/profile.rb
| ... | ... | @@ -131,7 +131,7 @@ class Profile < ActiveRecord::Base |
| 131 | 131 | # +limit+ is the maximum number of documents to be returned. It defaults to |
| 132 | 132 | # 10. |
| 133 | 133 | def recent_documents(limit = 10) |
| 134 | - self.articles.recent(self, limit) | |
| 134 | + self.articles.recent(limit) | |
| 135 | 135 | end |
| 136 | 136 | |
| 137 | 137 | class << self | ... | ... |
test/unit/article_test.rb
| ... | ... | @@ -132,7 +132,7 @@ class ArticleTest < Test::Unit::TestCase |
| 132 | 132 | end |
| 133 | 133 | end |
| 134 | 134 | |
| 135 | - should 'search for recent documents for a given profile' do | |
| 135 | + should 'search for recent documents' do | |
| 136 | 136 | first = profile.articles.build(:name => 'first'); first.save! |
| 137 | 137 | second = profile.articles.build(:name => 'second'); second.save! |
| 138 | 138 | third = profile.articles.build(:name => 'third'); third.save! |
| ... | ... | @@ -142,11 +142,8 @@ class ArticleTest < Test::Unit::TestCase |
| 142 | 142 | other_profile = create_user('otherpropfile').person |
| 143 | 143 | other_first = other_profile.articles.build(:name => 'first'); other_first.save! |
| 144 | 144 | |
| 145 | - assert_equal [first,second,third], Article.recent(profile, 3) | |
| 146 | - | |
| 147 | - assert_equal [first,second,third,forth,fifth], Article.recent(profile, 10) | |
| 148 | - | |
| 149 | - assert_equal [first,second,third,forth,fifth,other_first], Article.recent(nil, 10) | |
| 145 | + assert_equal [first,second,third], Article.recent(3) | |
| 146 | + assert_equal [first,second,third,forth,fifth,other_first], Article.recent(10) | |
| 150 | 147 | end |
| 151 | 148 | |
| 152 | 149 | should 'provied proper descriptions' do | ... | ... |