spec/query_spec.rb in attack-barometer-0.1.0 vs spec/query_spec.rb in attack-barometer-0.2.3
- old
+ new
@@ -5,10 +5,11 @@
before(:each) do
@zipcode = "90210"
@postal_code = "T5B 4M9"
@coordinates = "40.756054,-73.986951"
@geocode = "New York, NY"
+ @icao = "KSFO"
# actual conversions
@zipcode_to_coordinates = "34.1030032,-118.4104684"
@zipcode_to_geocode = "Beverly Hills, CA, USA"
@postalcode_to_coordinates = "53.570447,-113.456083"
@@ -24,24 +25,34 @@
it "detects a zipcode" do
Barometer::Query.is_us_zipcode?(@zipcode).should be_true
Barometer::Query.is_us_zipcode?(@postal_code).should be_false
Barometer::Query.is_us_zipcode?(@coordinates).should be_false
+ Barometer::Query.is_coordinates?(@icao).should be_false
end
it "detects a postalcode" do
Barometer::Query.is_canadian_postcode?(@postal_code).should be_true
Barometer::Query.is_canadian_postcode?(@zipcode).should be_false
Barometer::Query.is_canadian_postcode?(@coordinates).should be_false
+ Barometer::Query.is_coordinates?(@icao).should be_false
end
it "detects a coordinates" do
Barometer::Query.is_coordinates?(@coordinates).should be_true
Barometer::Query.is_coordinates?(@zipcode).should be_false
Barometer::Query.is_coordinates?(@postal_code).should be_false
+ Barometer::Query.is_coordinates?(@icao).should be_false
end
+ it "detects an ICAO" do
+ Barometer::Query.is_icao?(@coordinates).should be_false
+ Barometer::Query.is_icao?(@zipcode).should be_false
+ Barometer::Query.is_icao?(@postal_code).should be_false
+ Barometer::Query.is_icao?(@icao).should be_true
+ end
+
end
describe "determines the query format" do
before(:each) do
@@ -56,10 +67,11 @@
@query.format.to_sym.should == :zipcode
@query.country_code.should == "US"
@query.zipcode?.should be_true
@query.postalcode?.should be_false
+ @query.icao?.should be_false
@query.coordinates?.should be_false
@query.geocode?.should be_false
end
it "recognizes a postal code" do
@@ -69,23 +81,39 @@
@query.format.to_sym.should == :postalcode
@query.country_code.should == "CA"
@query.zipcode?.should be_false
@query.postalcode?.should be_true
+ @query.icao?.should be_false
@query.coordinates?.should be_false
@query.geocode?.should be_false
end
+ it "recognizes icao" do
+ @query.q = @icao
+ @query.format.should be_nil
+ @query.analyze!
+ @query.format.to_sym.should == :icao
+
+ @query.country_code.should be_nil
+ @query.zipcode?.should be_false
+ @query.postalcode?.should be_false
+ @query.icao?.should be_true
+ @query.coordinates?.should be_false
+ @query.geocode?.should be_false
+ end
+
it "recognizes latitude/longitude" do
@query.q = @coordinates
@query.format.should be_nil
@query.analyze!
@query.format.to_sym.should == :coordinates
@query.country_code.should be_nil
@query.zipcode?.should be_false
@query.postalcode?.should be_false
+ @query.icao?.should be_false
@query.coordinates?.should be_true
@query.geocode?.should be_false
end
it "defaults to a general geo_location" do
@@ -95,10 +123,11 @@
@query.format.to_sym.should == :geocode
@query.country_code.should be_nil
@query.zipcode?.should be_false
@query.postalcode?.should be_false
+ @query.icao?.should be_false
@query.coordinates?.should be_false
@query.geocode?.should be_true
end
end
@@ -166,11 +195,11 @@
if use_graticule
describe "when converting queries" do
before(:each) do
- @key = "ABQIAAAAq8TH4offRcGrok8JVY_MyxRi_j0U6kJrkFvY4-OX2XYmEAa76BSFwMlSow1YgX8BOPUeve_shMG7xw"
+ @key = KEY
url_start = "http://maps.google.com/maps/geo?"
#
# for Graticule and/or HTTParty geocoding
#
FakeWeb.register_uri(:get,
@@ -219,10 +248,17 @@
:string => File.read(File.join(File.dirname(__FILE__),
'fixtures',
'geocode_40_73.xml')
)
)
+ FakeWeb.register_uri(:get,
+ "#{url_start}output=xml&q=KSFO&gl=&key=#{@key}",
+ :string => File.read(File.join(File.dirname(__FILE__),
+ 'fixtures',
+ 'geocode_ksfo.xml')
+ )
+ )
end
describe "to coordinates," do
before(:each) do
@@ -251,10 +287,14 @@
it "converts from postalcode" do
Barometer::Query.to_coordinates(@postal_code, :postalcode).first.should == "53.570447,-113.456083"
end
+ it "converts from icao" do
+ Barometer::Query.to_coordinates(@icao, :icao).first.should == "37.615223,-122.389979"
+ end
+
end
describe "to geocode" do
before(:each) do
@@ -273,10 +313,14 @@
it "converts from postalcode" do
Barometer::Query.to_geocode(@postal_code, :postalcode).first.should == @postal_code
end
+ it "converts from icao" do
+ Barometer::Query.to_geocode(@icao, :icao).first.should == "San Francisco Airport, USA"
+ end
+
end
describe "when Graticule disabled," do
it "uses coordinates" do
@@ -355,11 +399,11 @@
describe "with an intial format of :zipcode," do
before(:each) do
@query = Barometer::Query.new(@zipcode)
- Barometer::Query.google_geocode_key = "ABQIAAAAq8TH4offRcGrok8JVY_MyxRi_j0U6kJrkFvY4-OX2XYmEAa76BSFwMlSow1YgX8BOPUeve_shMG7xw"
+ Barometer::Query.google_geocode_key = KEY
end
it "converts to coordinates" do
acceptable_formats = [:coordinates]
@query.convert!(acceptable_formats).should == @zipcode_to_coordinates
@@ -382,11 +426,11 @@
describe "with an intial format of :postalcode," do
before(:each) do
@query = Barometer::Query.new(@postal_code)
- Barometer::Query.google_geocode_key = "ABQIAAAAq8TH4offRcGrok8JVY_MyxRi_j0U6kJrkFvY4-OX2XYmEAa76BSFwMlSow1YgX8BOPUeve_shMG7xw"
+ Barometer::Query.google_geocode_key = KEY
end
it "converts to coordinates" do
acceptable_formats = [:coordinates]
@query.convert!(acceptable_formats).should == @postalcode_to_coordinates
@@ -409,11 +453,11 @@
describe "with an intial format of :geocode," do
before(:each) do
@query = Barometer::Query.new(@geocode)
- Barometer::Query.google_geocode_key = "ABQIAAAAq8TH4offRcGrok8JVY_MyxRi_j0U6kJrkFvY4-OX2XYmEAa76BSFwMlSow1YgX8BOPUeve_shMG7xw"
+ Barometer::Query.google_geocode_key = KEY
end
it "converts to coordinates" do
acceptable_formats = [:coordinates]
@query.convert!(acceptable_formats).should == @geocode_to_coordinates
@@ -436,10 +480,10 @@
describe "with an intial format of :coordinates," do
before(:each) do
@query = Barometer::Query.new(@coordinates)
- Barometer::Query.google_geocode_key = "ABQIAAAAq8TH4offRcGrok8JVY_MyxRi_j0U6kJrkFvY4-OX2XYmEAa76BSFwMlSow1YgX8BOPUeve_shMG7xw"
+ Barometer::Query.google_geocode_key = KEY
end
it "converts to geocode" do
acceptable_formats = [:geocode]
@query.convert!(acceptable_formats).should == @coordinates_to_geocode
\ No newline at end of file