Skip to content
Snippets Groups Projects
Commit 3a1c3244 authored by Luke Roberts's avatar Luke Roberts
Browse files

tests for telize error handling

parent 631c7670
No related branches found
No related tags found
No related merge requests found
...@@ -15,15 +15,12 @@ module Geocoder::Lookup ...@@ -15,15 +15,12 @@ module Geocoder::Lookup
private # --------------------------------------------------------------- private # ---------------------------------------------------------------
def parse_raw_data(raw_data)
raw_data.match(/^<html><title>404/) ? nil : super(raw_data)
end
def results(query) def results(query)
# don't look up a loopback address, just return the stored result # don't look up a loopback address, just return the stored result
return [reserved_result(query.text)] if query.loopback_ip_address? return [reserved_result(query.text)] if query.loopback_ip_address?
# note: Freegeoip.net returns plain text "Not Found" on bad request # note: Telize returns json with a code attribute of 401 on bad request
(doc = fetch_data(query)) ? [doc] : [] doc = fetch_data(query)
(doc && doc['code'] == 401) ? [] : [doc]
end end
def reserved_result(ip) def reserved_result(ip)
......
{
"message": "Input string is not a valid IP address",
"code": 401
}
<html><title>404: Not Found</title><body>404: Not Found</body></html> {
"message": "Input string is not a valid IP address",
"code": 401
}
...@@ -145,6 +145,10 @@ module Geocoder ...@@ -145,6 +145,10 @@ module Geocoder
class Telize class Telize
private private
def fixture_prefix
"telize"
end
def default_fixture_filename def default_fixture_filename
"telize_74_200_247_59" "telize_74_200_247_59"
end end
......
...@@ -17,4 +17,9 @@ class TelizeTest < GeocoderTestCase ...@@ -17,4 +17,9 @@ class TelizeTest < GeocoderTestCase
result = Geocoder.search("74.200.247.59").first result = Geocoder.search("74.200.247.59").first
assert_equal "Plano, TX 75093, United States", result.address assert_equal "Plano, TX 75093, United States", result.address
end end
def test_no_results
results = Geocoder.search("10.10.10.10")
assert_equal 0, results.length
end
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