Commit 6af4a830917d19ba60b7eec4b23ea865b5a9d1c3
1 parent
b25a3643
Exists in
master
and in
28 other branches
ActionItem558: search for products georeferenced
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2298 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
18 additions
and
4 deletions
Show diff stats
app/controllers/public/search_controller.rb
... | ... | @@ -99,9 +99,8 @@ class SearchController < ApplicationController |
99 | 99 | end |
100 | 100 | |
101 | 101 | def calculate_find_options(asset, limit, page, product_category, region, radius, year, month) |
102 | - | |
103 | 102 | result = { :product_category => product_category, :per_page => limit, :page => page } |
104 | - if [:enterprises, :people].include?(asset) && region | |
103 | + if [:enterprises, :people, :products].include?(asset) && region | |
105 | 104 | result.merge!(:within => radius, :region => region.id) |
106 | 105 | end |
107 | 106 | |
... | ... | @@ -199,8 +198,8 @@ class SearchController < ApplicationController |
199 | 198 | [ :products, ('Products'), @finder.recent('products', limit) ], |
200 | 199 | [ :events, _('Upcoming events'), @finder.upcoming_events({:per_page => limit}) ], |
201 | 200 | [ :communities, _('Communities'), @finder.recent('communities', limit) ], |
202 | - [ :articles, _('Articles'), @finder.recent('articles', limit) ], | |
203 | - [ :most_commented_articles, _('Most commented articles'), @finder.most_commented_articles(limit) ] | |
201 | + [ :most_commented_articles, _('Most commented articles'), @finder.most_commented_articles(limit) ], | |
202 | + [ :articles, _('Articles'), @finder.recent('text_articles', limit) ] | |
204 | 203 | ].each do |key, name, list| |
205 | 204 | @order << key |
206 | 205 | @results[key] = list | ... | ... |
test/functional/search_controller_test.rb
... | ... | @@ -913,6 +913,21 @@ class SearchControllerTest < Test::Unit::TestCase |
913 | 913 | assert_not_includes @controller.where_to_search.map(&:first), :products |
914 | 914 | end |
915 | 915 | |
916 | + should 'search for products by origin and radius correctly' do | |
917 | + s = City.create!(:name => 'Salvador', :lat => -12.97, :lng => -38.51, :environment => Environment.default) | |
918 | + e1 = Enterprise.create!(:name => 'test ent 1', :identifier => 'test_ent1', :lat => -12.97, :lng => -38.51) | |
919 | + p1 = e1.products.create!(:name => 'test_product1') | |
920 | + e1.save! | |
921 | + e2 = Enterprise.create!(:name => 'test ent 2', :identifier => 'test_ent2', :lat => -14.97, :lng => -40.51) | |
922 | + p2 = e2.products.create!(:name => 'test_product2') | |
923 | + e2.save! | |
924 | + | |
925 | + get :assets, :asset => 'products', :city => s.id, :radius => 15 | |
926 | + | |
927 | + assert_includes assigns(:results)[:products], p1 | |
928 | + assert_not_includes assigns(:results)[:products], p2 | |
929 | + end | |
930 | + | |
916 | 931 | ################################################################## |
917 | 932 | ################################################################## |
918 | 933 | ... | ... |