Commit ae3a5cc328186254a9b2dfae5ba5a8fcebf071ef

Authored by MoisesMachado
1 parent 6f0362a9

ActionItem501: fixed some test that has wrong interfaces and fixed the environme…

…nt_finder to propely fetch enterprises by its products categories


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2157 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/models/environment_finder.rb
@@ -31,7 +31,7 @@ class EnvironmentFinder @@ -31,7 +31,7 @@ class EnvironmentFinder
31 # SECURITY no risk of SQL injection, since product_category_ids comes from trusted source 31 # SECURITY no risk of SQL injection, since product_category_ids comes from trusted source
32 @environment.send(asset).find_by_contents(query, ferret_options, options.merge({:conditions => 'product_category_id in (%s)' % product_category_ids.join(',') })) 32 @environment.send(asset).find_by_contents(query, ferret_options, options.merge({:conditions => 'product_category_id in (%s)' % product_category_ids.join(',') }))
33 elsif product_category && asset == :enterprises 33 elsif product_category && asset == :enterprises
34 - @environment.send(asset).find_by_contents(query + " +extra_data_for_index:#{product_category.name}", ferret_options, options) 34 + @environment.send(asset).find_by_contents(query, ferret_options, options.merge(:include => 'products', :conditions => "products.product_category_id in (#{product_category_ids})"))
35 else 35 else
36 @environment.send(asset).find_by_contents(query, ferret_options, options) 36 @environment.send(asset).find_by_contents(query, ferret_options, options)
37 end 37 end
test/functional/search_controller_test.rb
@@ -396,8 +396,8 @@ class SearchControllerTest < Test::Unit::TestCase @@ -396,8 +396,8 @@ class SearchControllerTest < Test::Unit::TestCase
396 should 'list recent articles in the category' do 396 should 'list recent articles in the category' do
397 recent = [] 397 recent = []
398 finger = CategoryFinder.new(@category) 398 finger = CategoryFinder.new(@category)
399 - finger.expects(:recent).with(anything).at_least_once  
400 - finger.expects(:recent).with('articles').returns(recent) 399 + finger.expects(:recent).with(any_parameters).at_least_once
  400 + finger.expects(:recent).with('articles', anything).returns(recent)
401 CategoryFinder.expects(:new).with(@category).returns(finger) 401 CategoryFinder.expects(:new).with(@category).returns(finger)
402 402
403 get :category_index, :category_path => [ 'my-category' ] 403 get :category_index, :category_path => [ 'my-category' ]
@@ -417,8 +417,8 @@ class SearchControllerTest < Test::Unit::TestCase @@ -417,8 +417,8 @@ class SearchControllerTest < Test::Unit::TestCase
417 should 'list recently registered people in the category' do 417 should 'list recently registered people in the category' do
418 recent_people = [] 418 recent_people = []
419 finger = CategoryFinder.new(@category) 419 finger = CategoryFinder.new(@category)
420 - finger.expects(:recent).with(anything).at_least_once  
421 - finger.expects(:recent).with('people').returns(recent_people) 420 + finger.expects(:recent).with(any_parameters).at_least_once
  421 + finger.expects(:recent).with('people', kind_of(Integer)).returns(recent_people)
422 CategoryFinder.expects(:new).with(@category).returns(finger) 422 CategoryFinder.expects(:new).with(@category).returns(finger)
423 423
424 get :category_index, :category_path => [ 'my-category' ] 424 get :category_index, :category_path => [ 'my-category' ]
@@ -428,8 +428,8 @@ class SearchControllerTest < Test::Unit::TestCase @@ -428,8 +428,8 @@ class SearchControllerTest < Test::Unit::TestCase
428 should 'list recently registered communities in the category' do 428 should 'list recently registered communities in the category' do
429 recent_communities = [] 429 recent_communities = []
430 finger = CategoryFinder.new(@category) 430 finger = CategoryFinder.new(@category)
431 - finger.expects(:recent).with(anything).at_least_once  
432 - finger.expects(:recent).with('communities').returns(recent_communities) 431 + finger.expects(:recent).with(any_parameters).at_least_once
  432 + finger.expects(:recent).with('communities', anything).returns(recent_communities)
433 CategoryFinder.expects(:new).with(@category).returns(finger) 433 CategoryFinder.expects(:new).with(@category).returns(finger)
434 434
435 get :category_index, :category_path => [ 'my-category' ] 435 get :category_index, :category_path => [ 'my-category' ]
@@ -439,8 +439,8 @@ class SearchControllerTest < Test::Unit::TestCase @@ -439,8 +439,8 @@ class SearchControllerTest < Test::Unit::TestCase
439 should 'list recently registered enterprises in the category' do 439 should 'list recently registered enterprises in the category' do
440 recent_enterptises = [] 440 recent_enterptises = []
441 finger = CategoryFinder.new(@category) 441 finger = CategoryFinder.new(@category)
442 - finger.expects(:recent).with(anything).at_least_once  
443 - finger.expects(:recent).with('enterprises').returns(recent_enterptises) 442 + finger.expects(:recent).with(any_parameters).at_least_once
  443 + finger.expects(:recent).with('enterprises', anything).returns(recent_enterptises)
444 CategoryFinder.expects(:new).with(@category).returns(finger) 444 CategoryFinder.expects(:new).with(@category).returns(finger)
445 445
446 get :category_index, :category_path => [ 'my-category' ] 446 get :category_index, :category_path => [ 'my-category' ]
@@ -720,9 +720,9 @@ class SearchControllerTest < Test::Unit::TestCase @@ -720,9 +720,9 @@ class SearchControllerTest < Test::Unit::TestCase
720 cat1 = ProductCategory.create!(:name => 'pc test 1', :environment => Environment.default) 720 cat1 = ProductCategory.create!(:name => 'pc test 1', :environment => Environment.default)
721 cat2 = ProductCategory.create!(:name => 'pc test 2', :environment => Environment.default) 721 cat2 = ProductCategory.create!(:name => 'pc test 2', :environment => Environment.default)
722 ent = Enterprise.create!(:name => 'test ent', :identifier => 'test_ent') 722 ent = Enterprise.create!(:name => 'test ent', :identifier => 'test_ent')
723 - 723 +
724 cat1.products.create!(:name => 'prod test 1', :enterprise => ent) 724 cat1.products.create!(:name => 'prod test 1', :enterprise => ent)
725 - 725 +
726 get :index, :find_in => 'enterprises', :query => 'test' 726 get :index, :find_in => 'enterprises', :query => 'test'
727 727
728 assert_includes assigns(:categories_menu).map(&:first), cat1 728 assert_includes assigns(:categories_menu).map(&:first), cat1