Commit 9493ec05d8858b4a001814b7620934600f2e0aab

Authored by JoenioCosta
1 parent 518f2836

ActionItem567: return only TextArticle in CategoryFinder.find(:articles)

git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2278 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/public/search_controller.rb
@@ -197,7 +197,7 @@ class SearchController < ApplicationController @@ -197,7 +197,7 @@ class SearchController < ApplicationController
197 [ :products, ('Products'), @finder.recent('products', limit) ], 197 [ :products, ('Products'), @finder.recent('products', limit) ],
198 [ :events, _('Upcoming events'), @finder.upcoming_events({:per_page => limit}) ], 198 [ :events, _('Upcoming events'), @finder.upcoming_events({:per_page => limit}) ],
199 [ :communities, _('Communities'), @finder.recent('communities', limit) ], 199 [ :communities, _('Communities'), @finder.recent('communities', limit) ],
200 - [ :articles, _('Articles'), @finder.recent('articles', limit) ], 200 + [ :articles, _('Articles'), @finder.recent('text_articles', limit) ],
201 [ :most_commented_articles, _('Most commented articles'), @finder.most_commented_articles(limit) ] 201 [ :most_commented_articles, _('Most commented articles'), @finder.most_commented_articles(limit) ]
202 ].each do |key, name, list| 202 ].each do |key, name, list|
203 @order << key 203 @order << key
app/models/category_finder.rb
@@ -8,7 +8,7 @@ class CategoryFinder @@ -8,7 +8,7 @@ class CategoryFinder
8 attr_reader :category_id 8 attr_reader :category_id
9 9
10 def find(asset, query='', options={}) 10 def find(asset, query='', options={})
11 - @region = Region.find_by_id(options.delete(:region)) if options.has_key?(:region) 11 + @region = Region.find_by_id(options.delete(:region)) if options.has_key?(:region)
12 if @region && options[:within] 12 if @region && options[:within]
13 options[:origin] = [@region.lat, @region.lng] 13 options[:origin] = [@region.lat, @region.lng]
14 else 14 else
@@ -99,7 +99,7 @@ class CategoryFinder @@ -99,7 +99,7 @@ class CategoryFinder
99 else 99 else
100 {:joins => 'inner join categories_profiles on products.enterprise_id = categories_profiles.profile_id', :conditions => ['categories_profiles.category_id = (?)', category_id]}.merge!(options) 100 {:joins => 'inner join categories_profiles on products.enterprise_id = categories_profiles.profile_id', :conditions => ['categories_profiles.category_id = (?)', category_id]}.merge!(options)
101 end 101 end
102 - when 'Article' 102 + when 'Article', 'TextArticle'
103 {:joins => 'inner join articles_categories on (articles_categories.article_id = articles.id)', :conditions => ['articles_categories.category_id = (?)', category_id]}.merge!(options) 103 {:joins => 'inner join articles_categories on (articles_categories.article_id = articles.id)', :conditions => ['articles_categories.category_id = (?)', category_id]}.merge!(options)
104 when 'Event' 104 when 'Event'
105 conditions = 105 conditions =
test/functional/search_controller_test.rb
@@ -890,6 +890,15 @@ class SearchControllerTest &lt; Test::Unit::TestCase @@ -890,6 +890,15 @@ class SearchControllerTest &lt; Test::Unit::TestCase
890 assert_equal nil, assigns(:region) 890 assert_equal nil, assigns(:region)
891 end 891 end
892 892
  893 + should 'found TextileArticle in articles' do
  894 + person = create_user('teste').person
  895 + art = TextileArticle.create!(:name => 'an text_article article to be found', :profile => person)
  896 +
  897 + get 'index', :query => 'article found', :find_in => [ 'articles' ]
  898 +
  899 + assert_includes assigns(:results)[:articles], art
  900 + end
  901 +
893 ################################################################## 902 ##################################################################
894 ################################################################## 903 ##################################################################
895 904
test/unit/category_finder_test.rb
@@ -446,5 +446,21 @@ class CategoryFinderTest &lt; ActiveSupport::TestCase @@ -446,5 +446,21 @@ class CategoryFinderTest &lt; ActiveSupport::TestCase
446 assert ents.index(ent2) < ents.index(ent1), "expected #{ents.index(ent2)} be smaller than #{ents.index(ent1)}" 446 assert ents.index(ent2) < ents.index(ent1), "expected #{ents.index(ent2)} be smaller than #{ents.index(ent1)}"
447 assert ents.index(ent1) < ents.index(ent3), "expected #{ents.index(ent1)} be smaller than #{ents.index(ent3)}" 447 assert ents.index(ent1) < ents.index(ent3), "expected #{ents.index(ent1)} be smaller than #{ents.index(ent3)}"
448 end 448 end
  449 +
  450 + should 'search for text articles in a specific category' do
  451 + person = create_user('teste').person
  452 +
  453 + # in category
  454 + art1 = TextileArticle.create!(:name => 'an article to be found', :profile => person)
  455 + art1.add_category(@category)
  456 + art1.save!
  457 +
  458 + # not in category
  459 + art2 = TextileArticle.create!(:name => 'another article to be found', :profile => person)
  460 +
  461 + list = @finder.find(:text_articles, 'found')
  462 + assert_includes list, art1
  463 + assert_not_includes list, art2
  464 + end
449 465
450 end 466 end
test/unit/text_article_test.rb
@@ -7,4 +7,17 @@ class TextArticleTest &lt; Test::Unit::TestCase @@ -7,4 +7,17 @@ class TextArticleTest &lt; Test::Unit::TestCase
7 should 'inherit from Article' do 7 should 'inherit from Article' do
8 assert_kind_of Article, TextArticle.new 8 assert_kind_of Article, TextArticle.new
9 end 9 end
  10 +
  11 + should 'found TextileArticle by TextArticle class' do
  12 + person = create_user('testuser').person
  13 + article = TextileArticle.create!(:name => 'textile article test', :profile => person)
  14 + assert_includes TextArticle.find(:all), article
  15 + end
  16 +
  17 + should 'found TextileArticle by TextArticle indexes' do
  18 + person = create_user('testuser').person
  19 + article = TextileArticle.create!(:name => 'found article test', :profile => person)
  20 + assert_equal TextileArticle.find_by_contents('found'), TextArticle.find_by_contents('found')
  21 + end
  22 +
10 end 23 end