diff --git a/app/models/comment.rb b/app/models/comment.rb index 1fad56e..2e28215 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -34,4 +34,8 @@ class Comment < ActiveRecord::Base "comment-#{id}" end + def self.recent(limit = nil) + self.find(:all, :order => 'created_on desc, id desc', :limit => limit) + end + end diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb index bca99cf..24022f8 100644 --- a/test/functional/search_controller_test.rb +++ b/test/functional/search_controller_test.rb @@ -131,6 +131,38 @@ class SearchControllerTest < Test::Unit::TestCase assert_not_includes assigns(:results)[:comments], comment2 end + # 'assets' menu outside any category + should 'list comments in general' do + person = create_user('teste').person + art = person.articles.build(:name => 'an article to be found'); art.save! + comment = art.comments.build(:title => 'comment to be found', :body => 'hfyfyh', :author => person); comment.save! + + get :assets, :asset => 'comments' + assert_includes assigns(:results)[:comments], comment + end + + # 'assets' menu inside a specific category + should 'list comments in a specified category' do + person = create_user('teste').person + + # in category + art1 = person.articles.build(:name => 'an article to be found') + art1.categories << @category + art1.save! + comment1 = art1.comments.build(:title => 'comment to be found', :body => 'hfyfyh', :author => person); comment1.save! + + # not in category + art2 = person.articles.build(:name => 'another article to be found') + art2.save! + comment2 = art2.comments.build(:title => 'comment to be found', :body => 'hfyfyh', :author => person); comment2.save! + + + get :assets, :asset => 'comments', :category_path => [ 'my-category' ] + + assert_includes assigns(:results)[:comments], comment1 + assert_not_includes assigns(:results)[:comments], comment2 + end + should 'find enterprises' do ent = Enterprise.create!(:name => 'teste', :identifier => 'teste') get 'index', :query => 'teste', :find_in => [ 'enterprises' ] @@ -435,10 +467,5 @@ class SearchControllerTest < Test::Unit::TestCase get :assets, :asset => 'products' assert_equal 'Products', assigns(:asset_name) end - - should 'show assets comments' do - get :assets, :asset => 'comments' - assert_tag :tag => 'div', :attributes => {:id => 'boxes'}, :content => {:tag => 'h2', :content => "Comments"} - end end diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index 15d1b6d..ff62846 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -109,4 +109,33 @@ class CommentTest < Test::Unit::TestCase assert_includes Comment.find_by_contents('anything'), c1 end + should 'be able to find recent comments' do + Comment.delete_all + + owner = create_user('testuser').person + art = owner.articles.build(:name => 'ytest'); art.save! + comments = [] + 3.times do + comments.unshift art.comments.create!(:title => 'a test comment', :body => 'bla', :author => owner) + end + + assert_equal comments, Comment.recent + end + + should 'be able to find recent comments with limit' do + Comment.delete_all + + owner = create_user('testuser').person + art = owner.articles.build(:name => 'ytest'); art.save! + comments = [] + 3.times do + comments.unshift art.comments.create!(:title => 'a test comment', :body => 'bla', :author => owner) + end + + comments.pop + + assert_equal comments, Comment.recent(2) + end + + end -- libgit2 0.21.2