Commit 8e78f277356f11caa0ad19f9e4b38c8bc41ae45e

Authored by Thiago Ribeiro
Committed by Rodrigo Souto
1 parent ef7c2df9

Fix broken tests in sniffer plugin.

Using method in lib/noosfero/geo_ref.rb instead of old method.

Signed-off-by: Marcos Ronaldo <marcos.rpj2@gmail.com>
Signed-off-by: Thiago Ribeiro <thiagitosouza@gmail.com>
plugins/sniffer/controllers/sniffer_plugin_myprofile_controller.rb
... ... @@ -38,7 +38,7 @@ class SnifferPluginMyprofileController &lt; MyProfileController
38 38 response[:enterprises] = product_category.sniffer_plugin_enterprises.enabled.visible.map do |enterprise|
39 39 profile_data = filter_visible_attr_profile(enterprise)
40 40 profile_data[:balloonUrl] = url_for :controller => :sniffer_plugin_myprofile, :action => :map_balloon, :id => enterprise[:id], :escape => false
41   - profile_data[:sniffer_plugin_distance] = distance_between_profiles(@profile, enterprise)
  41 + profile_data[:sniffer_plugin_distance] = Noosfero::GeoRef.dist(@profile.lat, @profile.lng, enterprise.lat, enterprise.lng)
42 42 profile_data[:suppliersProducts] = filter_visible_attr_suppliers_products(
43 43 enterprise.products.sniffer_plugin_products_from_category(product_category)
44 44 )
... ... @@ -109,7 +109,7 @@ class SnifferPluginMyprofileController &lt; MyProfileController
109 109 profiles = Profile.all :conditions => {:id => products.map { |p| target_profile_id(p) }}
110 110 profiles_by_id = {}
111 111 profiles.each do |p|
112   - p[:sniffer_plugin_distance] = distance_between_profiles(@profile, p)
  112 + p[:sniffer_plugin_distance] = Noosfero::GeoRef.dist(@profile.lat, @profile.lng, p.lat, p.lng)
113 113 profiles_by_id[p.id] ||= p
114 114 end
115 115 profiles_by_id
... ...
plugins/sniffer/lib/sniffer_plugin/helper.rb
... ... @@ -2,13 +2,6 @@ module SnifferPlugin::Helper
2 2  
3 3 include Noosfero::GeoRef
4 4  
5   - def distance_between_profiles(source, target)
6   - Math.sqrt(
7   - (KM_LAT * ((target.lat || 0) - (source.lat || 0)))**2 +
8   - (KM_LNG * ((target.lng || 0) - (source.lng || 0)))**2
9   - )
10   - end
11   -
12 5 def filter_visible_attr_profile(profile)
13 6 filtered_profile = {}
14 7 visible_attributes = [:id, :name, :lat, :lng, :sniffer_plugin_distance]
... ...