mongoid_geospatial 2.0.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -1
- data/README.md +84 -60
- data/lib/mongoid_geospatial.rb +3 -7
- data/lib/mongoid_geospatial/{geospatial → extensions}/core_ext.rb +0 -0
- data/lib/mongoid_geospatial/field_option.rb +3 -4
- data/lib/mongoid_geospatial/fields/geometry_field.rb +34 -0
- data/lib/mongoid_geospatial/fields/line_string.rb +5 -7
- data/lib/mongoid_geospatial/fields/point.rb +18 -33
- data/lib/mongoid_geospatial/fields/polygon.rb +6 -14
- data/lib/mongoid_geospatial/geospatial.rb +20 -25
- data/lib/mongoid_geospatial/version.rb +1 -1
- data/lib/mongoid_geospatial/wrappers/georuby.rb +28 -0
- data/lib/mongoid_geospatial/wrappers/rgeo.rb +32 -0
- data/spec/models/farm.rb +5 -2
- data/spec/models/person.rb +4 -14
- data/spec/models/phone.rb +1 -3
- data/spec/mongoid_geospatial/extensions/core_ext_spec.rb +20 -0
- data/spec/mongoid_geospatial/field_option_spec.rb +11 -0
- data/spec/mongoid_geospatial/fields/line_string_spec.rb +40 -0
- data/spec/mongoid_geospatial/fields/point_spec.rb +136 -10
- data/spec/mongoid_geospatial/fields/polygon_spec.rb +75 -0
- data/spec/mongoid_geospatial/geospatial_spec.rb +88 -3
- data/spec/mongoid_geospatial/wrappers/rgeo_spec.rb +43 -0
- data/spec/spec_helper.rb +5 -21
- metadata +14 -26
- data/lib/mongoid_geospatial/contextual/mongo.rb +0 -118
- data/lib/mongoid_geospatial/criteria.rb +0 -10
- data/lib/mongoid_geospatial/criterion/complex.rb +0 -26
- data/lib/mongoid_geospatial/criterion/inclusion.rb +0 -14
- data/lib/mongoid_geospatial/criterion/near_spatial.rb +0 -52
- data/lib/mongoid_geospatial/criterion/within_spatial.rb +0 -62
- data/lib/mongoid_geospatial/extensions/symbol.rb +0 -46
- data/lib/mongoid_geospatial/finders.rb +0 -5
- data/lib/mongoid_geospatial/geospatial/geo_near_results.rb +0 -140
- data/spec/mongoid_geospatial/contextual/mongo_spec.rb +0 -135
- data/spec/mongoid_geospatial/criterion/complex_spec.rb +0 -15
- data/spec/mongoid_geospatial/criterion/inclusion_spec.rb +0 -375
- data/spec/mongoid_geospatial/criterion/near_spatial_spec.rb +0 -39
- data/spec/mongoid_geospatial/criterion/within_spatial_spec.rb +0 -54
- data/spec/mongoid_geospatial/geospatial/geo_near_results_spec.rb +0 -78
- data/spec/mongoid_geospatial/mongoid_geospatial_spec.rb +0 -83
@@ -1,78 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Mongoid::Geospatial::GeoNearResults do
|
4
|
-
before do
|
5
|
-
Bar.delete_all
|
6
|
-
Bar.create_indexes
|
7
|
-
|
8
|
-
50.times do |i|
|
9
|
-
Bar.create!(:name => i.to_s, :location => [rand(358)-179,rand(358)-179])
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
context ":paginator :array" do
|
16
|
-
let(:bars) { Bar.geo_near([1,1]) }
|
17
|
-
let(:sorted_bars) {
|
18
|
-
bars = Bar.geo_near([1,1])
|
19
|
-
bars.sort_by! {|b| b.name.to_i}
|
20
|
-
bars
|
21
|
-
}
|
22
|
-
[nil,1,2].each do |page|
|
23
|
-
it "page=#{page} should have 25" do
|
24
|
-
bars.page(page).size.should == 25
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
[1,2].each do |page|
|
29
|
-
it "modified result should keep order after pagination" do
|
30
|
-
sorted_bars.page(page).should == sorted_bars.slice((page-1)*25,25)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
{ nil => 25, 20 => 20 , 30 => 20, 50 => 0}.each do |per, total|
|
35
|
-
it "page=2 per=#{per} should have #{total}" do
|
36
|
-
bars.per(per).page(2).size.should == total
|
37
|
-
bars.page(2).per(per).size.should == total
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
it "page=3 should have 0" do
|
42
|
-
bars.page(3).size.should == 0
|
43
|
-
end
|
44
|
-
|
45
|
-
it "per=5" do
|
46
|
-
bars.per(5).size.should == 5
|
47
|
-
end
|
48
|
-
|
49
|
-
it "page=10 per=5" do
|
50
|
-
bars.per(5).page(10).should == bars[45..50]
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
context ":paginator :kaminari" do
|
56
|
-
let!(:near) {Bar.geo_near([1,1]).page(1)}
|
57
|
-
it "should have current_page" do
|
58
|
-
near.current_page.should == 1
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should have num_pages" do
|
62
|
-
near.total_entries.should == 50
|
63
|
-
near.num_pages.should == 2
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should have limit_value" do
|
67
|
-
near.limit_value.should == 25
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
|
72
|
-
context ":paginator :num_pages" do
|
73
|
-
it "when total=55 per=10 ,num_pages should be 6" do
|
74
|
-
5.times { |i| Bar.create(:name => i.to_s, :location => [rand(358)-179,rand(358)-179]) }
|
75
|
-
Bar.geo_near([1,1]).per(10).num_pages.should == 6
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
@@ -1,83 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Mongoid::Geospatial do
|
4
|
-
|
5
|
-
it "should not inferfer with mongoid" do
|
6
|
-
Bar.create!(name: "Moe's")
|
7
|
-
Bar.count.should eql(1)
|
8
|
-
end
|
9
|
-
|
10
|
-
describe "fields" do
|
11
|
-
|
12
|
-
it "should have a field mapped as point" do
|
13
|
-
bar = Bar.create!(location: [5,5])
|
14
|
-
bar.location.should be_a RGeo::Geographic::SphericalPointImpl
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should support a field mapped as linestring" do
|
18
|
-
river = River.create!(source: [[5,5],[6,5],[6,6],[5,6]])
|
19
|
-
river.source.should be_a RGeo::Geographic::SphericalPolygonImpl
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should support a field mapped as polygon" do
|
23
|
-
farm = Farm.create!(area: [[5,5],[6,5],[6,6],[5,6]])
|
24
|
-
farm.area.should be_a RGeo::Geographic::SphericalPolygonImpl
|
25
|
-
end
|
26
|
-
|
27
|
-
|
28
|
-
it "should accept an RGeo object" do
|
29
|
-
point = RGeo::Geographic.spherical_factory.point 1, 2
|
30
|
-
bar = Bar.create!(location: point)
|
31
|
-
bar.location.x.should be_within(0.1).of(1)
|
32
|
-
bar.location.y.should be_within(0.1).of(2)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe "methods" do
|
37
|
-
|
38
|
-
it "should have a .to_a" do
|
39
|
-
bar = Bar.create!(location: [3,2])
|
40
|
-
bar.location.to_a[0..1].should == [3.0, 2.0]
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should have an array [] accessor" do
|
44
|
-
bar = Bar.create!(location: [3,2])
|
45
|
-
bar.location[0].should == 3.0
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should have an ActiveModel symbol accessor" do
|
49
|
-
bar = Bar.create!(location: [3,2])
|
50
|
-
bar[:location].should == [3,2]
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
|
56
|
-
it "should calculate distance between points" do
|
57
|
-
bar = Bar.create!(location: [5,5])
|
58
|
-
bar2 = Bar.create!(location: [15,15])
|
59
|
-
bar.location.distance(bar2.location).should be_within(1).of(1561283.8)
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should calculate distance between points miles" do
|
63
|
-
pending
|
64
|
-
bar = Bar.create!(location: [5,5])
|
65
|
-
bar2 = Bar.create!(location: [15,15])
|
66
|
-
bar.location.distance(bar2.location).should be_within(1).of(1561283.8)
|
67
|
-
end
|
68
|
-
|
69
|
-
it "should calculate 3d distances by default" do
|
70
|
-
bar = Bar.create! location: [-73.77694444, 40.63861111 ]
|
71
|
-
bar2 = Bar.create! location: [-118.40, 33.94] #,:unit=>:mi, :spherical => true)
|
72
|
-
bar.location.distance(bar2.location).to_i.should be_within(1).of(2469)
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should have a nice simple way to ovewrite geo factory" do
|
76
|
-
pending
|
77
|
-
bar = Bar.create!(location: [5,5])
|
78
|
-
bar2 = Bar.create!(location: [15,15])
|
79
|
-
bar.location.distance(bar2.location).should be_within(1).of(1561283.8)
|
80
|
-
end
|
81
|
-
|
82
|
-
|
83
|
-
end
|