From 6af4a830917d19ba60b7eec4b23ea865b5a9d1c3 Mon Sep 17 00:00:00 2001 From: MoisesMachado Date: Mon, 21 Jul 2008 21:10:21 +0000 Subject: [PATCH] ActionItem558: search for products georeferenced --- app/controllers/public/search_controller.rb | 7 +++---- test/functional/search_controller_test.rb | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/controllers/public/search_controller.rb b/app/controllers/public/search_controller.rb index a940344..88d9174 100644 --- a/app/controllers/public/search_controller.rb +++ b/app/controllers/public/search_controller.rb @@ -99,9 +99,8 @@ class SearchController < ApplicationController end def calculate_find_options(asset, limit, page, product_category, region, radius, year, month) - result = { :product_category => product_category, :per_page => limit, :page => page } - if [:enterprises, :people].include?(asset) && region + if [:enterprises, :people, :products].include?(asset) && region result.merge!(:within => radius, :region => region.id) end @@ -199,8 +198,8 @@ 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) ], - [ :most_commented_articles, _('Most commented articles'), @finder.most_commented_articles(limit) ] + [ :most_commented_articles, _('Most commented articles'), @finder.most_commented_articles(limit) ], + [ :articles, _('Articles'), @finder.recent('text_articles', limit) ] ].each do |key, name, list| @order << key @results[key] = list diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb index b9e7567..605b5e6 100644 --- a/test/functional/search_controller_test.rb +++ b/test/functional/search_controller_test.rb @@ -913,6 +913,21 @@ class SearchControllerTest < Test::Unit::TestCase assert_not_includes @controller.where_to_search.map(&:first), :products end + should 'search for products by origin and radius correctly' do + s = City.create!(:name => 'Salvador', :lat => -12.97, :lng => -38.51, :environment => Environment.default) + e1 = Enterprise.create!(:name => 'test ent 1', :identifier => 'test_ent1', :lat => -12.97, :lng => -38.51) + p1 = e1.products.create!(:name => 'test_product1') + e1.save! + e2 = Enterprise.create!(:name => 'test ent 2', :identifier => 'test_ent2', :lat => -14.97, :lng => -40.51) + p2 = e2.products.create!(:name => 'test_product2') + e2.save! + + get :assets, :asset => 'products', :city => s.id, :radius => 15 + + assert_includes assigns(:results)[:products], p1 + assert_not_includes assigns(:results)[:products], p2 + end + ################################################################## ################################################################## -- libgit2 0.21.2