Skip to content
Snippets Groups Projects
Commit dd985747 authored by Alex Reisner's avatar Alex Reisner
Browse files

Add fixture for Google XML response, ActiveRecord::Base simulator, and two basic tests.

parent d197878f
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8" ?>
<kml xmlns="http://earth.google.com/kml/2.0"><Response>
<name>4 Penn Plaza, New York, NY</name>
<Status>
<code>200</code>
<request>geocode</request>
</Status>
<Placemark id="p1">
<address>4 Penn Plaza, New York, NY 10001, USA</address>
<AddressDetails Accuracy="8" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><CountryName>USA</CountryName><AdministrativeArea><AdministrativeAreaName>NY</AdministrativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>New York</SubAdministrativeAreaName><Locality><LocalityName>New York</LocalityName><Thoroughfare><ThoroughfareName>4 Penn Plaza</ThoroughfareName></Thoroughfare><PostalCode><PostalCodeNumber>10001</PostalCodeNumber></PostalCode></Locality></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails>
<ExtendedData>
<LatLonBox north="40.7527158" south="40.7464206" east="-73.9885076" west="-73.9948028" />
</ExtendedData>
<Point><coordinates>-73.9916733,40.7495760,0</coordinates></Point>
</Placemark>
</Response></kml>
require 'test_helper'
class GeocoderTest < Test::Unit::TestCase
# Replace this with your real tests.
def test_this_plugin
flunk
def test_fetch_coordinates
v = Venue.new(*venue_params(:msg))
assert_equal [40.7495760, -73.9916733], v.fetch_coordinates
end
def test_fetch_coordinates!
v = Venue.new(*venue_params(:msg))
v.fetch_coordinates!
assert_equal [40.7495760, -73.9916733], [v.latitude, v.longitude]
end
end
require 'rubygems'
require 'test/unit'
require 'activesupport'
$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
##
# Simulate enough of ActiveRecord::Base that objects can be used for testing.
#
module ActiveRecord
class Base
def initialize
@attributes = {}
end
def read_attribute(attr_name)
@attributes[attr_name.to_s]
end
def write_attribute(attr_name, value)
attr_name = attr_name.to_s
@attributes[attr_name] = value
end
def self.named_scope(*args); end
end
end
# Require Geocoder after ActiveRecord simulator.
require 'geocoder'
##
# Mock HTTP request to Google.
#
module Geocoder
def self._fetch_xml(query)
filename = File.join("test", "fixtures", "madison_square_garden.xml")
File.read(filename)
end
end
##
# Geocoded model.
#
class Venue < ActiveRecord::Base
geocoded_by :address
def initialize(name, address)
super()
write_attribute :name, name
write_attribute :address, address
end
# could implement these with method_missing
# to simulate custom lat/lon methods
def latitude; read_attribute(:latitude); end
def longitude; read_attribute(:longitude); end
end
class Test::Unit::TestCase
def venue_params(abbrev)
{
:msg => ["Madison Square Garden", "4 Penn Plaza, New York, NY"]
}[abbrev]
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment