main
 1require 'spec_helper'
 2
 3describe GeoLocationService do
 4	it "can get a location" do
 5		result = GeoLocationService.GetGeoLocation("Stampede Grounds, Calgary, Alberta")
 6		result.should_not be_nil
 7		result.should be_an_instance_of(GeoLocation)
 8	end
 9	
10	it "can get a correction location" do
11		result = GeoLocationService.GetGeoLocation("Stampede Grounds, Calgary, Alberta")
12		result.should_not be_nil
13		result.x.should_not be_nil
14		
15	end
16	
17	it "can get a location data" do
18		result = GeoLocationService.GetGeoLocationData("Stampede Grounds, Calgary, Alberta")
19		result.should_not be_nil
20	end
21	
22	it "can parse json result to get geolocation" do
23		json = GeoLocationService.GetGeoLocationData("Stampede Grounds, Calgary, Alberta")
24		result = GeoLocationService.ExtractGeoLocationFromJson(json)
25		result.should_not be_nil
26		result.should be_an_instance_of(GeoLocation)
27	end
28	
29	it "can get correct geo location for stampede grounds" do
30		result = GeoLocationService.GetGeoLocation("Stampede Grounds, Calgary, Alberta")
31		result.should be_an_instance_of(GeoLocation)
32		result.x.should be_within(0.0001).of(-114.0630194)
33		result.y.should be_within(0.0001).of(51.045220523)
34	end
35	
36	it "can look up by address" do
37		result = GeoLocationService.GetGeoLocation("200 E Randolph St, Chicago, IL")
38		result.should be_an_instance_of(GeoLocation)
39		result.x.should be_within(0.0001).of(-87.6221405679)
40		result.y.should be_within(0.0001).of(41.8845104628)
41	end
42
43        it "can look up by postal code" do 
44		result = GeoLocationService.GetGeoLocation("T2J0A3")
45		result.should be_an_instance_of(GeoLocation)
46		result.x.should be_within(0.0001).of(-114.06582942278891)
47		result.y.should be_within(0.0001).of(50.97218089773139)
48        end        
49
50        it "will return nil with an invalid postal code" do
51		result = GeoLocationService.GetGeoLocation("T2J0A")
52		result.should be_nil 
53        end
54end