example for stubbing geocoder calls
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
require 'geocoder' | |
Geocoder.configure(:lookup => :test) | |
Geocoder::Lookup::Test.add_stub( | |
"Nantes, France", [ | |
{ | |
'latitude' => 47.218371, | |
'longitude' => -1.553621, | |
'address' => '4 Rue de la Commune, 44000 Nantes, France', | |
'state' => 'Pays de la Loire', | |
'state_code' => 'Pays de la Loire', | |
'country' => 'France', | |
'country_code' => 'FR' | |
} | |
] | |
) | |
Geocoder::Lookup::Test.set_default_stub( | |
[ | |
{ | |
'latitude' => 45.1891676, | |
'longitude' => 5.6997775, | |
'address' => '8 Avenue Aristide Briand, 38600 Fontaine, France', | |
'state' => 'Rhone-Alpes', | |
'state_code' => 'RA', | |
'country' => 'France', | |
'country_code' => 'FR' | |
} | |
] | |
) | |
puts Geocoder.search("Nantes, France").first.state | |
# => Pays de la Loire | |
puts Geocoder.search("Use the fallback").first.state | |
# => Rhone-Alpes | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment