Commit 2519b304051222985c691154bcf089af3f0dc85b
1 parent
f86661c9
Exists in
master
and in
29 other branches
ActionItem129: added specifing a region instead of raw latitude an longitude
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1781 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
47 additions
and
2 deletions
Show diff stats
app/controllers/public/search_controller.rb
... | ... | @@ -127,8 +127,12 @@ class SearchController < ApplicationController |
127 | 127 | @product_category = ProductCategory.find(params[:category]) if params[:category] |
128 | 128 | @region = Region.find(params[:region]) if params[:region] |
129 | 129 | options = {} |
130 | - options.merge!({:include => :products, :conditions => ['products.product_category_id = ?', @product_category.id]}) if @product_category | |
131 | - options.merge!({:origin => [params[:lat].to_f, params[:long].to_f], :within => params[:radius] }) if params[:lat] && params[:long] && params[:radius] | |
130 | + options.merge! :include => :products, :conditions => ['products.product_category_id = ?', @product_category.id] if @product_category | |
131 | + | |
132 | + options.merge! :origin => [params[:lat].to_f, params[:long].to_f], :within => params[:radius] if !params[:lat].blank? && !params[:long].blank? && !params[:radius].blank? | |
133 | + | |
134 | + options.merge! :origin => [@region.lat, @region.lng], :within => params[:radius] if !params[:region].blank? && !params[:radius].blank? | |
135 | + | |
132 | 136 | @enterprises = Enterprise.find(:all, options) |
133 | 137 | end |
134 | 138 | ... | ... |
test/functional/search_controller_test.rb
... | ... | @@ -792,6 +792,47 @@ class SearchControllerTest < Test::Unit::TestCase |
792 | 792 | assert_not_includes assigns('enterprises'), ent2 |
793 | 793 | end |
794 | 794 | |
795 | + should 'find enterprise by an region with georeference' do | |
796 | + region = Region.create!(:name => 'r-test', :environment => Environment.default, :lat => 45.0, :lng => 45.0) | |
797 | + ent1 = Enterprise.create!(:name => 'test1', :identifier => 'test1', :lat => 45.0, :lng => 45.0) | |
798 | + ent2 = Enterprise.create!(:name => 'test2', :identifier => 'test2', :lat => 30.0, :lng => 30.0) | |
799 | + | |
800 | + get :sellers, :region => region.id, :radius => 10 | |
801 | + | |
802 | + assert_includes assigns('enterprises'), ent1 | |
803 | + assert_not_includes assigns('enterprises'), ent2 | |
804 | + end | |
805 | + | |
806 | + should 'find enterprise by region and product category' do | |
807 | + region = Region.create!(:name => 'r-test', :environment => Environment.default, :lat => 45.0, :lng => 45.0) | |
808 | + ent1 = Enterprise.create!(:name => 'test1', :identifier => 'test1', :lat => 45.0, :lng => 45.0) | |
809 | + prod_cat = ProductCategory.create!(:name => 'pc-test', :environment => Environment.default) | |
810 | + prod = ent1.products.create!(:name => 'teste', :product_category => prod_cat) | |
811 | + | |
812 | + ent2 = Enterprise.create!(:name => 'test2', :identifier => 'test2', :lat => 30.0, :lng => 30.0) | |
813 | + | |
814 | + get :sellers, :region => region.id, :radius => 10, :category => prod_cat.id | |
815 | + | |
816 | + assert_includes assigns('enterprises'), ent1 | |
817 | + assert_not_includes assigns('enterprises'), ent2 | |
818 | + end | |
819 | + | |
820 | + should 'find enterprise by region and product category in brazilian portuguese' do | |
821 | + region = Region.create!(:name => 'r-test', :environment => Environment.default, :lat => 45.0, :lng => 45.0) | |
822 | + ent1 = Enterprise.create!(:name => 'test1', :identifier => 'test1', :lat => 45.0, :lng => 45.0) | |
823 | + prod_cat = ProductCategory.create!(:name => 'pc-test', :environment => Environment.default) | |
824 | + prod = ent1.products.create!(:name => 'teste', :product_category => prod_cat) | |
825 | + | |
826 | + ent2 = Enterprise.create!(:name => 'test2', :identifier => 'test2', :lat => 30.0, :lng => 30.0) | |
827 | + | |
828 | + assert_nothing_raised do | |
829 | + get :sellers, :region => region.id, :radius => 10, :category => prod_cat.id, :lang => 'pt_BR' | |
830 | + end | |
831 | + | |
832 | + assert_includes assigns('enterprises'), ent1 | |
833 | + assert_not_includes assigns('enterprises'), ent2 | |
834 | + end | |
835 | + | |
795 | 836 | should 'not show term "Category:" before product category' do |
796 | 837 | Profile.delete_all |
797 | 838 | ent = Enterprise.create!(:name => 'teste1', :identifier => 'teste1') | ... | ... |