Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

#1 try remove and load again to test

  • Loading branch information...
commit d931dab8d0edf1aaa0a9ddde7199ec5853a49183 1 parent 0f510b5
@nofxx nofxx authored
View
4 lib/mongoid_geospatial/wrappers/georuby.rb
@@ -11,6 +11,10 @@ def to_geo
GeoRuby::SimpleFeatures::Point.xy(x, y)
end
+ def distance other
+ to_geo.spherical_distance(other.to_geo)
+ end
+
def self.mongoize(obj)
case obj
when GeoRuby::SimpleFeatures::Point then [obj.x, obj.y]
View
5 lib/mongoid_geospatial/wrappers/rgeo.rb
@@ -5,12 +5,15 @@ module Mongoid
module Geospatial
class Point
- delegate :distance, :to => :to_geo
def to_geo
RGeo::Geographic.spherical_factory.point x, y
end
+ def distance other
+ to_geo.distance other.to_geo
+ end
+
def self.mongoize(obj)
case obj
when RGeo::Geographic::SphericalPointImpl then [obj.x, obj.y]
View
14 spec/mongoid_geospatial/wrappers/georuby_spec.rb
@@ -1,15 +1,21 @@
require "spec_helper"
-Mongoid::Geospatial::Point = Class.new
+
+Mongoid::Geospatial.send(:remove_const, 'Point')
load "#{File.dirname(__FILE__)}/../../../lib/mongoid_geospatial/fields/point.rb"
describe Mongoid::Geospatial::Point do
+ before do
+ Object.send(:remove_const, 'Place')
+ load "#{File.dirname(__FILE__)}/../../models/place.rb"
+ end
+
it "should not inferfer with mongoid" do
Place.create!(name: "Moe's")
Place.count.should eql(1)
end
- it "should not respond to distance before loading external" do
+ it "should not respond to distance before loading external gem" do
bar = Place.create!(location: [5,5])
bar.location.should_not respond_to(:distance)
end
@@ -18,8 +24,8 @@
describe "queryable" do
before do
- Place.create_indexes
Mongoid::Geospatial.use_georuby
+ Place.create_indexes
end
describe "(de)mongoize" do
@@ -48,7 +54,7 @@
it "should calculate 3d distances by default" do
bar = Place.create! location: [-73.77694444, 40.63861111 ]
bar2 = Place.create! location: [-118.40, 33.94] #,:unit=>:mi, :spherical => true)
- bar.location.distance(bar2.location.to_geo).to_i.should be_within(1).of(3978262)
+ bar.location.distance(bar2.location).to_i.should be_within(1).of(3973808)
end
end
View
11 spec/mongoid_geospatial/wrappers/rgeo_spec.rb
@@ -1,6 +1,13 @@
require "spec_helper"
+Mongoid::Geospatial.send(:remove_const, 'Point')
+load "#{File.dirname(__FILE__)}/../../../lib/mongoid_geospatial/fields/point.rb"
+
describe Mongoid::Geospatial::Point do
+ before do
+ Object.send(:remove_const, 'Bar')
+ load "#{File.dirname(__FILE__)}/../../models/bar.rb"
+ end
it "should not inferfer with mongoid" do
Bar.create!(name: "Moe's")
@@ -16,8 +23,8 @@
describe "queryable" do
before do
- Bar.create_indexes
Mongoid::Geospatial.use_rgeo
+ Bar.create_indexes
end
describe "(de)mongoize" do
@@ -46,7 +53,7 @@
it "should calculate 3d distances by default" do
bar = Bar.create! location: [-73.77694444, 40.63861111 ]
bar2 = Bar.create! location: [-118.40, 33.94] #,:unit=>:mi, :spherical => true)
- bar.location.distance(bar2.location.to_geo).to_i.should be_within(1).of(3978262)
+ bar.location.distance(bar2.location).to_i.should be_within(1).of(3978262)
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.