Commit 325ea765e351e16e287f4914db77dcebd2fb6190

Authored by AntonioTerceiro
1 parent 065dc05f

ActionItem405: reverting commit in the wrong item

Revert "ActionItem410: removed comments from search"

This reverts commit 065dc05fbe43bcc5d53b3f0c9edf0691c979fdca.


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1898 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/public/search_controller.rb
... ... @@ -90,6 +90,7 @@ class SearchController < ApplicationController
90 90  
91 91 SEARCH_IN = [
92 92 [ :articles, N_('Articles') ],
  93 + [ :comments, N_('Comments') ],
93 94 [ :enterprises, N_('Enterprises') ],
94 95 [ :people, N_('People') ],
95 96 [ :communities, N_('Communities') ],
... ...
app/helpers/assets_helper.rb
... ... @@ -9,6 +9,7 @@ module AssetsHelper
9 9 [ options.merge(:asset => 'products'), "icon-menu-product", _('Products') ],
10 10 [ options.merge(:asset => 'enterprises'), "icon-menu-enterprise", _('Enterprises') ],
11 11 [ options.merge(:asset => 'communities'), "icon-menu-community", _('Communities') ],
  12 + [ options.merge(:asset => 'comments'), "icon-menu-comments", _('Comments') ],
12 13 [ options.merge(:asset => 'events'), "icon-menu-events", _('Events') ],
13 14  
14 15 ].map do |target,css_class,name|
... ...
app/models/article.rb
... ... @@ -21,11 +21,7 @@ class Article < ActiveRecord::Base
21 21  
22 22 acts_as_versioned
23 23  
24   - acts_as_searchable :additional_fields => [ :comment_data ]
25   -
26   - def comment_data
27   - comments.map {|item| [item.title, item.body].join(' ') }.join(' ')
28   - end
  24 + acts_as_searchable
29 25  
30 26 before_update do |article|
31 27 article.advertise = true
... ... @@ -124,10 +120,6 @@ class Article < ActiveRecord::Base
124 120 end
125 121 end
126 122  
127   - def comments_updated
128   - ferret_update
129   - end
130   -
131 123 private
132 124  
133 125 def sanitize_tag_list
... ...
app/models/comment.rb
1 1 class Comment < ActiveRecord::Base
2 2  
  3 + acts_as_searchable :fields => [:title, :body]
  4 +
3 5 validates_presence_of :title, :body
4 6 belongs_to :article, :counter_cache => true
5 7 belongs_to :author, :class_name => 'Person', :foreign_key => 'author_id'
... ... @@ -43,10 +45,4 @@ class Comment &lt; ActiveRecord::Base
43 45 self.find(:all, :order => 'comments.title', :conditions => ['comments.title like (?) or comments.title like (?)', initial + '%', initial.upcase + '%'])
44 46 end
45 47  
46   - after_save :notify_article
47   - after_destroy :notify_article
48   - def notify_article
49   - article.comments_updated
50   - end
51   -
52 48 end
... ...
test/unit/article_test.rb
... ... @@ -286,26 +286,5 @@ class ArticleTest &lt; Test::Unit::TestCase
286 286 assert_equal true, a1.display_to?(member)
287 287 end
288 288  
289   - should 'reindex when comments are changed' do
290   - a = Article.new
291   - a.expects(:ferret_update)
292   - a.comments_updated
293   - end
294   -
295   - should 'index comments title together with article' do
296   - owner = create_user('testuser').person
297   - art = owner.articles.build(:name => 'ytest'); art.save!
298   - c1 = art.comments.build(:title => 'a nice comment', :body => 'anything', :author => owner); c1.save!
299   -
300   - assert_includes Article.find_by_contents('nice'), art
301   - end
302   -
303   - should 'index comments body together with article' do
304   - owner = create_user('testuser').person
305   - art = owner.articles.build(:name => 'ytest'); art.save!
306   - c1 = art.comments.build(:title => 'test comment', :body => 'anything', :author => owner); c1.save!
307   -
308   - assert_includes Article.find_by_contents('anything'), art
309   - end
310 289  
311 290 end
... ...
test/unit/comment_test.rb
... ... @@ -93,6 +93,22 @@ class CommentTest &lt; Test::Unit::TestCase
93 93 assert_equal 'comment-4321', comment.anchor
94 94 end
95 95  
  96 + should 'be searched by contents of title' do
  97 + owner = create_user('testuser').person
  98 + art = owner.articles.build(:name => 'ytest'); art.save!
  99 + c1 = art.comments.build(:title => 'a nice comment', :body => 'anything', :author => owner); c1.save!
  100 +
  101 + assert_includes Comment.find_by_contents('nice'), c1
  102 + end
  103 +
  104 + should 'be searched by contents of body' do
  105 + owner = create_user('testuser').person
  106 + art = owner.articles.build(:name => 'ytest'); art.save!
  107 + c1 = art.comments.build(:title => 'test comment', :body => 'anything', :author => owner); c1.save!
  108 +
  109 + assert_includes Comment.find_by_contents('anything'), c1
  110 + end
  111 +
96 112 should 'be able to find recent comments' do
97 113 Comment.delete_all
98 114  
... ... @@ -139,25 +155,4 @@ class CommentTest &lt; Test::Unit::TestCase
139 155 assert_not_includes list, c2
140 156 end
141 157  
142   - should 'notify article to reindex after saving' do
143   - owner = create_user('testuser').person
144   - article = owner.articles.create!(:name => 'test', :body => '...')
145   -
146   - article.expects(:comments_updated)
147   -
148   - c1 = article.comments.new(:title => "A comment", :body => '...', :author => owner)
149   - c1.stubs(:article).returns(article)
150   - c1.save!
151   - end
152   -
153   - should 'notify article to reindex after being removed' do
154   - owner = create_user('testuser').person
155   - article = owner.articles.create!(:name => 'test', :body => '...')
156   - c1 = article.comments.create!(:title => "A comment", :body => '...', :author => owner)
157   -
158   - c1.stubs(:article).returns(article)
159   - article.expects(:comments_updated)
160   - c1.destroy
161   - end
162   -
163 158 end
... ...