From 2519b304051222985c691154bcf089af3f0dc85b Mon Sep 17 00:00:00 2001 From: MoisesMachado Date: Wed, 7 May 2008 15:44:50 +0000 Subject: [PATCH] ActionItem129: added specifing a region instead of raw latitude an longitude --- app/controllers/public/search_controller.rb | 8 ++++++-- test/functional/search_controller_test.rb | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/app/controllers/public/search_controller.rb b/app/controllers/public/search_controller.rb index d2ced2c..bbaecbb 100644 --- a/app/controllers/public/search_controller.rb +++ b/app/controllers/public/search_controller.rb @@ -127,8 +127,12 @@ class SearchController < ApplicationController @product_category = ProductCategory.find(params[:category]) if params[:category] @region = Region.find(params[:region]) if params[:region] options = {} - options.merge!({:include => :products, :conditions => ['products.product_category_id = ?', @product_category.id]}) if @product_category - options.merge!({:origin => [params[:lat].to_f, params[:long].to_f], :within => params[:radius] }) if params[:lat] && params[:long] && params[:radius] + options.merge! :include => :products, :conditions => ['products.product_category_id = ?', @product_category.id] if @product_category + + options.merge! :origin => [params[:lat].to_f, params[:long].to_f], :within => params[:radius] if !params[:lat].blank? && !params[:long].blank? && !params[:radius].blank? + + options.merge! :origin => [@region.lat, @region.lng], :within => params[:radius] if !params[:region].blank? && !params[:radius].blank? + @enterprises = Enterprise.find(:all, options) end diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb index 4650e5f..3025c4b 100644 --- a/test/functional/search_controller_test.rb +++ b/test/functional/search_controller_test.rb @@ -792,6 +792,47 @@ class SearchControllerTest < Test::Unit::TestCase assert_not_includes assigns('enterprises'), ent2 end + should 'find enterprise by an region with georeference' do + region = Region.create!(:name => 'r-test', :environment => Environment.default, :lat => 45.0, :lng => 45.0) + ent1 = Enterprise.create!(:name => 'test1', :identifier => 'test1', :lat => 45.0, :lng => 45.0) + ent2 = Enterprise.create!(:name => 'test2', :identifier => 'test2', :lat => 30.0, :lng => 30.0) + + get :sellers, :region => region.id, :radius => 10 + + assert_includes assigns('enterprises'), ent1 + assert_not_includes assigns('enterprises'), ent2 + end + + should 'find enterprise by region and product category' do + region = Region.create!(:name => 'r-test', :environment => Environment.default, :lat => 45.0, :lng => 45.0) + ent1 = Enterprise.create!(:name => 'test1', :identifier => 'test1', :lat => 45.0, :lng => 45.0) + prod_cat = ProductCategory.create!(:name => 'pc-test', :environment => Environment.default) + prod = ent1.products.create!(:name => 'teste', :product_category => prod_cat) + + ent2 = Enterprise.create!(:name => 'test2', :identifier => 'test2', :lat => 30.0, :lng => 30.0) + + get :sellers, :region => region.id, :radius => 10, :category => prod_cat.id + + assert_includes assigns('enterprises'), ent1 + assert_not_includes assigns('enterprises'), ent2 + end + + should 'find enterprise by region and product category in brazilian portuguese' do + region = Region.create!(:name => 'r-test', :environment => Environment.default, :lat => 45.0, :lng => 45.0) + ent1 = Enterprise.create!(:name => 'test1', :identifier => 'test1', :lat => 45.0, :lng => 45.0) + prod_cat = ProductCategory.create!(:name => 'pc-test', :environment => Environment.default) + prod = ent1.products.create!(:name => 'teste', :product_category => prod_cat) + + ent2 = Enterprise.create!(:name => 'test2', :identifier => 'test2', :lat => 30.0, :lng => 30.0) + + assert_nothing_raised do + get :sellers, :region => region.id, :radius => 10, :category => prod_cat.id, :lang => 'pt_BR' + end + + assert_includes assigns('enterprises'), ent1 + assert_not_includes assigns('enterprises'), ent2 + end + should 'not show term "Category:" before product category' do Profile.delete_all ent = Enterprise.create!(:name => 'teste1', :identifier => 'teste1') -- libgit2 0.21.2