Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
example for stubbing geocoder calls
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