Permalink
Browse files

spec fixes

  • Loading branch information...
nofxx committed Sep 11, 2012
1 parent 91185ba commit 9fc555f35a94a1921826220f788d6e0e7d4d4d16
Showing with 44 additions and 60 deletions.
  1. +2 −2 spec/models/bar.rb
  2. +2 −2 spec/models/river.rb
  3. +40 −22 spec/mongoid_geospatial/mongoid_geospatial_spec.rb
  4. +0 −34 spec/mongoid_setup.rb
View
@@ -4,8 +4,8 @@ class Bar
field :name, :type => String
field :location, :type => Point, :spatial => true
-
- has_one :rating, :as => :ratable
+
+ has_one :rating, :as => :ratable
spatial_index :location
end
View
@@ -5,9 +5,9 @@ class River
field :name, type: String
field :length, type: Integer
field :average_discharge, type: Integer
- field :source, type: Array, spatial: true
+ field :source, type: LineString, spatial: true
# set return_array to true if you do not want a hash returned all the time
- field :mouth, type: Array, spatial: {lat: 'latitude', lng: 'longitude'}
+ field :mouth, type: Point, spatial: {lat: 'latitude', lng: 'longitude'}
field :mouth_array, type: Array, spatial: {return_array: true}
# simplified spatial indexing
@@ -2,34 +2,57 @@
describe Mongoid::Geospatial do
- it "should instantiate with no problems" do
+ it "should not inferfer with mongoid" do
Bar.create!(name: "Moe's")
Bar.count.should eql(1)
end
- it "should have a field mapped as point" do
- bar = Bar.create!(location: [5,5])
- bar.location.should be_a RGeo::Geographic::SphericalPointImpl
- end
+ describe "fields" do
+
+ it "should have a field mapped as point" do
+ bar = Bar.create!(location: [5,5])
+ bar.location.should be_a RGeo::Geographic::SphericalPointImpl
+ end
+
+ it "should support a field mapped as linestring" do
+ river = River.create!(source: [[5,5],[6,5],[6,6],[5,6]])
+ river.source.should be_a RGeo::Geographic::SphericalPolygonImpl
+ end
+
+ it "should support a field mapped as polygon" do
+ farm = Farm.create!(area: [[5,5],[6,5],[6,6],[5,6]])
+ farm.area.should be_a RGeo::Geographic::SphericalPolygonImpl
+ end
- it "should have a .to_a" do
- bar = Bar.create!(location: [3,2])
- bar.location.to_a[0..1].should == [3.0, 2.0]
- end
- it "should have an array [] accessor" do
- bar = Bar.create!(location: [3,2])
- bar.location[0].should == 3.0
+ 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
end
+ describe "methods" do
+
+ it "should have a .to_a" do
+ bar = Bar.create!(location: [3,2])
+ bar.location.to_a[0..1].should == [3.0, 2.0]
+ end
+
+ it "should have an array [] accessor" do
+ bar = Bar.create!(location: [3,2])
+ bar.location[0].should == 3.0
+ end
+
+ it "should have an ActiveModel symbol accessor" do
+ bar = Bar.create!(location: [3,2])
+ bar[:location].should == [3,2]
+ 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 distance between points" do
bar = Bar.create!(location: [5,5])
bar2 = Bar.create!(location: [15,15])
@@ -56,10 +79,5 @@
bar.location.distance(bar2.location).should be_within(1).of(1561283.8)
end
- it "should support a field mapped as polygon" do
- farm = Farm.create!(area: [[5,5],[6,5],[6,6],[5,6]])
- farm.area.should be_a RGeo::Geographic::SphericalPolygonImpl
- end
-
end
View
@@ -1,34 +0,0 @@
-module Mongoid
- module VersionSetup
- def self.configure config
- version = Mongoid::VERSION
- case
- when version < '2'
- raise ArgumentError, "Mongoid versions < 2 not supported"
- when version < '3'
- version_2 config
- when version > '3'
- version_3 config
- end
- end
-
- def self.version_3 config
- config.connect_to('mongoid_geo_test')
- end
-
- def self.version_2 config
- opts = YAML.load(File.read(File.dirname(__FILE__) + '/support/mongoid.yml'))["test"]
- opts.delete("slaves") # no slaves support for version < 3
- name = opts.delete("database")
- host = opts.delete("host")
- port = opts.delete("port")
- config.master = begin
- Mongo::Connection.new(host, port, opts).db(name)
- rescue Mongo::ConnectionFailure
- Mongo::Connection.new(host, '27017', opts).db(name)
- end
- config.logger = nil
- config.allow_dynamic_fields = true
- end
- end
-end

0 comments on commit 9fc555f

Please sign in to comment.