Permalink
Browse files

extend spherical_point_impl to better work with other gems that expec…

…t array
  • Loading branch information...
1 parent 1b8dfd9 commit d89e45c190dfea5822e794d2927180aa85664aaf @kristianmandrup committed May 30, 2012
View
@@ -5,8 +5,8 @@ gemspec
gem 'rgeo'
-# gem 'mongoid', '~> 2.4' # all specs pass on 2.4.10 :)
-gem 'mongoid', :git => 'git://github.com/mongoid/mongoid'
+gem 'mongoid', '~> 2.4' # all specs pass on 2.4.10 :)
+# gem 'mongoid', :git => 'git://github.com/mongoid/mongoid'
group :development do
gem 'rspec'
@@ -5,10 +5,13 @@
require 'mongoid_geospatial/contexts/mongo'
require 'mongoid_geospatial/criteria'
require 'mongoid_geospatial/extensions/symbol'
+require 'mongoid_geospatial/extensions/rgeo_spherical_point_impl'
require 'mongoid_geospatial/field_option'
fields_path = 'mongoid_geospatial/fields' + (Mongoid::VERSION > '3' ? '' : '/mongoid2')
+puts "fields_path: #{fields_path}"
+
%w{point polygon line_string}.each do |type|
require "#{fields_path}/#{type}"
end
@@ -0,0 +1,9 @@
+module RGeo
+ module Geographic
+ class SphericalPointImpl
+ def to_a
+ [x, y, z]
+ end
+ end
+ end
+end
@@ -12,6 +12,11 @@
bar.location.should be_a RGeo::Geographic::SphericalPointImpl
end
+ it "should have a field mapped as point" do
+ bar = Bar.create!(location: [3,2])
+ bar.location.to_a[0..1].should == [3.0, 2.0]
+ end
+
it "should accept an RGeo object" do
point = RGeo::Geographic.spherical_factory.point 1, 2
bar = Bar.create!(location: point)
View
@@ -4,6 +4,8 @@ class Bar
field :name, :type => String
field :location, :type => Point, :spatial => true
- references_one :rating, :as => :ratable
+
+ has_one :rating, :as => :ratable
+
spatial_index :location
end

0 comments on commit d89e45c

Please sign in to comment.