forked from mongoid/mongoid-geospatial
/
rgeo_spec.rb
48 lines (38 loc) · 1.42 KB
/
rgeo_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require "spec_helper"
describe Mongoid::Geospatial::Point do
it "should not inferfer with mongoid" do
Bar.create!(name: "Moe's")
Bar.count.should eql(1)
end
describe "queryable" do
before do
Bar.create_indexes
Mongoid::Geospatial.use_rgeo
end
describe "(de)mongoize" do
it "should mongoize array" do
geom = Bar.new(location: [10, -9]).location
geom.class.should eql(Mongoid::Geospatial::Point)
geom.to_geo.class.should eql(RGeo::Geographic::SphericalPointImpl)
geom.x.should be_within(0.1).of(10)
geom.to_geo.y.should be_within(0.1).of(-9)
end
it "should mongoize hash" do
geom = Bar.new(location: {x: 10, y: -9}).location
geom.class.should eql(Mongoid::Geospatial::Point)
geom.to_geo.class.should eql(RGeo::Geographic::SphericalPointImpl)
end
it "should accept an RGeo object" do
point = RGeo::Geographic.spherical_factory.point 1, 2
bar = Bar.create!(location: point)
bar.location.x.should be_within(0.1).of(1)
bar.location.y.should be_within(0.1).of(2)
end
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_i.should be_within(1).of(2469)
end
end
end
end