diff --git a/app/controllers/public/search_controller.rb b/app/controllers/public/search_controller.rb index 182c2e0..ab1d5a9 100644 --- a/app/controllers/public/search_controller.rb +++ b/app/controllers/public/search_controller.rb @@ -90,6 +90,7 @@ class SearchController < ApplicationController SEARCH_IN = [ [ :articles, N_('Articles') ], + [ :comments, N_('Comments') ], [ :enterprises, N_('Enterprises') ], [ :people, N_('People') ], [ :communities, N_('Communities') ], diff --git a/app/helpers/assets_helper.rb b/app/helpers/assets_helper.rb index b3efbd9..d0f75e5 100644 --- a/app/helpers/assets_helper.rb +++ b/app/helpers/assets_helper.rb @@ -9,6 +9,7 @@ module AssetsHelper [ options.merge(:asset => 'products'), "icon-menu-product", _('Products') ], [ options.merge(:asset => 'enterprises'), "icon-menu-enterprise", _('Enterprises') ], [ options.merge(:asset => 'communities'), "icon-menu-community", _('Communities') ], + [ options.merge(:asset => 'comments'), "icon-menu-comments", _('Comments') ], [ options.merge(:asset => 'events'), "icon-menu-events", _('Events') ], ].map do |target,css_class,name| diff --git a/app/models/article.rb b/app/models/article.rb index 4f5a04f..7be9b86 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -21,11 +21,7 @@ class Article < ActiveRecord::Base acts_as_versioned - acts_as_searchable :additional_fields => [ :comment_data ] - - def comment_data - comments.map {|item| [item.title, item.body].join(' ') }.join(' ') - end + acts_as_searchable before_update do |article| article.advertise = true @@ -124,10 +120,6 @@ class Article < ActiveRecord::Base end end - def comments_updated - ferret_update - end - private def sanitize_tag_list diff --git a/app/models/comment.rb b/app/models/comment.rb index 3d822dc..74276a5 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -1,5 +1,7 @@ class Comment < ActiveRecord::Base + acts_as_searchable :fields => [:title, :body] + validates_presence_of :title, :body belongs_to :article, :counter_cache => true belongs_to :author, :class_name => 'Person', :foreign_key => 'author_id' @@ -43,10 +45,4 @@ class Comment < ActiveRecord::Base self.find(:all, :order => 'comments.title', :conditions => ['comments.title like (?) or comments.title like (?)', initial + '%', initial.upcase + '%']) end - after_save :notify_article - after_destroy :notify_article - def notify_article - article.comments_updated - end - end diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index b2072d4..01f0131 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -286,26 +286,5 @@ class ArticleTest < Test::Unit::TestCase assert_equal true, a1.display_to?(member) end - should 'reindex when comments are changed' do - a = Article.new - a.expects(:ferret_update) - a.comments_updated - end - - should 'index comments title together with article' do - owner = create_user('testuser').person - art = owner.articles.build(:name => 'ytest'); art.save! - c1 = art.comments.build(:title => 'a nice comment', :body => 'anything', :author => owner); c1.save! - - assert_includes Article.find_by_contents('nice'), art - end - - should 'index comments body together with article' do - owner = create_user('testuser').person - art = owner.articles.build(:name => 'ytest'); art.save! - c1 = art.comments.build(:title => 'test comment', :body => 'anything', :author => owner); c1.save! - - assert_includes Article.find_by_contents('anything'), art - end end diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index 5f9a7ac..cad72a3 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -93,6 +93,22 @@ class CommentTest < Test::Unit::TestCase assert_equal 'comment-4321', comment.anchor end + should 'be searched by contents of title' do + owner = create_user('testuser').person + art = owner.articles.build(:name => 'ytest'); art.save! + c1 = art.comments.build(:title => 'a nice comment', :body => 'anything', :author => owner); c1.save! + + assert_includes Comment.find_by_contents('nice'), c1 + end + + should 'be searched by contents of body' do + owner = create_user('testuser').person + art = owner.articles.build(:name => 'ytest'); art.save! + c1 = art.comments.build(:title => 'test comment', :body => 'anything', :author => owner); c1.save! + + assert_includes Comment.find_by_contents('anything'), c1 + end + should 'be able to find recent comments' do Comment.delete_all @@ -139,25 +155,4 @@ class CommentTest < Test::Unit::TestCase assert_not_includes list, c2 end - should 'notify article to reindex after saving' do - owner = create_user('testuser').person - article = owner.articles.create!(:name => 'test', :body => '...') - - article.expects(:comments_updated) - - c1 = article.comments.new(:title => "A comment", :body => '...', :author => owner) - c1.stubs(:article).returns(article) - c1.save! - end - - should 'notify article to reindex after being removed' do - owner = create_user('testuser').person - article = owner.articles.create!(:name => 'test', :body => '...') - c1 = article.comments.create!(:title => "A comment", :body => '...', :author => owner) - - c1.stubs(:article).returns(article) - article.expects(:comments_updated) - c1.destroy - end - end -- libgit2 0.21.2