From 9493ec05d8858b4a001814b7620934600f2e0aab Mon Sep 17 00:00:00 2001 From: JoenioCosta Date: Thu, 17 Jul 2008 22:36:59 +0000 Subject: [PATCH] ActionItem567: return only TextArticle in CategoryFinder.find(:articles) --- app/controllers/public/search_controller.rb | 2 +- app/models/category_finder.rb | 4 ++-- test/functional/search_controller_test.rb | 9 +++++++++ test/unit/category_finder_test.rb | 16 ++++++++++++++++ test/unit/text_article_test.rb | 13 +++++++++++++ 5 files changed, 41 insertions(+), 3 deletions(-) diff --git a/app/controllers/public/search_controller.rb b/app/controllers/public/search_controller.rb index f4619b9..e41e37b 100644 --- a/app/controllers/public/search_controller.rb +++ b/app/controllers/public/search_controller.rb @@ -197,7 +197,7 @@ class SearchController < ApplicationController [ :products, ('Products'), @finder.recent('products', limit) ], [ :events, _('Upcoming events'), @finder.upcoming_events({:per_page => limit}) ], [ :communities, _('Communities'), @finder.recent('communities', limit) ], - [ :articles, _('Articles'), @finder.recent('articles', limit) ], + [ :articles, _('Articles'), @finder.recent('text_articles', limit) ], [ :most_commented_articles, _('Most commented articles'), @finder.most_commented_articles(limit) ] ].each do |key, name, list| @order << key diff --git a/app/models/category_finder.rb b/app/models/category_finder.rb index 981e1f3..2e36d8d 100644 --- a/app/models/category_finder.rb +++ b/app/models/category_finder.rb @@ -8,7 +8,7 @@ class CategoryFinder attr_reader :category_id def find(asset, query='', options={}) - @region = Region.find_by_id(options.delete(:region)) if options.has_key?(:region) + @region = Region.find_by_id(options.delete(:region)) if options.has_key?(:region) if @region && options[:within] options[:origin] = [@region.lat, @region.lng] else @@ -99,7 +99,7 @@ class CategoryFinder else {:joins => 'inner join categories_profiles on products.enterprise_id = categories_profiles.profile_id', :conditions => ['categories_profiles.category_id = (?)', category_id]}.merge!(options) end - when 'Article' + when 'Article', 'TextArticle' {:joins => 'inner join articles_categories on (articles_categories.article_id = articles.id)', :conditions => ['articles_categories.category_id = (?)', category_id]}.merge!(options) when 'Event' conditions = diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb index 6a11cc6..6f86795 100644 --- a/test/functional/search_controller_test.rb +++ b/test/functional/search_controller_test.rb @@ -890,6 +890,15 @@ class SearchControllerTest < Test::Unit::TestCase assert_equal nil, assigns(:region) end + should 'found TextileArticle in articles' do + person = create_user('teste').person + art = TextileArticle.create!(:name => 'an text_article article to be found', :profile => person) + + get 'index', :query => 'article found', :find_in => [ 'articles' ] + + assert_includes assigns(:results)[:articles], art + end + ################################################################## ################################################################## diff --git a/test/unit/category_finder_test.rb b/test/unit/category_finder_test.rb index 946338a..8f08f3a 100644 --- a/test/unit/category_finder_test.rb +++ b/test/unit/category_finder_test.rb @@ -446,5 +446,21 @@ class CategoryFinderTest < ActiveSupport::TestCase assert ents.index(ent2) < ents.index(ent1), "expected #{ents.index(ent2)} be smaller than #{ents.index(ent1)}" assert ents.index(ent1) < ents.index(ent3), "expected #{ents.index(ent1)} be smaller than #{ents.index(ent3)}" end + + should 'search for text articles in a specific category' do + person = create_user('teste').person + + # in category + art1 = TextileArticle.create!(:name => 'an article to be found', :profile => person) + art1.add_category(@category) + art1.save! + + # not in category + art2 = TextileArticle.create!(:name => 'another article to be found', :profile => person) + + list = @finder.find(:text_articles, 'found') + assert_includes list, art1 + assert_not_includes list, art2 + end end diff --git a/test/unit/text_article_test.rb b/test/unit/text_article_test.rb index 4c37aad..7670fac 100644 --- a/test/unit/text_article_test.rb +++ b/test/unit/text_article_test.rb @@ -7,4 +7,17 @@ class TextArticleTest < Test::Unit::TestCase should 'inherit from Article' do assert_kind_of Article, TextArticle.new end + + should 'found TextileArticle by TextArticle class' do + person = create_user('testuser').person + article = TextileArticle.create!(:name => 'textile article test', :profile => person) + assert_includes TextArticle.find(:all), article + end + + should 'found TextileArticle by TextArticle indexes' do + person = create_user('testuser').person + article = TextileArticle.create!(:name => 'found article test', :profile => person) + assert_equal TextileArticle.find_by_contents('found'), TextArticle.find_by_contents('found') + end + end -- libgit2 0.21.2