-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from mattvv/master
GeoPoint Support
- Loading branch information
Showing
4 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,19 @@ | |||
class ParseGeoPoint | |||
attr_accessor :latitude, :longitude | |||
|
|||
def initialize(hash=nil) | |||
if hash.nil? | |||
self.latitude=0.0 | |||
self.longitude=0.0 | |||
else | |||
self.latitude = hash["latitude"] || hash[:latitude] | |||
self.longitude = hash["longitude"] || hash[:longitude] | |||
end | |||
|
|||
end | |||
|
|||
def to_pointer | |||
{"__type"=>"GeoPoint", :latitude=> self.latitude, :longitude => self.longitude} | |||
end | |||
|
|||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,43 @@ | |||
require 'helper' | |||
require 'parse_resource' | |||
|
|||
ParseResource::Base.load!(ENV["PARSE_RESOURCE_APPLICATION_ID"], ENV["PARSE_RESOURCE_MASTER_KEY"]) | |||
|
|||
class Place < ParseResource::Base | |||
fields :name, :location | |||
end | |||
|
|||
class TestParseResource < Test::Unit::TestCase | |||
|
|||
def test_saving_geopoint_with_coords | |||
Place.destroy_all | |||
place = Place.new | |||
place.name = "Office" | |||
place.location = ParseGeoPoint.new | |||
place.location.latitude = 34.09300844216167 | |||
place.location.longitude = -118.3780094460731 | |||
place.save | |||
assert_equal Place.count, 1 | |||
end | |||
|
|||
def test_saving_geo_point_with_quick_init | |||
Place.destroy_all | |||
place = Place.new | |||
place.location = ParseGeoPoint.new :latitude => 34.09300844216167, :longitude => -118.3780094460731 | |||
place.save | |||
assert_equal Place.count, 1 | |||
end | |||
|
|||
def test_fetching_geopoint_field | |||
Place.destroy_all | |||
place = Place.new | |||
place.location = ParseGeoPoint.new :latitude => 34.09300844216167, :longitude => -118.3780094460731 | |||
place.save | |||
assert_equal Place.count, 1 | |||
|
|||
server_place = Place.find(place.objectId) | |||
assert_equal server_place.location.latitude, 34.09300844216167 | |||
assert_equal server_place.location.longitude, -118.3780094460731 | |||
end | |||
|
|||
end |