Skip to content

Commit

Permalink
added [] accessor to Point
Browse files Browse the repository at this point in the history
  • Loading branch information
kristianmandrup committed May 31, 2012
1 parent d89e45c commit c7a7ae7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 0 additions & 2 deletions lib/mongoid_geospatial.rb
Expand Up @@ -10,8 +10,6 @@

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
Expand Down
Expand Up @@ -4,6 +4,10 @@ class SphericalPointImpl
def to_a
[x, y, z]
end

def [] index
to_a[index]
end
end
end
end
8 changes: 7 additions & 1 deletion spec/functional/mongoid_geospatial_spec.rb
Expand Up @@ -12,11 +12,17 @@
bar.location.should be_a RGeo::Geographic::SphericalPointImpl
end

it "should have a field mapped as point" 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 accept an RGeo object" do
point = RGeo::Geographic.spherical_factory.point 1, 2
bar = Bar.create!(location: point)
Expand Down

0 comments on commit c7a7ae7

Please sign in to comment.